From baf756e16396ea7c4e1f4fea57d3f2cdd8ddf743 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 6 Oct 2023 17:53:43 +0200 Subject: [PATCH] =?UTF-8?q?allow=20using=20heart=20as=20fav=20icon=20?= =?UTF-8?q?=E2=9D=A4=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes sk22#81 --- .../api/session/AccountLocalPreferences.java | 3 +++ .../settings/SettingsDisplayFragment.java | 21 ++++++++++--------- .../displayitems/FooterStatusDisplayItem.java | 17 ++++++++++++--- mastodon/src/main/res/color/like_icon.xml | 5 +++++ .../drawable/ic_fluent_heart_24_filled.xml | 3 +++ .../drawable/ic_fluent_heart_24_selector.xml | 8 +++++++ .../main/res/layout/display_item_footer.xml | 1 + mastodon/src/main/res/values/colors.xml | 1 + mastodon/src/main/res/values/strings_sk.xml | 1 + 9 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 mastodon/src/main/res/color/like_icon.xml create mode 100644 mastodon/src/main/res/drawable/ic_fluent_heart_24_filled.xml create mode 100644 mastodon/src/main/res/drawable/ic_fluent_heart_24_selector.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountLocalPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountLocalPreferences.java index d67138d22f..c3f6fc7dc6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountLocalPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountLocalPreferences.java @@ -43,6 +43,7 @@ public class AccountLocalPreferences{ public boolean emojiReactionsEnabled; public ShowEmojiReactions showEmojiReactions; public ColorPreference color; + public boolean likeIcon; private final static Type recentLanguagesType = new TypeToken>() {}.getType(); private final static Type timelinesType = new TypeToken>() {}.getType(); @@ -71,6 +72,7 @@ public AccountLocalPreferences(SharedPreferences prefs, AccountSession session){ emojiReactionsEnabled=prefs.getBoolean("emojiReactionsEnabled", session.getInstance().isPresent() && session.getInstance().get().isAkkoma()); showEmojiReactions=ShowEmojiReactions.valueOf(prefs.getString("showEmojiReactions", ShowEmojiReactions.HIDE_EMPTY.name())); color=ColorPreference.valueOf(prefs.getString("color", ColorPreference.MATERIAL3.name())); + likeIcon=prefs.getBoolean("likeIcon", false); } public long getNotificationsPauseEndTime(){ @@ -105,6 +107,7 @@ public void save(){ .putBoolean("emojiReactionsEnabled", emojiReactionsEnabled) .putString("showEmojiReactions", showEmojiReactions.name()) .putString("color", color.name()) + .putBoolean("likeIcon", likeIcon) .apply(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java index 93e8fc7396..1b4190d890 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java @@ -38,7 +38,7 @@ public class SettingsDisplayFragment extends BaseSettingsFragment{ private CheckableListItem revealCWsItem, hideSensitiveMediaItem, interactionCountsItem, emojiInNamesItem; // MEGALODON - private CheckableListItem trueBlackModeItem, marqueeItem, disableSwipeItem, reduceMotionItem, altIndicatorItem, noAltIndicatorItem, collapsePostsItem, spectatorModeItem, hideFabItem, translateOpenedItem, disablePillItem, showNavigationLabelsItem; + private CheckableListItem trueBlackModeItem, marqueeItem, disableSwipeItem, reduceMotionItem, altIndicatorItem, noAltIndicatorItem, collapsePostsItem, spectatorModeItem, hideFabItem, translateOpenedItem, disablePillItem, showNavigationLabelsItem, likeIconItem; private ListItem colorItem, publishTextItem, autoRevealCWsItem; private CheckableListItem pronounsInUserListingsItem, pronounsInTimelinesItem, pronounsInThreadsItem; @@ -70,6 +70,7 @@ public void onCreate(Bundle savedInstanceState){ hideFabItem=new CheckableListItem<>(R.string.sk_settings_hide_fab, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.autoHideFab, R.drawable.ic_fluent_edit_24_regular, ()->toggleCheckableItem(hideFabItem)), translateOpenedItem=new CheckableListItem<>(R.string.sk_settings_translate_only_opened, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.translateButtonOpenedOnly, R.drawable.ic_fluent_translate_24_regular, ()->toggleCheckableItem(translateOpenedItem)), disablePillItem=new CheckableListItem<>(R.string.sk_disable_pill_shaped_active_indicator, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.disableM3PillActiveIndicator, R.drawable.ic_fluent_pill_24_regular, ()->toggleCheckableItem(disablePillItem)), + likeIconItem=new CheckableListItem<>(R.string.sk_settings_like_icon, 0, CheckableListItem.Style.SWITCH, lp.likeIcon, R.drawable.ic_fluent_heart_24_regular, ()->toggleCheckableItem(likeIconItem)), showNavigationLabelsItem=new CheckableListItem<>(R.string.sk_settings_show_labels_in_navigation_bar, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showNavigationLabels, R.drawable.ic_fluent_tag_24_regular, ()->toggleCheckableItem(showNavigationLabelsItem), true), pronounsInTimelinesItem=new CheckableListItem<>(R.string.sk_settings_display_pronouns_in_timelines, 0, CheckableListItem.Style.CHECKBOX, GlobalUserPreferences.displayPronounsInTimelines, 0, ()->toggleCheckableItem(pronounsInTimelinesItem)), pronounsInThreadsItem=new CheckableListItem<>(R.string.sk_settings_display_pronouns_in_threads, 0, CheckableListItem.Style.CHECKBOX, GlobalUserPreferences.displayPronounsInThreads, 0, ()->toggleCheckableItem(pronounsInThreadsItem)), @@ -97,12 +98,14 @@ protected void onHidden(){ boolean restartPlease= GlobalUserPreferences.disableM3PillActiveIndicator!=disablePillItem.checked || - GlobalUserPreferences.showNavigationLabels!=showNavigationLabelsItem.checked; + GlobalUserPreferences.showNavigationLabels!=showNavigationLabelsItem.checked || + lp.likeIcon!=likeIconItem.checked; lp.revealCWs=revealCWsItem.checked; lp.hideSensitiveMedia=hideSensitiveMediaItem.checked; lp.showInteractionCounts=interactionCountsItem.checked; lp.customEmojiInNames=emojiInNamesItem.checked; + lp.likeIcon=likeIconItem.checked; lp.save(); GlobalUserPreferences.toolbarMarquee=marqueeItem.checked; GlobalUserPreferences.reduceMotion=reduceMotionItem.checked; @@ -197,8 +200,7 @@ private void onAppearanceClick(){ } private void onColorClick(){ - AccountLocalPreferences prefs=AccountSessionManager.get(accountID).getLocalPreferences(); - int selected=prefs.color.ordinal(); + int selected=lp.color.ordinal(); int[] newSelected={selected}; String[] names=Arrays.stream(ColorPreference.values()).map(ColorPreference::getName).map(this::getString).toArray(String[]::new); new M3AlertDialogBuilder(getActivity()) @@ -207,9 +209,9 @@ private void onColorClick(){ selected, (dlg, item)->newSelected[0]=item) .setPositiveButton(R.string.ok, (dlg, item)->{ ColorPreference pref=ColorPreference.values()[newSelected[0]]; - if(pref!=prefs.color){ - ColorPreference prev=prefs.color; - prefs.color=pref; + if(pref!=lp.color){ + ColorPreference prev=lp.color; + lp.color=pref; GlobalUserPreferences.save(); colorItem.subtitleRes=getColorPaletteValue(); rebindItem(colorItem); @@ -260,17 +262,16 @@ private void onAutoRevealSpoilersClick(){ } private void maybeApplyNewThemeRightNow(GlobalUserPreferences.ThemePreference prevTheme, ColorPreference prevColor, Boolean prevTrueBlack){ - AccountLocalPreferences prefs=AccountSessionManager.get(accountID).getLocalPreferences(); if(prevTheme==null) prevTheme=GlobalUserPreferences.theme; if(prevTrueBlack==null) prevTrueBlack=GlobalUserPreferences.trueBlackTheme; - if(prevColor==null) prevColor=prefs.color; + if(prevColor==null) prevColor=lp.color; boolean isCurrentDark=prevTheme==GlobalUserPreferences.ThemePreference.DARK || (prevTheme==GlobalUserPreferences.ThemePreference.AUTO && Build.VERSION.SDK_INT>=30 && getResources().getConfiguration().isNightModeActive()); boolean isNewDark=GlobalUserPreferences.theme==GlobalUserPreferences.ThemePreference.DARK || (GlobalUserPreferences.theme==GlobalUserPreferences.ThemePreference.AUTO && Build.VERSION.SDK_INT>=30 && getResources().getConfiguration().isNightModeActive()); boolean isNewBlack=GlobalUserPreferences.trueBlackTheme; - if(isCurrentDark!=isNewDark || prevColor!=prefs.color || (isNewDark && prevTrueBlack!=isNewBlack)){ + if(isCurrentDark!=isNewDark || prevColor!=lp.color || (isNewDark && prevTrueBlack!=isNewBlack)){ restartActivityToApplyNewTheme(); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java index 7c323825f0..675ac812fb 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java @@ -1,12 +1,10 @@ package org.joinmastodon.android.ui.displayitems; -import static org.joinmastodon.android.ui.utils.UiUtils.opacityIn; -import static org.joinmastodon.android.ui.utils.UiUtils.opacityOut; - import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.Intent; +import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.LayoutInflater; @@ -17,6 +15,7 @@ import android.view.accessibility.AccessibilityNodeInfo; import android.widget.Button; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.TextView; import org.joinmastodon.android.GlobalUserPreferences; @@ -57,6 +56,7 @@ public Type getType(){ public static class Holder extends StatusDisplayItem.Holder{ private final TextView replies, boosts, favorites; private final View reply, boost, favorite, share, bookmark; + private final ImageView favIcon; private View touchingView = null; private boolean longClickPerformed = false; @@ -89,6 +89,7 @@ public Holder(Activity activity, ViewGroup parent){ favorite=findViewById(R.id.favorite_btn); share=findViewById(R.id.share_btn); bookmark=findViewById(R.id.bookmark_btn); + favIcon=findViewById(R.id.favorite_icon); reply.setOnTouchListener(this::onButtonTouch); reply.setOnClickListener(this::onReplyClick); @@ -132,6 +133,16 @@ public void onBind(FooterStatusDisplayItem item){ boolean condenseBottom = !item.isMainStatus && item.hasDescendantNeighbor && !nextIsWarning; + + AccountSession session=AccountSessionManager.get(item.accountID); + boolean like=session!=null && session.getLocalPreferences().likeIcon; + ColorStateList color=item.parentFragment.getResources().getColorStateList( + like ? R.color.like_icon : R.color.favorite_icon, item.parentFragment.getContext().getTheme() + ); + favIcon.setImageResource(like ? R.drawable.ic_fluent_heart_24_selector : R.drawable.ic_fluent_star_24_selector); + favIcon.setImageTintList(color); + favorites.setTextColor(color); + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) itemView.getLayoutParams(); params.setMargins(params.leftMargin, params.topMargin, params.rightMargin, condenseBottom ? V.dp(-5) : 0); diff --git a/mastodon/src/main/res/color/like_icon.xml b/mastodon/src/main/res/color/like_icon.xml new file mode 100644 index 0000000000..242d799861 --- /dev/null +++ b/mastodon/src/main/res/color/like_icon.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/ic_fluent_heart_24_filled.xml b/mastodon/src/main/res/drawable/ic_fluent_heart_24_filled.xml new file mode 100644 index 0000000000..8dc20bdeb3 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_heart_24_filled.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_fluent_heart_24_selector.xml b/mastodon/src/main/res/drawable/ic_fluent_heart_24_selector.xml new file mode 100644 index 0000000000..80231c3e4f --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_heart_24_selector.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/mastodon/src/main/res/layout/display_item_footer.xml b/mastodon/src/main/res/layout/display_item_footer.xml index b63a32e1f2..51e1c68435 100644 --- a/mastodon/src/main/res/layout/display_item_footer.xml +++ b/mastodon/src/main/res/layout/display_item_footer.xml @@ -101,6 +101,7 @@ android:layout_height="match_parent" android:paddingVertical="12dp"> @color/warning_500 @color/success_500 + @color/error_400 @color/gray_100 @color/primary_700 diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index 6c0ecf7aaf..80c17c2601 100644 --- a/mastodon/src/main/res/values/strings_sk.xml +++ b/mastodon/src/main/res/values/strings_sk.xml @@ -406,4 +406,5 @@ Muted accounts Blocked accounts + Use heart as favorite icon \ No newline at end of file