From 68bdee39524339eb986c6710e63730be2ef856f2 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 24 Dec 2020 13:00:06 +0800 Subject: New feature: Hide read posts automatically. --- .../infinityforreddit/PostFilter.java | 2 -- .../adapters/PostRecyclerViewAdapter.java | 6 ++++-- .../settings/PostHistoryFragment.java | 24 ++++++++++++++-------- .../utils/SharedPreferencesUtils.java | 1 + 4 files changed, 20 insertions(+), 13 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java index 680e1e59..7e236624 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java @@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit; import android.os.Parcel; import android.os.Parcelable; -import android.util.Log; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -34,7 +33,6 @@ public class PostFilter implements Parcelable { public static boolean isPostAllowed(Post post, PostFilter postFilter) { if (postFilter == null || post == null) { - Log.i("asdasfd", "s " + post.getTitle()); return true; } if (post.isNSFW() && !postFilter.allowNSFW) { 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 defbb0a5..fd76f4f7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -196,6 +196,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { markPostsAsReadSwitch.performClick(); }); markPostsAsReadSwitch.setOnCheckedChangeListener((compoundButton, b) -> - postHistorySharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) - + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, b).apply()); + postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, b).apply()); - markPostsAsReadAfterVotingLinearLayout.setOnClickListener(view -> { - markPostsAsReadAfterVotingSwitch.performClick(); - }); + markPostsAsReadAfterVotingLinearLayout.setOnClickListener(view -> markPostsAsReadAfterVotingSwitch.performClick()); markPostsAsReadAfterVotingSwitch.setOnCheckedChangeListener((compoundButton, b) -> - postHistorySharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) - + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, b).apply()); + postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, b).apply()); + + hideReadPostsAutomaticallyLinearLayout.setOnClickListener(view -> hideReadPostsAutomaticallySwitch.performClick()); + + hideReadPostsAutomaticallySwitch.setOnCheckedChangeListener((compoundButton, b) -> postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, b).apply()); return rootView; } 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 72d85aa6..1f3fab50 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -221,6 +221,7 @@ public class SharedPreferencesUtils { public static final String POST_HISTORY_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.post_history"; public static final String MARK_POSTS_AS_READ_BASE = "_mark_posts_as_read"; public static final String MARK_POSTS_AS_READ_AFTER_VOTING_BASE = "_mark_posts_as_read_after_voting"; + public static final String HIDE_READ_POSTS_AUTOMATICALLY_BASE = "_hide_read_posts_automatically"; //Legacy Settings public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title"; -- cgit v1.2.3