From d7bef67550ae90d932b0923a87ccac62c7057d6a Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Tue, 5 Sep 2023 11:24:35 -0300 Subject: [PATCH] feat: initial steps for only show media preview setting It contains settings, flags and settings. But no implementation just yet --- .../org/joinmastodon/android/GlobalUserPreferences.java | 5 ++++- .../android/fragments/StatusListFragment.java | 2 ++ .../fragments/settings/SettingsDisplayFragment.java | 3 ++- .../android/ui/displayitems/StatusDisplayItem.java | 8 +++++++- mastodon/src/main/res/values/strings_mo.xml | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index 6365bbfdc..191f2b07d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -76,6 +76,7 @@ public class GlobalUserPreferences{ public static boolean loadRemoteAccountFollowers; public static boolean mentionRebloggerAutomatically; public static boolean showPostsWithoutAlt; + public static boolean showMediaPreview; public static SharedPreferences getPrefs(){ return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE); @@ -151,7 +152,8 @@ public class GlobalUserPreferences{ swapBookmarkWithBoostAction=prefs.getBoolean("swapBookmarkWithBoostAction", false); loadRemoteAccountFollowers=prefs.getBoolean("loadRemoteAccountFollowers", true); mentionRebloggerAutomatically=prefs.getBoolean("mentionRebloggerAutomatically", false); - showPostsWithoutAlt =prefs.getBoolean("showPostsWithoutAlt", true); + showPostsWithoutAlt=prefs.getBoolean("showPostsWithoutAlt", true); + showMediaPreview=prefs.getBoolean("showMediaPreview", true); theme=ThemePreference.values()[prefs.getInt("theme", 0)]; @@ -234,6 +236,7 @@ public class GlobalUserPreferences{ .putBoolean("relocatePublishButton", relocatePublishButton) .putBoolean("enableDeleteNotifications", enableDeleteNotifications) .putBoolean("showPostsWithoutAlt", showPostsWithoutAlt) + .putBoolean("showMediaPreview", showMediaPreview) .putInt("theme", theme.ordinal()) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java index 64e000f94..6140ca966 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java @@ -48,6 +48,8 @@ public abstract class StatusListFragment extends BaseStatusListFragment flags |= StatusDisplayItem.FLAG_NO_FOOTER; if (!lp.emojiReactionsEnabled || lp.showEmojiReactions==ONLY_OPENED) flags |= StatusDisplayItem.FLAG_NO_EMOJI_REACTIONS; + if(GlobalUserPreferences.showMediaPreview) + flags |= StatusDisplayItem.FLAG_NO_MEDIA_PREVIEW; return StatusDisplayItem.buildItems(this, s, accountID, s, knownAccounts, getFilterContext(), isMainThreadStatus ? 0 : flags); } 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 6391530f4..2b39c8158 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 @@ -43,7 +43,7 @@ public class SettingsDisplayFragment extends BaseSettingsFragment{ private CheckableListItem pronounsInUserListingsItem, pronounsInTimelinesItem, pronounsInThreadsItem; // MOSHIDON - private CheckableListItem enableDoubleTapToSwipeItem, relocatePublishButtonItem, showPostDividersItem, enableDoubleTapToSearchItem; + private CheckableListItem enableDoubleTapToSwipeItem, relocatePublishButtonItem, showPostDividersItem, enableDoubleTapToSearchItem, showMediaPreviewItem; private AccountLocalPreferences lp; @@ -131,6 +131,7 @@ public class SettingsDisplayFragment extends BaseSettingsFragment{ GlobalUserPreferences.displayPronounsInTimelines=pronounsInTimelinesItem.checked; GlobalUserPreferences.displayPronounsInThreads=pronounsInThreadsItem.checked; GlobalUserPreferences.displayPronounsInUserListings=pronounsInUserListingsItem.checked; + GlobalUserPreferences.showMediaPreview=showMediaPreviewItem.checked; GlobalUserPreferences.save(); if(restartPlease) restartActivityToApplyNewTheme(); else E.post(new StatusDisplaySettingsChangedEvent(accountID)); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index 038348b9a..9aa262f4d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -69,6 +69,7 @@ public abstract class StatusDisplayItem{ public static final int FLAG_NO_HEADER=1 << 4; public static final int FLAG_NO_TRANSLATE=1 << 5; public static final int FLAG_NO_EMOJI_REACTIONS=1 << 6; + public static final int FLAG_NO_MEDIA_PREVIEW=1 << 7; public void setAncestryInfo( boolean hasDescendantNeighbor, @@ -252,7 +253,7 @@ public abstract class StatusDisplayItem{ } List imageAttachments=statusForContent.mediaAttachments.stream().filter(att->att.type.isImage()).collect(Collectors.toList()); - if(!imageAttachments.isEmpty()){ + if(!imageAttachments.isEmpty() && ((flags & FLAG_NO_MEDIA_PREVIEW)!=0)){ int color = UiUtils.getThemeColor(fragment.getContext(), R.attr.colorM3SurfaceVariant); for (Attachment att : imageAttachments) { if (att.blurhashPlaceholder == null) { @@ -267,6 +268,11 @@ public abstract class StatusDisplayItem{ statusForContent.sensitiveRevealed=true; contentItems.add(mediaGrid); } + if((flags & FLAG_NO_MEDIA_PREVIEW)==0){ + for(Attachment att:imageAttachments){ + contentItems.add(new FileStatusDisplayItem(parentID, fragment, att, statusForContent)); + } + } for(Attachment att:statusForContent.mediaAttachments){ if(att.type==Attachment.Type.AUDIO){ contentItems.add(new AudioStatusDisplayItem(parentID, fragment, statusForContent, att)); diff --git a/mastodon/src/main/res/values/strings_mo.xml b/mastodon/src/main/res/values/strings_mo.xml index f39fc4c35..e78bddaca 100644 --- a/mastodon/src/main/res/values/strings_mo.xml +++ b/mastodon/src/main/res/values/strings_mo.xml @@ -97,4 +97,5 @@ Unfollow Account Confirm to unfollow %s Recent emoji cleared + Show media preview in timelines \ No newline at end of file