diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-02-24 09:48:47 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-02-24 09:48:47 +0000 |
commit | f4bfa4fc401d484379c529c4266e3b78d88306be (patch) | |
tree | 1a51b62f87b6e43ecfe287b85b03f77f98ad9ed4 /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | 8768e71a910284a74824a26db3041c339a3af325 (diff) | |
download | infinity-for-reddit-f4bfa4fc401d484379c529c4266e3b78d88306be.tar infinity-for-reddit-f4bfa4fc401d484379c529c4266e3b78d88306be.tar.gz infinity-for-reddit-f4bfa4fc401d484379c529c4266e3b78d88306be.tar.bz2 infinity-for-reddit-f4bfa4fc401d484379c529c4266e3b78d88306be.tar.lz infinity-for-reddit-f4bfa4fc401d484379c529c4266e3b78d88306be.tar.xz infinity-for-reddit-f4bfa4fc401d484379c529c4266e3b78d88306be.tar.zst infinity-for-reddit-f4bfa4fc401d484379c529c4266e3b78d88306be.zip |
New option: Hide the number of comments.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
5 files changed, 50 insertions, 2 deletions
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<Post, RecyclerView private boolean mHideTheNumberOfAwards; private boolean mHideSubredditAndUserPrefix; private boolean mHideTheNumberOfVotes; + private boolean mHideTheNumberOfComments; private Drawable mCommentIcon; private NetworkState networkState; private ExoCreator mExoCreator; @@ -287,6 +288,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mHideTheNumberOfAwards = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false); mHideSubredditAndUserPrefix = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false); mHideTheNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false); + mHideTheNumberOfComments = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false); mPostLayout = postLayout; @@ -662,7 +664,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostBaseViewHolder) holder).crosspostImageView.setVisibility(View.VISIBLE); } - ((PostBaseViewHolder) holder).commentsCountTextView.setText(Integer.toString(post.getNComments())); + if (!mHideTheNumberOfComments) { + ((PostBaseViewHolder) holder).commentsCountTextView.setVisibility(View.VISIBLE); + ((PostBaseViewHolder) holder).commentsCountTextView.setText(Integer.toString(post.getNComments())); + } else { + ((PostBaseViewHolder) holder).commentsCountTextView.setVisibility(View.GONE); + } if (post.isSaved()) { ((PostBaseViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); @@ -1241,7 +1248,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView break; } - ((PostCompactBaseViewHolder) holder).commentsCountTextView.setText(Integer.toString(post.getNComments())); + if (!mHideTheNumberOfComments) { + ((PostCompactBaseViewHolder) holder).commentsCountTextView.setVisibility(View.VISIBLE); + ((PostCompactBaseViewHolder) holder).commentsCountTextView.setText(Integer.toString(post.getNComments())); + } else { + ((PostCompactBaseViewHolder) holder).commentsCountTextView.setVisibility(View.GONE); + } if (post.isSaved()) { ((PostCompactBaseViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); @@ -1798,6 +1810,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mHideTheNumberOfVotes = hideTheNumberOfVotes; } + public void setHideTheNumberOfComments(boolean hideTheNumberOfComments) { + mHideTheNumberOfComments = hideTheNumberOfComments; + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideTheNumberOfCommentsEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideTheNumberOfCommentsEvent.java new file mode 100644 index 00000000..7a4ec05f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideTheNumberOfCommentsEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.events; + +public class ChangeHideTheNumberOfCommentsEvent { + public boolean hideTheNumberOfComments; + + public ChangeHideTheNumberOfCommentsEvent(boolean hideTheNumberOfComments) { + this.hideTheNumberOfComments = hideTheNumberOfComments; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 60fd460d..44e4e613 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -87,6 +87,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeEnableSwipeActionSwitch import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent; +import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfCommentsEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfVotesEvent; import ml.docilealligator.infinityforreddit.events.ChangeLongPressToHideToolbarInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeMuteAutoplayingVideosEvent; @@ -1675,6 +1676,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + @Subscribe + public void onChangeHideTheNumberOfCommentsEvent(ChangeHideTheNumberOfCommentsEvent event) { + if (mAdapter != null) { + mAdapter.setHideTheNumberOfComments(event.hideTheNumberOfComments); + refreshAdapter(); + } + } + private void refreshAdapter() { int previousPosition = -1; if (mLinearLayoutManager != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java index b7d0f205..c45a2c1a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.settings; import android.os.Bundle; import androidx.preference.ListPreference; +import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; @@ -14,6 +15,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent; +import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfCommentsEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfVotesEvent; import ml.docilealligator.infinityforreddit.events.ChangeLongPressToHideToolbarInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeShowAbsoluteNumberOfVotesEvent; @@ -37,6 +39,7 @@ public class PostPreferenceFragment extends PreferenceFragmentCompat { SwitchPreference hideTheNumberOfAwardsSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS); SwitchPreference hideSubredditAndUserPrefixSwitch = findPreference(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX); SwitchPreference hideTheNumberOfVotesSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES); + SwitchPreference hideTheNumberOfCommentsSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS); if (defaultPostLayoutList != null) { defaultPostLayoutList.setOnPreferenceChangeListener((preference, newValue) -> { @@ -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"; |