From 5456f4fbea0e184b1d07e9f75ff31ba7f9567299 Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Mon, 28 Aug 2023 11:30:08 -0300 Subject: [PATCH] refactor: tidy things up with the show posts with missing alt text IT DOESNT WORK YET GODDAMNIT --- .../android/GlobalUserPreferences.java | 8 +++++--- .../settings/SettingsBehaviorFragment.java | 5 +++-- .../android/model/AltTextFilter.java | 4 +--- .../WarningFilteredStatusDisplayItem.java | 2 ++ .../android/utils/StatusFilterPredicate.java | 19 +++++++++++++++---- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index 7220be48b..5b04a6c8b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -47,7 +47,6 @@ public class GlobalUserPreferences{ public static boolean reduceMotion; public static boolean showAltIndicator; public static boolean showNoAltIndicator; - public static boolean showPostsWithoutAlt; public static boolean enablePreReleases; public static PrefixRepliesMode prefixReplies; public static boolean collapseLongPosts; @@ -74,6 +73,7 @@ public class GlobalUserPreferences{ public static boolean swapBookmarkWithBoostAction; public static boolean loadRemoteAccountFollowers; public static boolean mentionRebloggerAutomatically; + public static boolean showPostsWithoutAlt; public static SharedPreferences getPrefs(){ return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE); @@ -118,7 +118,6 @@ public class GlobalUserPreferences{ reduceMotion=prefs.getBoolean("reduceMotion", false); showAltIndicator=prefs.getBoolean("showAltIndicator", true); showNoAltIndicator=prefs.getBoolean("showNoAltIndicator", true); - showPostsWithoutAlt =prefs.getBoolean("showPostsWithoutAlt", true); enablePreReleases=prefs.getBoolean("enablePreReleases", false); prefixReplies=PrefixRepliesMode.valueOf(prefs.getString("prefixReplies", PrefixRepliesMode.NEVER.name())); collapseLongPosts=prefs.getBoolean("collapseLongPosts", true); @@ -148,6 +147,8 @@ public class GlobalUserPreferences{ swapBookmarkWithBoostAction=prefs.getBoolean("swapBookmarkWithBoostAction", false); loadRemoteAccountFollowers=prefs.getBoolean("loadRemoteAccountFollowers", true); mentionRebloggerAutomatically=prefs.getBoolean("mentionRebloggerAutomatically", false); + showPostsWithoutAlt =prefs.getBoolean("showPostsWithoutAlt", true); + theme=ThemePreference.values()[prefs.getInt("theme", 0)]; @@ -196,7 +197,6 @@ public class GlobalUserPreferences{ .putBoolean("reduceMotion", reduceMotion) .putBoolean("showAltIndicator", showAltIndicator) .putBoolean("showNoAltIndicator", showNoAltIndicator) - .putBoolean("showPostsWithoutAlt", showPostsWithoutAlt) .putBoolean("enablePreReleases", enablePreReleases) .putString("prefixReplies", prefixReplies.name()) .putBoolean("collapseLongPosts", collapseLongPosts) @@ -227,6 +227,8 @@ public class GlobalUserPreferences{ .putBoolean("showDividers", showDividers) .putBoolean("relocatePublishButton", relocatePublishButton) .putBoolean("enableDeleteNotifications", enableDeleteNotifications) + .putBoolean("showPostsWithoutAlt", showPostsWithoutAlt) + .putInt("theme", theme.ordinal()) .apply(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java index fdcef246f..51ee9d0f8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java @@ -1,7 +1,6 @@ package org.joinmastodon.android.fragments.settings; import android.os.Bundle; -import android.provider.Settings; import androidx.annotation.StringRes; @@ -34,7 +33,7 @@ public class SettingsBehaviorFragment extends BaseSettingsFragment impleme private CheckableListItem forwardReportsItem, remoteLoadingItem, showBoostsItem, showRepliesItem, loadNewPostsItem, seeNewPostsBtnItem, overlayMediaItem; // MOSHIDON - private CheckableListItem mentionRebloggerAutomaticallyItem, hapticFeedbackItem, unlistedRepliesItem; + private CheckableListItem mentionRebloggerAutomaticallyItem, hapticFeedbackItem, unlistedRepliesItem, showPostsWithoutAltItem; @Override public void onCreate(Bundle savedInstanceState){ @@ -50,6 +49,7 @@ public class SettingsBehaviorFragment extends BaseSettingsFragment impleme List> items = new ArrayList<>(List.of( languageItem=new ListItem<>(getString(R.string.default_post_language), postLanguage!=null ? postLanguage.getDisplayName(getContext()) : null, R.drawable.ic_fluent_local_language_24_regular, this::onDefaultLanguageClick), altTextItem=new CheckableListItem<>(R.string.settings_alt_text_reminders, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.altTextReminders, R.drawable.ic_fluent_image_alt_text_24_regular, ()->toggleCheckableItem(altTextItem)), + showPostsWithoutAltItem=new CheckableListItem<>(R.string.mo_settings_show_posts_without_alt, R.string.mo_settings_show_posts_without_alt_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showPostsWithoutAlt, R.drawable.ic_fluent_eye_tracking_on_24_regular, ()->toggleCheckableItem(showPostsWithoutAltItem)), playGifsItem=new CheckableListItem<>(R.string.settings_gif, R.string.mo_setting_play_gif_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.playGifs, R.drawable.ic_fluent_gif_24_regular, ()->toggleCheckableItem(playGifsItem)), unlistedRepliesItem=new CheckableListItem<>(R.string.mo_change_default_reply_visibility_to_unlisted, R.string.mo_setting_default_reply_privacy_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.defaultToUnlistedReplies, R.drawable.ic_fluent_lock_open_24_regular, ()->toggleCheckableItem(unlistedRepliesItem)), overlayMediaItem=new CheckableListItem<>(R.string.sk_settings_continues_playback, R.string.sk_settings_continues_playback_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.overlayMedia, R.drawable.ic_fluent_play_circle_hint_24_regular, ()->toggleCheckableItem(overlayMediaItem)), @@ -183,6 +183,7 @@ public class SettingsBehaviorFragment extends BaseSettingsFragment impleme GlobalUserPreferences.mentionRebloggerAutomatically=mentionRebloggerAutomaticallyItem.checked; GlobalUserPreferences.hapticFeedback=hapticFeedbackItem.checked; GlobalUserPreferences.defaultToUnlistedReplies=unlistedRepliesItem.checked; + GlobalUserPreferences.showPostsWithoutAlt=showPostsWithoutAltItem.checked; GlobalUserPreferences.save(); AccountLocalPreferences lp=getLocalPrefs(); lp.showBoosts=showBoostsItem.checked; diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/AltTextFilter.java b/mastodon/src/main/java/org/joinmastodon/android/model/AltTextFilter.java index 2353fee96..4168e6505 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/AltTextFilter.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/AltTextFilter.java @@ -1,12 +1,10 @@ package org.joinmastodon.android.model; -import org.joinmastodon.android.GlobalUserPreferences; -import org.joinmastodon.android.R; import org.jsoup.internal.StringUtil; import java.util.EnumSet; -public class AltTextFilter extends Filter { +public class AltTextFilter extends LegacyFilter { public AltTextFilter(FilterAction filterAction, FilterContext firstContext, FilterContext... restContexts) { this.filterAction = filterAction; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/WarningFilteredStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/WarningFilteredStatusDisplayItem.java index 55b7782be..a8e6d4751 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/WarningFilteredStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/WarningFilteredStatusDisplayItem.java @@ -8,7 +8,9 @@ import android.widget.TextView; import org.joinmastodon.android.R; import org.joinmastodon.android.fragments.BaseStatusListFragment; +import org.joinmastodon.android.model.AltTextFilter; import org.joinmastodon.android.model.Filter; +import org.joinmastodon.android.model.LegacyFilter; import org.joinmastodon.android.model.Status; import java.util.List; diff --git a/mastodon/src/main/java/org/joinmastodon/android/utils/StatusFilterPredicate.java b/mastodon/src/main/java/org/joinmastodon/android/utils/StatusFilterPredicate.java index 35c224e88..febbd8cf6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/utils/StatusFilterPredicate.java +++ b/mastodon/src/main/java/org/joinmastodon/android/utils/StatusFilterPredicate.java @@ -1,6 +1,16 @@ package org.joinmastodon.android.utils; +import static org.joinmastodon.android.model.FilterAction.HIDE; +import static org.joinmastodon.android.model.FilterAction.WARN; +import static org.joinmastodon.android.model.FilterContext.ACCOUNT; +import static org.joinmastodon.android.model.FilterContext.HOME; +import static org.joinmastodon.android.model.FilterContext.NOTIFICATIONS; +import static org.joinmastodon.android.model.FilterContext.PUBLIC; +import static org.joinmastodon.android.model.FilterContext.THREAD; + +import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.api.session.AccountSessionManager; +import org.joinmastodon.android.model.AltTextFilter; import org.joinmastodon.android.model.LegacyFilter; import org.joinmastodon.android.model.FilterAction; import org.joinmastodon.android.model.FilterContext; @@ -34,7 +44,7 @@ public class StatusFilterPredicate implements Predicate{ } public StatusFilterPredicate(List filters, FilterContext context){ - this(filters, context, FilterAction.HIDE); + this(filters, context, HIDE); } /** @@ -52,7 +62,7 @@ public class StatusFilterPredicate implements Predicate{ * @param context null makes the predicate pass automatically */ public StatusFilterPredicate(String accountID, FilterContext context){ - this(accountID, context, FilterAction.HIDE); + this(accountID, context, HIDE); } /** @@ -77,11 +87,12 @@ public class StatusFilterPredicate implements Predicate{ // only apply filters for given context .filter(filter -> filter.context.contains(context)) // treating filterAction = null (from filters list) as FilterAction.HIDE - .filter(filter -> filter.filterAction == null ? action == FilterAction.HIDE : filter.filterAction == action) + .filter(filter -> filter.filterAction == null ? action == HIDE : filter.filterAction == action) .findAny(); //Apply client filters if no server filter is triggered - if (applyingFilter.isEmpty()) { + if (applyingFilter.isEmpty() && clientFilters != null) { + System.out.println("It got here"); applyingFilter = clientFilters.stream() .filter(filter -> filter.context.contains(context)) .filter(filter -> filter.filterAction == null ? action == HIDE : filter.filterAction == action)