From c37ccbb6e849deae5439269c6c80e2a53cb7d2fd Mon Sep 17 00:00:00 2001 From: Colin Kinloch Date: Mon, 4 Oct 2021 06:48:44 +0100 Subject: [PATCH] Add confirmation for favourite and bookmark actions (#2245) * Add confirmation for favourite and bookmark actions * Favourite confirmation american spelling and default values * Remove bookmarking confirmation * Update app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java Co-authored-by: Konrad Pozniak Co-authored-by: Konrad Pozniak --- .../tusky/adapter/NotificationsAdapter.java | 1 + .../tusky/adapter/StatusBaseViewHolder.java | 29 +++++++++++++++++-- .../conversation/ConversationsFragment.kt | 1 + .../preference/PreferencesActivity.kt | 5 ++-- .../preference/PreferencesFragment.kt | 7 +++++ .../fragments/ReportStatusesFragment.kt | 1 + .../fragments/SearchStatusesFragment.kt | 1 + .../components/timeline/TimelineAdapter.java | 1 + .../components/timeline/TimelineFragment.kt | 1 + .../tusky/fragment/NotificationsFragment.java | 1 + .../tusky/fragment/ViewThreadFragment.java | 1 + .../tusky/settings/SettingsConstants.kt | 1 + .../tusky/util/StatusDisplayOptions.kt | 2 ++ app/src/main/res/values/strings.xml | 4 ++- 14 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java index e0d8e898..5b6ca64f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java @@ -258,6 +258,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter { statusDisplayOptions.useBlurhash(), CardViewMode.NONE, statusDisplayOptions.confirmReblogs(), + statusDisplayOptions.confirmFavourites(), statusDisplayOptions.hideStats(), statusDisplayOptions.animateEmojis() ); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 435f3ac1..734f4e58 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -651,11 +651,19 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } favouriteButton.setEventListener((button, buttonState) -> { + // return true to play animaion int position = getBindingAdapterPosition(); if (position != RecyclerView.NO_POSITION) { - listener.onFavourite(!buttonState, position); + if (statusDisplayOptions.confirmFavourites()) { + showConfirmFavouriteDialog(listener, statusContent, buttonState, position); + return false; + } else { + listener.onFavourite(!buttonState, position); + return true; + } + } else { + return true; } - return true; }); bookmarkButton.setEventListener((button, buttonState) -> { @@ -703,6 +711,23 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { .show(); } + private void showConfirmFavouriteDialog(StatusActionListener listener, + String statusContent, + boolean buttonState, + int position) { + int okButtonTextId = buttonState ? R.string.action_unfavourite : R.string.action_favourite; + new AlertDialog.Builder(favouriteButton.getContext()) + .setMessage(statusContent) + .setPositiveButton(okButtonTextId, (__, ___) -> { + listener.onFavourite(!buttonState, position); + if (!buttonState) { + // Play animation only when it's favourite, not unfavourite + favouriteButton.playAnimation(); + } + }) + .show(); + } + public void setupWithStatus(StatusViewData.Concrete status, final StatusActionListener listener, StatusDisplayOptions statusDisplayOptions) { this.setupWithStatus(status, listener, statusDisplayOptions, null); diff --git a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt index 4272c1bd..526b8d1e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt @@ -84,6 +84,7 @@ class ConversationsFragment : SFragment(), StatusActionListener, Injectable, Res useBlurhash = preferences.getBoolean("useBlurhash", true), cardViewMode = CardViewMode.NONE, confirmReblogs = preferences.getBoolean("confirmReblogs", true), + confirmFavourites = preferences.getBoolean("confirmFavourites", true), hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false), animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false) ) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesActivity.kt index 8297fae4..ee79a624 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesActivity.kt @@ -124,8 +124,9 @@ class PreferencesActivity : restartActivitiesOnExit = true this.restartCurrentActivity() } - "statusTextSize", "absoluteTimeView", "showBotOverlay", "animateGifAvatars", - "useBlurhash", "showCardsInTimelines", "confirmReblogs", "enableSwipeForTabs", "mainNavPosition", PrefKeys.HIDE_TOP_TOOLBAR -> { + "statusTextSize", "absoluteTimeView", "showBotOverlay", "animateGifAvatars", "useBlurhash", + "showCardsInTimelines", "confirmReblogs", "confirmFavourites", + "enableSwipeForTabs", "mainNavPosition", PrefKeys.HIDE_TOP_TOOLBAR -> { restartActivitiesOnExit = true } "language" -> { diff --git a/app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesFragment.kt index d3f44e32..e585e78f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesFragment.kt @@ -166,6 +166,13 @@ class PreferencesFragment : PreferenceFragmentCompat(), Injectable { isSingleLineTitle = false } + switchPreference { + setDefaultValue(false) + key = PrefKeys.CONFIRM_FAVOURITES + setTitle(R.string.pref_title_confirm_favourites) + isSingleLineTitle = false + } + switchPreference { setDefaultValue(true) key = PrefKeys.ENABLE_SWIPE_FOR_TABS diff --git a/app/src/main/java/com/keylesspalace/tusky/components/report/fragments/ReportStatusesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/report/fragments/ReportStatusesFragment.kt index 98de3c94..d52d99bb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/report/fragments/ReportStatusesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/report/fragments/ReportStatusesFragment.kt @@ -114,6 +114,7 @@ class ReportStatusesFragment : Fragment(R.layout.fragment_report_statuses), Inje useBlurhash = preferences.getBoolean("useBlurhash", true), cardViewMode = CardViewMode.NONE, confirmReblogs = preferences.getBoolean("confirmReblogs", true), + confirmFavourites = preferences.getBoolean("confirmFavourites", true), hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false), animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false) ) 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 3ade751f..8b2cf834 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 @@ -81,6 +81,7 @@ class SearchStatusesFragment : SearchFragmentBoost Remove boost Favorite - Bookmark Remove favorite + Bookmark + Remove bookmark More Compose Login with Mastodon @@ -591,6 +592,7 @@ Mastodon has a minimum scheduling interval of 5 minutes. Show link previews in timelines Show confirmation dialog before boosting + Show confirmation dialog before favoriting Hide the title of the top toolbar Wellbeing Your private note about this account