From 0b690838bbbb79d4cc35555e238bb15a3056b9d3 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 24 Nov 2022 16:44:24 +0100 Subject: [PATCH] Fix issue #533 - Add an option to keep notifications when muting --- .../android/activities/ProfileActivity.java | 93 +++++++++++-------- .../android/ui/drawer/StatusAdapter.java | 10 +- app/src/main/res/values/strings.xml | 1 + 3 files changed, 61 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java index e2b97c1c..24f350b6 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java @@ -695,7 +695,6 @@ public class ProfileActivity extends BaseActivity { splitAcct = account.acct.split("@"); } SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this); - AlertDialog.Builder builderInner = null; final boolean isOwner = account != null && account.id != null && BaseMainActivity.currentUserID != null && account.id.compareToIgnoreCase(BaseMainActivity.currentUserID) == 0; final String[] stringArrayConf; if (isOwner) { @@ -920,21 +919,43 @@ public class ProfileActivity extends BaseActivity { startActivity(intent); return true; } else if (itemId == R.id.action_mute) { - + AlertDialog.Builder builderInner; if (relationship != null) { - if (relationship.muting) { - builderInner = new AlertDialog.Builder(ProfileActivity.this, Helper.dialogStyle()); - builderInner.setTitle(stringArrayConf[4]); - doActionAccount = action.UNMUTE; + String target; + if (item.getItemId() == R.id.action_block_instance) { + target = account.acct.split("@")[1]; } else { - builderInner = new AlertDialog.Builder(ProfileActivity.this, Helper.dialogStyle()); - builderInner.setTitle(stringArrayConf[0]); - doActionAccount = action.MUTE; + target = account.id; } - } else { - doActionAccount = action.NOTHING; - } + if (relationship.muting) { + accountsVM.unmute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target) + .observe(ProfileActivity.this, relationShip -> { + this.relationship = relationShip; + updateAccount(); + }); + return true; + } + builderInner = new AlertDialog.Builder(ProfileActivity.this, Helper.dialogStyle()); + builderInner.setTitle(stringArrayConf[0]); + builderInner.setNeutralButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setNegativeButton(R.string.keep_notifications, (dialog, which) -> { + accountsVM.mute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target, false, 0) + .observe(ProfileActivity.this, relationShip -> { + this.relationship = relationShip; + updateAccount(); + }); + }); + builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> { + accountsVM.mute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target, true, 0) + .observe(ProfileActivity.this, relationShip -> { + this.relationship = relationShip; + updateAccount(); + }); + dialog.dismiss(); + }); + builderInner.show(); + } } else if (itemId == R.id.action_timed_mute) { MastodonHelper.scheduleBoost(ProfileActivity.this, MastodonHelper.ScheduleType.TIMED_MUTED, null, account, rs -> { this.relationship = rs; @@ -942,7 +963,7 @@ public class ProfileActivity extends BaseActivity { }); return true; } else if (itemId == R.id.action_report) { - builderInner = new AlertDialog.Builder(ProfileActivity.this, Helper.dialogStyle()); + AlertDialog.Builder builderInner = new AlertDialog.Builder(ProfileActivity.this, Helper.dialogStyle()); builderInner.setTitle(R.string.report_account); //Text for report EditText input = new EditText(ProfileActivity.this); @@ -962,7 +983,7 @@ public class ProfileActivity extends BaseActivity { builderInner.show(); return true; } else if (itemId == R.id.action_block) { - builderInner = new AlertDialog.Builder(ProfileActivity.this, Helper.dialogStyle()); + AlertDialog.Builder builderInner = new AlertDialog.Builder(ProfileActivity.this, Helper.dialogStyle()); if (relationship != null) { if (relationship.blocking) { builderInner.setTitle(stringArrayConf[5]); @@ -974,15 +995,6 @@ public class ProfileActivity extends BaseActivity { } else { doActionAccount = action.NOTHING; } - } else if (itemId == R.id.action_block_instance) { - builderInner = new AlertDialog.Builder(ProfileActivity.this, Helper.dialogStyle()); - doActionAccount = action.BLOCK_DOMAIN; - String domain = account.acct.split("@")[1]; - builderInner.setMessage(getString(R.string.block_domain_confirm_message, domain)); - } else { - return true; - } - if (doAction != action.NOTHING && builderInner != null) { builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { String target; @@ -992,20 +1004,6 @@ public class ProfileActivity extends BaseActivity { target = account.id; } switch (doActionAccount) { - case MUTE: - accountsVM.mute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target, true, 0) - .observe(ProfileActivity.this, relationShip -> { - this.relationship = relationShip; - updateAccount(); - }); - break; - case UNMUTE: - accountsVM.unmute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target) - .observe(ProfileActivity.this, relationShip -> { - this.relationship = relationShip; - updateAccount(); - }); - break; case BLOCK: accountsVM.block(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target) .observe(ProfileActivity.this, relationShip -> { @@ -1020,13 +1018,28 @@ public class ProfileActivity extends BaseActivity { updateAccount(); }); break; - case BLOCK_DOMAIN: - accountsVM.addDomainBlocks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target); - break; } dialog.dismiss(); }); builderInner.show(); + } else if (itemId == R.id.action_block_instance) { + AlertDialog.Builder builderInner = new AlertDialog.Builder(ProfileActivity.this, Helper.dialogStyle()); + String domain = account.acct.split("@")[1]; + builderInner.setMessage(getString(R.string.block_domain_confirm_message, domain)); + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { + String target; + if (item.getItemId() == R.id.action_block_instance) { + target = account.acct.split("@")[1]; + } else { + target = account.id; + } + accountsVM.addDomainBlocks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target); + dialog.dismiss(); + }); + builderInner.show(); + } else { + return true; } return true; } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index cb8cfe57..75c5f853 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -1863,14 +1863,18 @@ public class StatusAdapter extends RecyclerView.Adapter AlertDialog.Builder builderInner = new AlertDialog.Builder(context, Helper.dialogStyle()); builderInner.setTitle(stringArrayConf[0]); builderInner.setMessage(statusToDeal.account.acct); - builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); - builderInner.setPositiveButton(R.string.yes, (dialog, which) -> accountsVM.mute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.account.id, null, null) + builderInner.setNeutralButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setNegativeButton(R.string.keep_notifications, (dialog, which) -> accountsVM.mute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.account.id, false, null) + .observe((LifecycleOwner) context, relationShip -> { + sendAction(context, Helper.ARG_STATUS_ACCOUNT_ID_DELETED, null, statusToDeal.account.id); + Toasty.info(context, context.getString(R.string.toast_mute), Toasty.LENGTH_LONG).show(); + })); + builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> accountsVM.mute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.account.id, null, null) .observe((LifecycleOwner) context, relationShip -> { sendAction(context, Helper.ARG_STATUS_ACCOUNT_ID_DELETED, null, statusToDeal.account.id); Toasty.info(context, context.getString(R.string.toast_mute), Toasty.LENGTH_LONG).show(); })); builderInner.show(); - } else if (itemId == R.id.action_mute_conversation) { if (statusToDeal.muted) { statusesVM.unMute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id).observe((LifecycleOwner) context, status1 -> Toasty.info(context, context.getString(R.string.toast_unmute_conversation)).show()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ae5912e8..c8cd1be2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1915,4 +1915,5 @@ Are you sure to unpin that timeline? Delete the pinned timelines? Domains + Keep notifications \ No newline at end of file