From 91263eed8b4b479f3a2d356bdd14d27828e510c2 Mon Sep 17 00:00:00 2001 From: Levi Bard Date: Mon, 30 Mar 2020 21:03:27 +0200 Subject: [PATCH] Confirm blocks and mutes from timelines (#1740) * Add preference for confirming blocks and mutes from timelines Implements #1737 * Apply code review feedback --- .../keylesspalace/tusky/AccountActivity.kt | 28 +++++++++++++++++-- .../components/search/SearchViewModel.kt | 2 +- .../fragments/SearchStatusesFragment.kt | 20 +++++++++++-- .../tusky/fragment/SFragment.java | 21 ++++++++++++-- app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 66 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt index ad91b19e..333eb09d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt @@ -681,6 +681,30 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI .show() } + private fun toggleBlock() { + if (viewModel.relationshipData.value?.data?.blocking != true) { + AlertDialog.Builder(this) + .setMessage(getString(R.string.dialog_block_warning, loadedAccount?.username)) + .setPositiveButton(android.R.string.ok) { _, _ -> viewModel.changeBlockState() } + .setNegativeButton(android.R.string.cancel, null) + .show() + } else { + viewModel.changeBlockState() + } + } + + private fun toggleMute() { + if (viewModel.relationshipData.value?.data?.muting != true) { + AlertDialog.Builder(this) + .setMessage(getString(R.string.dialog_mute_warning, loadedAccount?.username)) + .setPositiveButton(android.R.string.ok) { _, _ -> viewModel.changeMuteState() } + .setNegativeButton(android.R.string.cancel, null) + .show() + } else { + viewModel.changeMuteState() + } + } + private fun mention() { loadedAccount?.let { val intent = ComposeActivity.startIntent(this, @@ -727,11 +751,11 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI return true } R.id.action_block -> { - viewModel.changeBlockState() + toggleBlock() return true } R.id.action_mute -> { - viewModel.changeMuteState() + toggleMute() return true } R.id.action_mute_domain -> { diff --git a/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt index 71121a91..aa55c99c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt @@ -193,7 +193,7 @@ class SearchViewModel @Inject constructor( return accountManager.getAllAccountsOrderedByActive() } - fun muteAcount(accountId: String) { + fun muteAccount(accountId: String) { timelineCases.mute(accountId) } diff --git a/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt index 0833f04c..4e5f64fb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt @@ -325,11 +325,11 @@ class SearchStatusesFragment : SearchFragment { - viewModel.muteAcount(accountId) + onMute(accountId, accountUsername) return@setOnMenuItemClickListener true } R.id.status_block -> { - viewModel.blockAccount(accountId) + onBlock(accountId, accountUsername) return@setOnMenuItemClickListener true } R.id.status_report -> { @@ -362,6 +362,22 @@ class SearchStatusesFragment : SearchFragment viewModel.blockAccount(accountId) } + .setNegativeButton(android.R.string.cancel, null) + .show() + } + + private fun onMute(accountId: String, accountUsername: String) { + AlertDialog.Builder(requireContext()) + .setMessage(getString(R.string.dialog_mute_warning, accountUsername)) + .setPositiveButton(android.R.string.ok) { _, _ -> viewModel.muteAccount(accountId) } + .setNegativeButton(android.R.string.cancel, null) + .show() + } + private fun accountIsInMentions(account: AccountEntity?, mentions: Array): Boolean { return mentions.firstOrNull { account?.username == it.username && account.domain == Uri.parse(it.url)?.host diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java index 6a7e5f12..5b475a04 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java @@ -39,6 +39,7 @@ import androidx.appcompat.widget.PopupMenu; import androidx.core.app.ActivityOptionsCompat; import androidx.core.view.ViewCompat; import androidx.lifecycle.Lifecycle; +import androidx.preference.PreferenceManager; import com.keylesspalace.tusky.BaseActivity; import com.keylesspalace.tusky.BottomSheetActivity; @@ -284,11 +285,11 @@ public abstract class SFragment extends BaseFragment implements Injectable { return true; } case R.id.status_mute: { - timelineCases.mute(accountId); + onMute(accountId, accountUsername); return true; } case R.id.status_block: { - timelineCases.block(accountId); + onBlock(accountId, accountUsername); return true; } case R.id.status_report: { @@ -328,6 +329,22 @@ public abstract class SFragment extends BaseFragment implements Injectable { popup.show(); } + private void onMute(String accountId, String accountUsername) { + new AlertDialog.Builder(requireContext()) + .setMessage(getString(R.string.dialog_mute_warning, accountUsername)) + .setPositiveButton(android.R.string.ok, (__, ___) -> timelineCases.mute(accountId)) + .setNegativeButton(android.R.string.cancel, null) + .show(); + } + + private void onBlock(String accountId, String accountUsername) { + new AlertDialog.Builder(requireContext()) + .setMessage(getString(R.string.dialog_block_warning, accountUsername)) + .setPositiveButton(android.R.string.ok, (__, ___) -> timelineCases.block(accountId)) + .setNegativeButton(android.R.string.cancel, null) + .show(); + } + private static boolean accountIsInMentions(AccountEntity account, Status.Mention[] mentions) { if (account == null) { return false; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 50900565..bf480226 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -196,6 +196,8 @@ Delete and re-draft this toot? Are you sure you want to block all of %s? You will not see content from that domain in any public timelines or in your notifications. Your followers from that domain will be removed. Hide entire domain + Block @%s? + Mute @%s? Public: Post to public timelines Unlisted: Do not show in public timelines