Confirm blocks and mutes from timelines (#1740)

* Add preference for confirming blocks and mutes from timelines
Implements #1737

* Apply code review feedback
This commit is contained in:
Levi Bard 2020-03-30 21:03:27 +02:00 committed by Alibek Omarov
parent ae651c3cf1
commit bf7e9e019d
5 changed files with 94 additions and 7 deletions

View File

@ -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 -> {

View File

@ -193,7 +193,7 @@ class SearchViewModel @Inject constructor(
return accountManager.getAllAccountsOrderedByActive()
}
fun muteAcount(accountId: String) {
fun muteAccount(accountId: String) {
timelineCases.mute(accountId)
}

View File

@ -303,12 +303,18 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
requestDownloadAllMedia(status)
return@setOnMenuItemClickListener true
}
R.id.status_mute_conversation -> {
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<Pair<Status, StatusViewData.Concre
popup.show()
}
private fun onBlock(accountId: String, accountUsername: String) {
AlertDialog.Builder(requireContext())
.setMessage(getString(R.string.dialog_block_warning, accountUsername))
.setPositiveButton(android.R.string.ok) { _, _ -> 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<Mention>): 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) {

View File

@ -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);

View File

@ -194,6 +194,8 @@
<string name="dialog_redraft_toot_warning">Delete and re-draft this [pst?</string>
<string name="mute_domain_warning">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.</string>
<string name="mute_domain_warning_dialog_ok">Hide entire domain</string>
<string name="dialog_block_warning">Block @%s?</string>
<string name="dialog_mute_warning">Mute @%s?</string>
<string name="visibility_public">Public: Post to public timelines</string>
<string name="visibility_unlisted">Unlisted: Do not show in public timelines</string>