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 <connyduck@users.noreply.github.com>

Co-authored-by: Konrad Pozniak <connyduck@users.noreply.github.com>
This commit is contained in:
Colin Kinloch 2021-10-04 06:48:44 +01:00 committed by GitHub
parent 651b35267f
commit c37ccbb6e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 51 additions and 5 deletions

View file

@ -258,6 +258,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
statusDisplayOptions.useBlurhash(),
CardViewMode.NONE,
statusDisplayOptions.confirmReblogs(),
statusDisplayOptions.confirmFavourites(),
statusDisplayOptions.hideStats(),
statusDisplayOptions.animateEmojis()
);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -81,6 +81,7 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
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)
)

View file

@ -68,6 +68,7 @@ public final class TimelineAdapter extends RecyclerView.Adapter {
statusDisplayOptions.useBlurhash(),
statusDisplayOptions.cardViewMode(),
statusDisplayOptions.confirmReblogs(),
statusDisplayOptions.confirmFavourites(),
statusDisplayOptions.hideStats(),
statusDisplayOptions.animateEmojis()
);

View file

@ -145,6 +145,7 @@ class TimelineFragment :
)
) CardViewMode.INDENTED else CardViewMode.NONE,
confirmReblogs = preferences.getBoolean(PrefKeys.CONFIRM_REBLOGS, true),
confirmFavourites = preferences.getBoolean(PrefKeys.CONFIRM_FAVOURITES, true),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
)

View file

@ -255,6 +255,7 @@ public class NotificationsFragment extends SFragment implements
preferences.getBoolean("useBlurhash", true),
CardViewMode.NONE,
preferences.getBoolean("confirmReblogs", true),
preferences.getBoolean("confirmFavourites", true),
preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
);

View file

@ -140,6 +140,7 @@ public final class ViewThreadFragment extends SFragment implements
CardViewMode.INDENTED :
CardViewMode.NONE,
preferences.getBoolean("confirmReblogs", true),
preferences.getBoolean("confirmFavourites", true),
preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
);

View file

@ -30,6 +30,7 @@ object PrefKeys {
const val SHOW_NOTIFICATIONS_FILTER = "showNotificationsFilter"
const val SHOW_CARDS_IN_TIMELINES = "showCardsInTimelines"
const val CONFIRM_REBLOGS = "confirmReblogs"
const val CONFIRM_FAVOURITES = "confirmFavourites"
const val ENABLE_SWIPE_FOR_TABS = "enableSwipeForTabs"
const val ANIMATE_CUSTOM_EMOJIS = "animateCustomEmojis"

View file

@ -15,6 +15,8 @@ data class StatusDisplayOptions(
val cardViewMode: CardViewMode,
@get:JvmName("confirmReblogs")
val confirmReblogs: Boolean,
@get:JvmName("confirmFavourites")
val confirmFavourites: Boolean,
@get:JvmName("hideStats")
val hideStats: Boolean,
@get:JvmName("animateEmojis")

View file

@ -72,8 +72,9 @@
<string name="action_reblog">Boost</string>
<string name="action_unreblog">Remove boost</string>
<string name="action_favourite">Favorite</string>
<string name="action_bookmark">Bookmark</string>
<string name="action_unfavourite">Remove favorite</string>
<string name="action_bookmark">Bookmark</string>
<string name="action_unbookmark">Remove bookmark</string>
<string name="action_more">More</string>
<string name="action_compose">Compose</string>
<string name="action_login">Login with Mastodon</string>
@ -591,6 +592,7 @@
<string name="warning_scheduling_interval">Mastodon has a minimum scheduling interval of 5 minutes.</string>
<string name="pref_title_show_cards_in_timelines">Show link previews in timelines</string>
<string name="pref_title_confirm_reblogs">Show confirmation dialog before boosting</string>
<string name="pref_title_confirm_favourites">Show confirmation dialog before favoriting</string>
<string name="pref_title_hide_top_toolbar">Hide the title of the top toolbar</string>
<string name="pref_title_wellbeing_mode">Wellbeing</string>
<string name="account_note_hint">Your private note about this account</string>