From 4843d574cac586c641fdbc3029028f60faa5c1b2 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Tue, 16 May 2023 17:07:13 +0200 Subject: [PATCH] feat: show confirmation dialog on unfollow --- .../android/ui/utils/UiUtils.java | 23 +++++++++++++++---- mastodon/src/main/res/values/strings_mo.xml | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index 8278620f7..c20d7dc2a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -390,12 +390,16 @@ public class UiUtils { showConfirmationAlert(context, context.getString(title), context.getString(message), context.getString(confirmButton), icon, onConfirmed); } - public static void showConfirmationAlert(Context context, CharSequence title, CharSequence message, CharSequence confirmButton, int icon, Runnable onConfirmed){ + public static void showConfirmationAlert(Context context, CharSequence title, CharSequence message, CharSequence confirmButton, int icon, Runnable onConfirmed) { + showConfirmationAlert(context, title, message, confirmButton, icon, onConfirmed, null); + } + + public static void showConfirmationAlert(Context context, CharSequence title, CharSequence message, CharSequence confirmButton, int icon, Runnable onConfirmed, Runnable onDenied){ new M3AlertDialogBuilder(context) .setTitle(title) .setMessage(message) .setPositiveButton(confirmButton, (dlg, i)->onConfirmed.run()) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, (dialog, which) -> onDenied.run()) .setIcon(icon) .show(); } @@ -779,7 +783,17 @@ public class UiUtils { } progressCallback.accept(true); - follow(activity, accountID, account, !relationship.following && !relationship.requested, progressCallback, resultCallback); + if (!relationship.following && !relationship.requested) { + follow(activity, accountID, account, true, progressCallback, resultCallback); + } else { + showConfirmationAlert(activity, + activity.getString(R.string.mo_confirm_unfollow_title), + activity.getString(R.string.mo_confirm_unfollow, account.getDisplayUsername()), + activity.getString(R.string.unfollow), + 0, + () -> follow(activity, accountID, account, false, progressCallback, resultCallback), + () -> progressCallback.accept(false)); + } } @@ -801,7 +815,8 @@ public class UiUtils { progressCallback.accept(false); } }) - .exec(accountID); } + .exec(accountID); + } public static void handleFollowRequest(Activity activity, Account account, String accountID, @Nullable String notificationID, boolean accepted, Relationship relationship, Consumer resultCallback) { diff --git a/mastodon/src/main/res/values/strings_mo.xml b/mastodon/src/main/res/values/strings_mo.xml index 07a83c40a..f0e6ddbb4 100644 --- a/mastodon/src/main/res/values/strings_mo.xml +++ b/mastodon/src/main/res/values/strings_mo.xml @@ -54,5 +54,6 @@ Use reblog action instead of bookmark action on notifications Download latest nightly release Load remote profile follows and followers - Automatically mention account who reblogged the post in replies + Unfollow Account + Confirm to unfollow %s \ No newline at end of file