From f68e4aad09427570ea0ceb2623576be125cd767a Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 20 Jul 2021 09:01:57 +0800 Subject: New option: Remeber Muting Option in Post Feed. --- .../adapters/PostRecyclerViewAdapter.java | 25 ++++++++++++++++++++-- .../ChangeRememberMutingOptionInPostFeedEvent.java | 9 ++++++++ .../infinityforreddit/fragments/PostFragment.java | 24 +++++++++++++++++++++ .../settings/VideoPreferenceFragment.java | 9 ++++++++ .../utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/video_preferences.xml | 10 +++++++++ 7 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeRememberMutingOptionInPostFeedEvent.java (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index ee3896de..c0f29cce 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -709,7 +709,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter posts = mAdapter.getCurrentList(); @@ -1878,6 +1894,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + @Subscribe + public void onChangeRememberMutingOptionInPostFeedEvent(ChangeRememberMutingOptionInPostFeedEvent event) { + rememberMutingOptionInPostFeed = event.rememberMutingOptionInPostFeedEvent; + if (!event.rememberMutingOptionInPostFeedEvent) { + masterMutingOption = null; + } + } + private void refreshAdapter() { int previousPosition = -1; if (mLinearLayoutManager != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java index f7941534..6a89dcd6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java @@ -22,6 +22,7 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.events.ChangeAutoplayNsfwVideosEvent; import ml.docilealligator.infinityforreddit.events.ChangeMuteAutoplayingVideosEvent; import ml.docilealligator.infinityforreddit.events.ChangeMuteNSFWVideoEvent; +import ml.docilealligator.infinityforreddit.events.ChangeRememberMutingOptionInPostFeedEvent; import ml.docilealligator.infinityforreddit.events.ChangeStartAutoplayVisibleAreaOffsetEvent; import ml.docilealligator.infinityforreddit.events.ChangeVideoAutoplayEvent; import ml.docilealligator.infinityforreddit.Infinity; @@ -43,6 +44,7 @@ public class VideoPreferenceFragment extends PreferenceFragmentCompat { ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY); SwitchPreference muteAutoplayingVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS); + SwitchPreference rememberMutingOptionInPostFeedSwitchPreference = findPreference(SharedPreferencesUtils.REMEMBER_MUTING_OPTION_IN_POST_FEED); SwitchPreference muteNSFWVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_NSFW_VIDEO); SwitchPreference autoplayNsfwVideosSwitchPreference = findPreference(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS); SeekBarPreference startAutoplayVisibleAreaOffsetPortrait = findPreference(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT); @@ -74,6 +76,13 @@ public class VideoPreferenceFragment extends PreferenceFragmentCompat { }); } + if (rememberMutingOptionInPostFeedSwitchPreference != null) { + rememberMutingOptionInPostFeedSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeRememberMutingOptionInPostFeedEvent((Boolean) newValue)); + return true; + }); + } + int orientation = getResources().getConfiguration().orientation; if (startAutoplayVisibleAreaOffsetPortrait != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index 0f2c2a33..a9a75626 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -183,6 +183,7 @@ public class SharedPreferencesUtils { public static final String ENABLE_MATERIAL_YOU = "enable_material_you"; public static final String APPLY_MATERIAL_YOU = "apply_material_you"; public static final String VIDEO_PLAYER_AUTOMATIC_LANDSCAPE_ORIENTATION = "video_player_automatic_landscape_orientation"; + public static final String REMEMBER_MUTING_OPTION_IN_POST_FEED = "remember_muting_option_in_post_feed"; public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 276f2746..f44c7c92 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -586,6 +586,7 @@ Disable NSFW Forever Show Only One Comment Level Indicator Switch to Landscape Orientation in Video Player Automatically + Remember Muting Option in Post Feed Cannot get the link diff --git a/app/src/main/res/xml/video_preferences.xml b/app/src/main/res/xml/video_preferences.xml index 93ccff6b..93a77e9f 100644 --- a/app/src/main/res/xml/video_preferences.xml +++ b/app/src/main/res/xml/video_preferences.xml @@ -19,6 +19,11 @@ app:key="automatically_try_redgifs" app:title="@string/settings_automatically_try_redgifs_title" /> + + + +