From f4bfa4fc401d484379c529c4266e3b78d88306be Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 24 Feb 2021 17:48:47 +0800 Subject: [PATCH] New option: Hide the number of comments. --- .../adapters/PostRecyclerViewAdapter.java | 20 +++++++++++++++++-- .../ChangeHideTheNumberOfCommentsEvent.java | 9 +++++++++ .../fragments/PostFragment.java | 9 +++++++++ .../settings/PostPreferenceFragment.java | 13 ++++++++++++ .../utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/post_preferences.xml | 5 +++++ 7 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideTheNumberOfCommentsEvent.java 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 46f3f7d9..e1911342 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -212,6 +212,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { @@ -107,5 +110,15 @@ public class PostPreferenceFragment extends PreferenceFragmentCompat { return true; }); } + + if (hideTheNumberOfCommentsSwitch != null) { + hideTheNumberOfCommentsSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + EventBus.getDefault().post(new ChangeHideTheNumberOfCommentsEvent((Boolean) newValue)); + return true; + } + }); + } } } \ No newline at end of file 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 abef106a..aa2d7c3f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -167,6 +167,7 @@ public class SharedPreferencesUtils { public static final String HIDE_THE_NUMBER_OF_AWARDS = "hide_the_number_of_awards"; public static final String HIDE_SUBREDDIT_AND_USER_PREFIX = "hide_subreddit_and_user_prefix"; public static final String HIDE_THE_NUMBER_OF_VOTES = "hide_the_number_of_votes"; + public static final String HIDE_THE_NUMBER_OF_COMMENTS = "hide_the_number_of_comments"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 92097b7c..1825ef3e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -539,6 +539,7 @@ Hide the Number of Awards Hide Subreddit and User Prefix Hide the Number of Votes + Hide the Number of Comments Cannot get the link diff --git a/app/src/main/res/xml/post_preferences.xml b/app/src/main/res/xml/post_preferences.xml index c695d63c..7e47f86c 100644 --- a/app/src/main/res/xml/post_preferences.xml +++ b/app/src/main/res/xml/post_preferences.xml @@ -34,6 +34,11 @@ app:key="hide_the_number_of_votes" app:title="@string/settings_hide_the_number_of_votes" /> + +