From e2193e8e3c700addbe6951e3fb821726d56d93a2 Mon Sep 17 00:00:00 2001 From: sk Date: Wed, 15 Mar 2023 21:24:25 +0100 Subject: [PATCH] reply line below, compact above --- .../android/GlobalUserPreferences.java | 9 ++- .../android/fragments/ComposeFragment.java | 4 +- .../android/fragments/SettingsFragment.java | 15 ++++- .../ReblogOrReplyLineStatusDisplayItem.java | 20 ++++-- .../ui/displayitems/StatusDisplayItem.java | 65 ++++++++++++------- .../ic_fluent_re_order_24_regular.xml | 3 + .../display_item_reblog_or_reply_line.xml | 41 ++++++++++-- mastodon/src/main/res/values/strings_sk.xml | 3 +- 8 files changed, 116 insertions(+), 44 deletions(-) create mode 100644 mastodon/src/main/res/drawable/ic_fluent_re_order_24_regular.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index d66b63f04..fa2d08f3e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -44,7 +44,8 @@ public class GlobalUserPreferences{ public static boolean collapseLongPosts; public static boolean spectatorMode; public static boolean autoHideFab; - public static boolean replyLineBelowHeader; + public static boolean replyLineAboveHeader; + public static boolean compactReblogReplyLine; public static String publishButtonText; public static ThemePreference theme; public static ColorPreference color; @@ -94,7 +95,8 @@ public class GlobalUserPreferences{ collapseLongPosts=prefs.getBoolean("collapseLongPosts", true); spectatorMode=prefs.getBoolean("spectatorMode", false); autoHideFab=prefs.getBoolean("autoHideFab", true); - replyLineBelowHeader=prefs.getBoolean("replyLineBelowHeader", true); + replyLineAboveHeader =prefs.getBoolean("replyLineAboveHeader", false); + compactReblogReplyLine=prefs.getBoolean("compactReblogReplyLine", true); publishButtonText=prefs.getString("publishButtonText", ""); theme=ThemePreference.values()[prefs.getInt("theme", 0)]; recentLanguages=fromJson(prefs.getString("recentLanguages", null), recentLanguagesType, new HashMap<>()); @@ -136,9 +138,10 @@ public class GlobalUserPreferences{ .putBoolean("collapseLongPosts", collapseLongPosts) .putBoolean("spectatorMode", spectatorMode) .putBoolean("autoHideFab", autoHideFab) + .putBoolean("compactReblogReplyLine", compactReblogReplyLine) .putString("publishButtonText", publishButtonText) .putBoolean("bottomEncoding", bottomEncoding) - .putBoolean("replyLineBelowHeader", replyLineBelowHeader) + .putBoolean("replyLineAboveHeader", replyLineAboveHeader) .putInt("theme", theme.ordinal()) .putString("color", color.name()) .putString("recentLanguages", gson.toJson(recentLanguages)) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index a27f9c73c..7afaf9935 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -333,8 +333,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr scheduleTimeBtn=view.findViewById(R.id.scheduled_time_btn); sensitiveIcon=view.findViewById(R.id.sensitive_icon); sensitiveItem=view.findViewById(R.id.sensitive_item); - replyText=view.findViewById(GlobalUserPreferences.replyLineBelowHeader ? R.id.reply_text_below : R.id.reply_text); - view.findViewById(GlobalUserPreferences.replyLineBelowHeader ? R.id.reply_text : R.id.reply_text_below) + replyText=view.findViewById(GlobalUserPreferences.replyLineAboveHeader ? R.id.reply_text : R.id.reply_text_below); + view.findViewById(GlobalUserPreferences.replyLineAboveHeader ? R.id.reply_text_below : R.id.reply_text) .setVisibility(View.GONE); if (isPhotoPickerAvailable()) { diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java index d7f299143..6704813bc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java @@ -80,7 +80,7 @@ public class SettingsFragment extends MastodonToolbarFragment{ private ArrayList items=new ArrayList<>(); private ThemeItem themeItem; private NotificationPolicyItem notificationPolicyItem; - private SwitchItem showNewPostsButtonItem, glitchModeItem; + private SwitchItem showNewPostsButtonItem, glitchModeItem, compactReblogReplyLineItem; private String accountID; private boolean needUpdateNotificationSettings; private boolean needAppRestart; @@ -253,10 +253,19 @@ public class SettingsFragment extends MastodonToolbarFragment{ GlobalUserPreferences.save(); needAppRestart=true; })); - items.add(new SwitchItem(R.string.sk_reply_line_below_avatar, R.drawable.ic_fluent_arrow_reply_24_regular, GlobalUserPreferences.replyLineBelowHeader, i->{ - GlobalUserPreferences.replyLineBelowHeader=i.checked; + items.add(new SwitchItem(R.string.sk_reply_line_above_avatar, R.drawable.ic_fluent_arrow_reply_24_regular, GlobalUserPreferences.replyLineAboveHeader, i->{ + GlobalUserPreferences.replyLineAboveHeader=i.checked; + GlobalUserPreferences.compactReblogReplyLine=i.checked; + compactReblogReplyLineItem.enabled=i.checked; + compactReblogReplyLineItem.checked= GlobalUserPreferences.replyLineAboveHeader; + if (list.findViewHolderForAdapterPosition(items.indexOf(compactReblogReplyLineItem)) instanceof SwitchViewHolder svh) svh.rebind(); GlobalUserPreferences.save(); })); + items.add(compactReblogReplyLineItem=new SwitchItem(R.string.sk_compact_reblog_reply_line, R.drawable.ic_fluent_re_order_24_regular, GlobalUserPreferences.compactReblogReplyLine, i->{ + GlobalUserPreferences.compactReblogReplyLine=i.checked; + GlobalUserPreferences.save();; + })); + compactReblogReplyLineItem.enabled=GlobalUserPreferences.replyLineAboveHeader; items.add(new SwitchItem(R.string.sk_settings_translate_only_opened, R.drawable.ic_fluent_translate_24_regular, GlobalUserPreferences.translateButtonOpenedOnly, i->{ GlobalUserPreferences.translateButtonOpenedOnly=i.checked; GlobalUserPreferences.save(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ReblogOrReplyLineStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ReblogOrReplyLineStatusDisplayItem.java index 71973c466..edb1b60d3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ReblogOrReplyLineStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ReblogOrReplyLineStatusDisplayItem.java @@ -39,6 +39,7 @@ public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{ private CustomEmojiHelper emojiHelper=new CustomEmojiHelper(); private View.OnClickListener handleClick; boolean belowHeader, needBottomPadding; + ReblogOrReplyLineStatusDisplayItem secondary; public ReblogOrReplyLineStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, CharSequence text, List emojis, @DrawableRes int icon, StatusPrivacy visibility, @Nullable View.OnClickListener handleClick) { super(parentID, parentFragment); @@ -79,15 +80,17 @@ public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{ } public static class Holder extends StatusDisplayItem.Holder implements ImageLoaderViewHolder{ - private final TextView text; + private final TextView text, secondaryText; + private final View secondaryWrap; public Holder(Activity activity, ViewGroup parent){ super(activity, R.layout.display_item_reblog_or_reply_line, parent); text=findViewById(R.id.text); + secondaryText=findViewById(R.id.secondary_text); + secondaryWrap=findViewById(R.id.secondary_wrap); } - @Override - public void onBind(ReblogOrReplyLineStatusDisplayItem item){ + private void bindLine(ReblogOrReplyLineStatusDisplayItem item, TextView text) { text.setText(item.text); text.setCompoundDrawablesRelativeWithIntrinsicBounds(item.icon, 0, item.iconEnd, 0); text.setOnClickListener(item.handleClick); @@ -104,11 +107,18 @@ public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{ if (visibilityText != 0) text.setContentDescription(item.text + " (" + ctx.getString(visibilityText) + ")"); if(Build.VERSION.SDK_INT { + args.putParcelable("profileAccount", Parcels.wrap(account)); + Nav.go(fragment.getActivity(), ProfileFragment.class, args); + }; + + String text = threadReply ? fragment.getString(R.string.sk_show_thread) + : account == null ? fragment.getString(R.string.sk_in_reply) + : GlobalUserPreferences.compactReblogReplyLine && status.reblog != null ? account.displayName + : fragment.getString(R.string.in_reply_to, account.displayName); + + replyLine = new ReblogOrReplyLineStatusDisplayItem( + parentID, fragment, text, account == null ? List.of() : account.emojis, + R.drawable.ic_fluent_arrow_reply_20_filled, null, handleClick + ); + } + if(status.reblog!=null){ boolean isOwnPost = AccountSessionManager.getInstance().isSelf(fragment.getAccountID(), status.account); - items.add(new ReblogOrReplyLineStatusDisplayItem(parentID, fragment, fragment.getString(R.string.user_boosted, status.account.displayName), status.account.emojis, R.drawable.ic_fluent_arrow_repeat_all_20_filled, isOwnPost ? status.visibility : null, i->{ + String text = GlobalUserPreferences.compactReblogReplyLine && replyLine != null + ? status.account.displayName + : fragment.getString(R.string.user_boosted, status.account.displayName); + + items.add(new ReblogOrReplyLineStatusDisplayItem(parentID, fragment, text, status.account.emojis, R.drawable.ic_fluent_arrow_repeat_all_20_filled, isOwnPost ? status.visibility : null, i->{ args.putParcelable("profileAccount", Parcels.wrap(status.account)); Nav.go(fragment.getActivity(), ProfileFragment.class, args); })); @@ -134,42 +161,30 @@ public abstract class StatusDisplayItem{ ))); } - ReblogOrReplyLineStatusDisplayItem replyLine = null; - boolean threadReply = statusForContent.inReplyToAccountId != null && - statusForContent.inReplyToAccountId.equals(status.account.id); + if (replyLine != null && GlobalUserPreferences.replyLineAboveHeader) { + Optional primaryLine = items.stream() + .filter(i -> i instanceof ReblogOrReplyLineStatusDisplayItem) + .map(ReblogOrReplyLineStatusDisplayItem.class::cast) + .findFirst(); - if(statusForContent.inReplyToAccountId!=null && !(threadReply && fragment instanceof ThreadFragment)){ - Account account = knownAccounts.get(statusForContent.inReplyToAccountId); - View.OnClickListener handleClick = account == null || threadReply ? null : i -> { - args.putParcelable("profileAccount", Parcels.wrap(account)); - Nav.go(fragment.getActivity(), ProfileFragment.class, args); - }; - - String text = threadReply ? - fragment.getString(R.string.sk_show_thread) : account != null ? - fragment.getString(R.string.in_reply_to, account.displayName) : fragment.getString(R.string.sk_in_reply); - - replyLine = new ReblogOrReplyLineStatusDisplayItem( - parentID, fragment, text, account == null ? List.of() : account.emojis, - R.drawable.ic_fluent_arrow_reply_20_filled, null, handleClick - ); - } - - if (replyLine != null && !GlobalUserPreferences.replyLineBelowHeader) { - items.add(replyLine); + if (primaryLine.isPresent() && GlobalUserPreferences.compactReblogReplyLine) { + primaryLine.get().secondary = replyLine; + } else { + items.add(replyLine); + } } HeaderStatusDisplayItem header; items.add(header=new HeaderStatusDisplayItem(parentID, statusForContent.account, statusForContent.createdAt, fragment, accountID, statusForContent, null, notification, scheduledStatus)); - if (replyLine != null && GlobalUserPreferences.replyLineBelowHeader) { + if (replyLine != null && !GlobalUserPreferences.replyLineAboveHeader) { replyLine.belowHeader = true; items.add(replyLine); } if(!TextUtils.isEmpty(statusForContent.content)) items.add(new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID), fragment, statusForContent, disableTranslate)); - else if (GlobalUserPreferences.replyLineBelowHeader && replyLine != null) + else if (!GlobalUserPreferences.replyLineAboveHeader && replyLine != null) replyLine.needBottomPadding=true; else header.needBottomPadding=true; diff --git a/mastodon/src/main/res/drawable/ic_fluent_re_order_24_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_re_order_24_regular.xml new file mode 100644 index 000000000..15ef7bc46 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_re_order_24_regular.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/layout/display_item_reblog_or_reply_line.xml b/mastodon/src/main/res/layout/display_item_reblog_or_reply_line.xml index 90bf482c3..f3de28551 100644 --- a/mastodon/src/main/res/layout/display_item_reblog_or_reply_line.xml +++ b/mastodon/src/main/res/layout/display_item_reblog_or_reply_line.xml @@ -1,16 +1,16 @@ - - \ No newline at end of file + + + + + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index 4406ecca2..1a6a70b3e 100644 --- a/mastodon/src/main/res/values/strings_sk.xml +++ b/mastodon/src/main/res/values/strings_sk.xml @@ -263,6 +263,7 @@ Followed from %s Auto-hide Compose button In reply - “In reply to” line below avatar + “In reply to” line above avatar Show thread + Compact reblog/reply line \ No newline at end of file