Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public static boolean isRefreshRequired(final Context context, final String key)
|| key.equals(context.getString(R.string.pref_behaviour_nsfw_key))
|| key.equals(context.getString(R.string.pref_behaviour_postcount_key))
|| key.equals(context.getString(R.string.pref_behaviour_comment_min_key))
|| key.equals(context.getString(R.string.pref_behaviour_hide_few_comments_key))
|| key.equals(context.getString(R.string.pref_behaviour_min_comments_key))
|| key.equals(context.getString(R.string.pref_behaviour_pinned_subredditsort_key))
|| key.equals(context.getString(
R.string.pref_behaviour_blocked_subredditsort_key))
Expand Down Expand Up @@ -806,7 +808,6 @@ public static boolean pref_behaviour_video_frame_step() {
return getBoolean(R.string.pref_behaviour_video_frame_step_key,
false);
}

public static boolean pref_behaviour_video_mute_default() {
return getBoolean(
R.string.pref_behaviour_video_mute_default_key,
Expand Down Expand Up @@ -1171,6 +1172,30 @@ public static boolean pref_behaviour_mark_posts_as_read() {
true);
}

public static boolean pref_behaviour_hide_few_comments() {
return getBoolean(
R.string.pref_behaviour_hide_few_comments_key,
false);
}

public static int pref_behaviour_min_comments() {
try {
return Integer.parseInt(getString(
R.string.pref_behaviour_min_comments_key,
"10"));
} catch(final Throwable e) {
return 10;
}
}

public static void pref_behaviour_min_comments(final int value) {
sharedPrefs.edit()
.putString(
getPrefKey(R.string.pref_behaviour_min_comments_key),
String.valueOf(value))
.apply();
}

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 @@ -713,6 +713,15 @@ public void onDataStreamComplete(
&& mPostListingURL.pathType()
!= RedditURLParser.USER_POST_LISTING_URL;

final boolean hideFewComments
= PrefsUtility.pref_behaviour_hide_few_comments();

final int minComments = hideFewComments
? PrefsUtility.pref_behaviour_min_comments()
: 0;

final AtomicInteger filteredCommentCount = new AtomicInteger(0);

final boolean isConnectionWifi = General.isConnectionWifi(activity);

final boolean inlinePreviews
Expand Down Expand Up @@ -856,6 +865,13 @@ public void onDataStreamComplete(
continue;
}

// Skip adding this post if it has too few comments
if(hideFewComments && post.getNum_comments() < minComments) {
mPostsNotShown = true;
filteredCommentCount.incrementAndGet();
continue;
}

if(precacheComments) {
precacheComments(activity, preparedPost, positionInList);
}
Expand Down Expand Up @@ -944,6 +960,19 @@ public void onSuccess(final ImageInfo info) {
mPostListingManager.addViewToItems(emptyView);
}

// Show toast if posts were filtered due to few comments
if(firstDownload && filteredCommentCount.get() > 0) {
final String message =
getContext().getResources().getQuantityString(
R.plurals.posts_filtered_few_comments,
filteredCommentCount.get(),
filteredCommentCount.get(),
minComments);
Toast
.makeText(getContext(), message, Toast.LENGTH_SHORT)
.show();
}

onPostsAdded();

mRequest = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,31 @@ public void onCreatePreferences(
}
}

{
final CheckBoxPreference hideFewCommentsPref =
findPreference(getString(R.string.pref_behaviour_hide_few_comments_key));

if (hideFewCommentsPref != null) {
// Update summary to show current minimum when enabled
updateHideFewCommentsSummary(hideFewCommentsPref);

hideFewCommentsPref.setOnPreferenceChangeListener((preference, newValue) -> {
final boolean isChecked = (Boolean) newValue;

if (isChecked) {
// Show dialog to ask for minimum comment count
showMinCommentsDialog(hideFewCommentsPref);
return false; // Don't change the preference yet
} else {
// Clear the summary when unchecked
hideFewCommentsPref.setSummary(null);
return true;
}
});
}
}



final Preference testNotificationPref =
findPreference(getString(R.string.pref_developer_test_notification_key));
Expand Down Expand Up @@ -796,4 +821,56 @@ public void run() {
}.start();

}

private void updateHideFewCommentsSummary(final CheckBoxPreference preference) {
if (preference.isChecked()) {
final Context context = getActivity();
final int minComments = PrefsUtility.pref_behaviour_min_comments();
final String summary = context.getResources().getQuantityString(
R.plurals.pref_behaviour_hide_few_comments_summary,
minComments,
minComments);
preference.setSummary(summary);
} else {
preference.setSummary(null);
}
}

private void showMinCommentsDialog(final CheckBoxPreference preference) {
final Context context = getActivity();
final int currentValue = PrefsUtility.pref_behaviour_min_comments();

// Create an EditText for number input
final android.widget.EditText editText = new android.widget.EditText(context);
editText.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
editText.setText(String.valueOf(currentValue));
editText.setSelection(editText.getText().length());

new MaterialAlertDialogBuilder(context)
.setTitle(R.string.pref_behaviour_min_comments_dialog_title)
.setView(editText)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
try {
final String input = editText.getText().toString().trim();
final int minComments = Integer.parseInt(input);

if (minComments >= 0 && minComments <= 100_000) {
// Save the minimum comments value
PrefsUtility.pref_behaviour_min_comments(minComments);

// Enable the checkbox
preference.setChecked(true);

// Update the summary
updateHideFewCommentsSummary(preference);
} else {
General.quickToast(context, R.string.error_invalid_number_range);
}
} catch (final NumberFormatException e) {
General.quickToast(context, R.string.error_invalid_number);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
}
23 changes: 21 additions & 2 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,22 @@
<string name="pref_behaviour_hide_read_posts_key" translatable="false">pref_behaviour_hide_read_posts</string>
<string name="pref_behaviour_hide_read_posts_title">Hide read posts</string>

<string name="pref_behaviour_hide_few_comments_key" translatable="false">pref_behaviour_hide_few_comments</string>
<string name="pref_behaviour_hide_few_comments_title">Hide posts with few comments</string>
<string name="pref_behaviour_min_comments_key" translatable="false">pref_behaviour_min_comments</string>
<string name="pref_behaviour_min_comments_title">Minimum comments</string>
<string name="pref_behaviour_min_comments_dialog_title">Minimum number of comments to show post</string>

<plurals name="posts_filtered_few_comments">
<item quantity="one">%1$d post filtered (fewer than %2$d comments)</item>
<item quantity="other">%1$d posts filtered (fewer than %2$d comments)</item>
</plurals>

<plurals name="pref_behaviour_hide_few_comments_summary">
<item quantity="one">Minimum %1$d comment</item>
<item quantity="other">Minimum %1$d comments</item>
</plurals>

<!-- 2018-10-06 -->
<string name="pref_menus_mainmenu_shortcutitems_title">Shortcuts</string>
<string name="pref_menus_mainmenu_shortcutitems_key" translatable="false">pref_menus_mainmenu_shortcutitems_key</string>
Expand Down Expand Up @@ -1507,7 +1523,7 @@

<string name="restore_preferences_error_version_warning_title">Warning</string>
<string name="restore_preferences_error_version_warning_message">The selected file was created by a newer version of RedReader. Restoring the preferences from this file may lead to crashes and instability.</string>

<string name="button_continue_anyway">Continue anyway</string>
<string name="button_cancel">Cancel</string>
<string name="button_restore_preferences">Restore</string>
Expand Down Expand Up @@ -1879,7 +1895,7 @@
<string name="album_pref_all_settings">All settings</string>

<string name="album_link_button">Link</string>

<string name="radio_button_selected">Selected</string>
<string name="radio_button_not_selected">Not selected</string>

Expand All @@ -1891,6 +1907,9 @@
<string name="error_invalid_account_title">Invalid account</string>
<string name="error_invalid_account_message">Selected account is not currently logged in</string>

<string name="error_invalid_number">Invalid number</string>
<string name="error_invalid_number_range">Number must be between 0 and 100000</string>

<!-- 2024-08-04 -->
<string name="album_more_options">More settings</string>

Expand Down
4 changes: 4 additions & 0 deletions src/main/res/xml/prefs_behaviour.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
android:key="@string/pref_behaviour_mark_posts_as_read_key"
android:defaultValue="true"/>

<CheckBoxPreference android:title="@string/pref_behaviour_hide_few_comments_title"
android:key="@string/pref_behaviour_hide_few_comments_key"
android:defaultValue="false"/>

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