Skip to content

Preference to hide posts with few comments #1176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/org/quantumbadger/redreader/common/PrefsUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,19 @@ public static boolean pref_behaviour_hide_read_posts() {
false);
}

// How many comments a post should have to be shown?
public static long pref_behavior_hide_with_few_comments() {
final String value = getString(
R.string.pref_behaviour_hide_posts_min_comments_key,
"-1");
try {
return Long.parseLong(value);
} catch(final Throwable e) {
// The preference is unset, set to "", or somehow set to not-a-number
return -1;
}
}

public enum SharingDomain {
STANDARD_REDDIT("reddit.com"),
SHORT_REDDIT("redd.it"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,12 @@ public void onDataStreamComplete(
&& blockedSubreddits.contains(
new SubredditCanonicalId(post.getSubreddit().getDecoded()));

final long minCommentsOrHide =
PrefsUtility.pref_behavior_hide_with_few_comments();

if(!isPostBlocked
&& (minCommentsOrHide <= 0
|| post.getNum_comments() >= minCommentsOrHide)
&& (!post.getOver_18() || isNsfwAllowed)
&& mPostIds.add(post.getIdAlone())) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public void onCreatePreferences(

final int[] editTextPrefsToUpdate = {
R.string.pref_behaviour_comment_min_key,
R.string.pref_behaviour_hide_posts_min_comments_key,
R.string.pref_reddit_client_id_override_key
};

Expand Down
4 changes: 4 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
<string name="pref_behaviour_nsfw_key" translatable="false">pref_behaviour_nsfw</string>
<string name="pref_behaviour_nsfw_title">Show NSFW content</string>

<string name="pref_behaviour_hide_posts_min_comments_key" translatable="false">pref_behaviour_hide_posts_few_comments</string>
<string name="pref_behaviour_hide_posts_min_comments_title">Hide posts with few comments</string>
<string name="pref_behaviour_hide_posts_min_comments_dialog_title">Hide posts with fewer than those comments (blank or -1 to show all)</string>

<!-- Cache Prefs -->

<string name="pref_cache_pruning">Cache Pruning</string>
Expand Down
7 changes: 7 additions & 0 deletions src/main/res/xml/prefs_behaviour.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@
android:key="@string/pref_behaviour_hide_read_posts_key"
android:defaultValue="false"/>

<EditTextPreference android:title="@string/pref_behaviour_hide_posts_min_comments_title"
android:key="@string/pref_behaviour_hide_posts_min_comments_key"
android:dialogTitle="@string/pref_behaviour_hide_posts_min_comments_dialog_title"
android:inputType="numberSigned"
android:maxLength="5"
android:defaultValue="-1"/>

<ListPreference android:title="@string/pref_behaviour_postcount_title"
android:key="@string/pref_behaviour_postcount_key"
android:entries="@array/pref_behaviour_postcount_items"
Expand Down