diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt index 20b6202f..a4903c61 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt @@ -718,6 +718,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, @@ -764,11 +788,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 7979fee5..02825b17 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 5a7f1260..52939029 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 @@ -303,12 +303,18 @@ class SearchStatusesFragment : SearchFragment { + searchAdapter.getItem(position)?.let { foundStatus -> + viewModel.muteConversation(foundStatus, status.muted != true) + } + return@setOnMenuItemClickListener true + } R.id.status_mute -> { - 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 -> { @@ -341,6 +347,28 @@ 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 + } != null + } + private fun showOpenAsDialog(statusUrl: String, dialogTitle: CharSequence) { bottomSheetActivity?.showAccountChooserDialog(dialogTitle, false, object : AccountSelectionListener { override fun onAccountSelected(account: AccountEntity) { 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 33be8033..a1746e21 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; @@ -332,11 +333,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: { @@ -377,6 +378,38 @@ 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; + } + + for (Status.Mention mention : mentions) { + if (account.getUsername().equals(mention.getUsername())) { + Uri uri = Uri.parse(mention.getUrl()); + if (uri != null && account.getDomain().equals(uri.getHost())) { + return true; + } + } + } + return false; + } + protected void viewMedia(int urlIndex, Status status, @Nullable View view) { final Status actionable = status.getActionableStatus(); final Attachment active = actionable.getAttachments().get(urlIndex); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 01233d39..80f2edf3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -194,6 +194,8 @@ Delete and re-draft this [pst? 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