New option: Hide the number of comments.

This commit is contained in:
Alex Ning 2021-02-24 17:48:47 +08:00
parent 8768e71a91
commit f4bfa4fc40
7 changed files with 56 additions and 2 deletions

View File

@ -212,6 +212,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean mHideTheNumberOfAwards; private boolean mHideTheNumberOfAwards;
private boolean mHideSubredditAndUserPrefix; private boolean mHideSubredditAndUserPrefix;
private boolean mHideTheNumberOfVotes; private boolean mHideTheNumberOfVotes;
private boolean mHideTheNumberOfComments;
private Drawable mCommentIcon; private Drawable mCommentIcon;
private NetworkState networkState; private NetworkState networkState;
private ExoCreator mExoCreator; private ExoCreator mExoCreator;
@ -287,6 +288,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mHideTheNumberOfAwards = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false); mHideTheNumberOfAwards = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false);
mHideSubredditAndUserPrefix = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false); mHideSubredditAndUserPrefix = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false);
mHideTheNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false); mHideTheNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false);
mHideTheNumberOfComments = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false);
mPostLayout = postLayout; mPostLayout = postLayout;
@ -662,7 +664,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostBaseViewHolder) holder).crosspostImageView.setVisibility(View.VISIBLE); ((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()) { if (post.isSaved()) {
((PostBaseViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); ((PostBaseViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
@ -1241,7 +1248,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
break; 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()) { if (post.isSaved()) {
((PostCompactBaseViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); ((PostCompactBaseViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
@ -1798,6 +1810,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mHideTheNumberOfVotes = hideTheNumberOfVotes; mHideTheNumberOfVotes = hideTheNumberOfVotes;
} }
public void setHideTheNumberOfComments(boolean hideTheNumberOfComments) {
mHideTheNumberOfComments = hideTheNumberOfComments;
}
@Override @Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder); super.onViewRecycled(holder);

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.events;
public class ChangeHideTheNumberOfCommentsEvent {
public boolean hideTheNumberOfComments;
public ChangeHideTheNumberOfCommentsEvent(boolean hideTheNumberOfComments) {
this.hideTheNumberOfComments = hideTheNumberOfComments;
}
}

View File

@ -87,6 +87,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeEnableSwipeActionSwitch
import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent; import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfCommentsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfVotesEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.events.ChangeLongPressToHideToolbarInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeLongPressToHideToolbarInCompactLayoutEvent;
import ml.docilealligator.infinityforreddit.events.ChangeMuteAutoplayingVideosEvent; 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() { private void refreshAdapter() {
int previousPosition = -1; int previousPosition = -1;
if (mLinearLayoutManager != null) { if (mLinearLayoutManager != null) {

View File

@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.settings;
import android.os.Bundle; import android.os.Bundle;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference; 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.ChangeHidePostTypeEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfCommentsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfVotesEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.events.ChangeLongPressToHideToolbarInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeLongPressToHideToolbarInCompactLayoutEvent;
import ml.docilealligator.infinityforreddit.events.ChangeShowAbsoluteNumberOfVotesEvent; 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 hideTheNumberOfAwardsSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS);
SwitchPreference hideSubredditAndUserPrefixSwitch = findPreference(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX); SwitchPreference hideSubredditAndUserPrefixSwitch = findPreference(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX);
SwitchPreference hideTheNumberOfVotesSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES); SwitchPreference hideTheNumberOfVotesSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES);
SwitchPreference hideTheNumberOfCommentsSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS);
if (defaultPostLayoutList != null) { if (defaultPostLayoutList != null) {
defaultPostLayoutList.setOnPreferenceChangeListener((preference, newValue) -> { defaultPostLayoutList.setOnPreferenceChangeListener((preference, newValue) -> {
@ -107,5 +110,15 @@ public class PostPreferenceFragment extends PreferenceFragmentCompat {
return true; 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;
}
});
}
} }
} }

View File

@ -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_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_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_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_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count"; public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count";

View File

@ -539,6 +539,7 @@
<string name="settings_hide_the_number_of_awards">Hide the Number of Awards</string> <string name="settings_hide_the_number_of_awards">Hide the Number of Awards</string>
<string name="settings_hide_subreddit_and_user_prefix">Hide Subreddit and User Prefix</string> <string name="settings_hide_subreddit_and_user_prefix">Hide Subreddit and User Prefix</string>
<string name="settings_hide_the_number_of_votes">Hide the Number of Votes</string> <string name="settings_hide_the_number_of_votes">Hide the Number of Votes</string>
<string name="settings_hide_the_number_of_comments">Hide the Number of Comments</string>
<string name="no_link_available">Cannot get the link</string> <string name="no_link_available">Cannot get the link</string>

View File

@ -34,6 +34,11 @@
app:key="hide_the_number_of_votes" app:key="hide_the_number_of_votes"
app:title="@string/settings_hide_the_number_of_votes" /> app:title="@string/settings_hide_the_number_of_votes" />
<SwitchPreference
app:defaultValue="false"
app:key="hide_the_number_of_comments"
app:title="@string/settings_hide_the_number_of_comments" />
<PreferenceCategory <PreferenceCategory
app:title="@string/post_layout_compact" /> app:title="@string/post_layout_compact" />