diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-12-24 05:00:06 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-12-24 05:00:06 +0000 |
commit | 68bdee39524339eb986c6710e63730be2ef856f2 (patch) | |
tree | 725421b910794ea371514be9036d32ba09143ebf /app/src | |
parent | c293e9f22ff34f07f62ca3afba6e508aec2226ff (diff) | |
download | infinity-for-reddit-68bdee39524339eb986c6710e63730be2ef856f2.tar infinity-for-reddit-68bdee39524339eb986c6710e63730be2ef856f2.tar.gz infinity-for-reddit-68bdee39524339eb986c6710e63730be2ef856f2.tar.bz2 infinity-for-reddit-68bdee39524339eb986c6710e63730be2ef856f2.tar.lz infinity-for-reddit-68bdee39524339eb986c6710e63730be2ef856f2.tar.xz infinity-for-reddit-68bdee39524339eb986c6710e63730be2ef856f2.tar.zst infinity-for-reddit-68bdee39524339eb986c6710e63730be2ef856f2.zip |
New feature: Hide read posts automatically.
Diffstat (limited to '')
7 files changed, 57 insertions, 17 deletions
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<Post, RecyclerView private boolean mDisableImagePreview = false; private boolean mMarkPostsAsRead; private boolean mMarkPostsAsReadAfterVoting; + private boolean mHideReadPostsAutomatically; private Drawable mCommentIcon; private NetworkState networkState; private ExoCreator mExoCreator; @@ -260,6 +261,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mMarkPostsAsRead = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false); mMarkPostsAsReadAfterVoting = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false); + mHideReadPostsAutomatically = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false); mPostLayout = postLayout; @@ -401,7 +403,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView Post post = getItem(position); if (post != null) { if (post.isRead()) { - if (position < mHideReadPostsIndex) { + if (mHideReadPostsAutomatically || position < mHideReadPostsIndex) { post.hidePostInRecyclerView(); holder.itemView.setVisibility(View.GONE); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams(); @@ -723,7 +725,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView Post post = getItem(position); if (post != null) { if (post.isRead()) { - if (position < mHideReadPostsIndex) { + if (mHideReadPostsAutomatically || position < mHideReadPostsIndex) { post.hidePostInRecyclerView(); holder.itemView.setVisibility(View.GONE); ViewGroup.LayoutParams params = holder.itemView.getLayoutParams(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java index eebfe17f..5d5a9e16 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java @@ -39,6 +39,10 @@ public class PostHistoryFragment extends Fragment { LinearLayout markPostsAsReadAfterVotingLinearLayout; @BindView(R.id.mark_posts_as_read_after_voting_switch_post_history_fragment) SwitchMaterial markPostsAsReadAfterVotingSwitch; + @BindView(R.id.hide_read_posts_automatically_linear_layout_post_history_fragment) + LinearLayout hideReadPostsAutomaticallyLinearLayout; + @BindView(R.id.hide_read_posts_automatically_switch_post_history_fragment) + SwitchMaterial hideReadPostsAutomaticallySwitch; @Inject @Named("post_history") SharedPreferences postHistorySharedPreferences; @@ -67,25 +71,27 @@ public class PostHistoryFragment extends Fragment { } markPostsAsReadSwitch.setChecked(postHistorySharedPreferences.getBoolean( - (accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false)); + accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false)); markPostsAsReadAfterVotingSwitch.setChecked(postHistorySharedPreferences.getBoolean( - (accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false)); + accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false)); + hideReadPostsAutomaticallySwitch.setChecked(postHistorySharedPreferences.getBoolean( + accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false)); markPostsAsReadLinearLayout.setOnClickListener(view -> { 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"; diff --git a/app/src/main/res/layout/fragment_post_history.xml b/app/src/main/res/layout/fragment_post_history.xml index 7eb07801..9ed65c7f 100644 --- a/app/src/main/res/layout/fragment_post_history.xml +++ b/app/src/main/res/layout/fragment_post_history.xml @@ -25,6 +25,11 @@ android:fontFamily="?attr/font_family" app:drawableStartCompat="@drawable/ic_info_preference_24dp" /> + <View + android:layout_width="match_parent" + android:layout_height="1dp" + android:background="@color/dividerColor" /> + <LinearLayout android:id="@+id/mark_posts_as_read_linear_layout_post_history_fragment" android:layout_width="match_parent" @@ -88,6 +93,37 @@ </LinearLayout> + <LinearLayout + android:id="@+id/hide_read_posts_automatically_linear_layout_post_history_fragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="4dp" + android:paddingBottom="4dp" + android:paddingStart="72dp" + android:paddingEnd="16dp" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground"> + + <TextView + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:layout_marginEnd="16dp" + android:layout_gravity="center_vertical" + android:text="@string/settings_hide_read_posts_automatically_title" + android:textColor="?attr/primaryTextColor" + android:textSize="?attr/font_16" + android:fontFamily="?attr/font_family" /> + + <com.google.android.material.switchmaterial.SwitchMaterial + android:id="@+id/hide_read_posts_automatically_switch_post_history_fragment" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" /> + + </LinearLayout> + </LinearLayout> </androidx.core.widget.NestedScrollView>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ea62ed9c..c683d45e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -517,6 +517,7 @@ <string name="settings_post_history_title">Post History</string> <string name="settings_mark_posts_as_read_title">Mark Posts As Read</string> <string name="settings_mark_posts_as_read_after_voting_title">Mark Posts As Read After Voting</string> + <string name="settings_hide_read_posts_automatically_title">Hide Read Posts Automatically</string> <string name="no_link_available">Cannot get the link</string> diff --git a/app/src/main/res/xml/post_history.xml b/app/src/main/res/xml/post_history.xml deleted file mode 100644 index 624ed13a..00000000 --- a/app/src/main/res/xml/post_history.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> - -</PreferenceScreen>
\ No newline at end of file |