aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-02-24 09:48:47 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-02-24 09:48:47 +0000
commitf4bfa4fc401d484379c529c4266e3b78d88306be (patch)
tree1a51b62f87b6e43ecfe287b85b03f77f98ad9ed4 /app
parent8768e71a910284a74824a26db3041c339a3af325 (diff)
downloadinfinity-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')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideTheNumberOfCommentsEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/values/strings.xml1
-rw-r--r--app/src/main/res/xml/post_preferences.xml5
7 files changed, 56 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";
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 @@
<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_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>
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" />
+ <SwitchPreference
+ app:defaultValue="false"
+ app:key="hide_the_number_of_comments"
+ app:title="@string/settings_hide_the_number_of_comments" />
+
<PreferenceCategory
app:title="@string/post_layout_compact" />