From a6f728a96b1f3968e434678fc56ed2dd38b6b54a Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 31 Dec 2020 17:00:25 +0800 Subject: Mark posts as read on scroll. --- .../adapters/PostRecyclerViewAdapter.java | 56 +++++++++++++++------- .../settings/PostHistoryFragment.java | 10 ++++ .../utils/SharedPreferencesUtils.java | 1 + 3 files changed, 49 insertions(+), 18 deletions(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') 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 970426c3..ccb2880c 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= 0) { + Post post = getItem(position); + ((PostBaseViewHolder) holder).markPostRead(post, false); + } + } ((PostBaseViewHolder) holder).itemView.setVisibility(View.VISIBLE); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams(); params.height = ViewGroup.LayoutParams.WRAP_CONTENT; @@ -1366,6 +1375,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter= 0) { + Post post = getItem(position); + ((PostCompactBaseViewHolder) holder).markPostRead(post, false); + } + } ((PostCompactBaseViewHolder) holder).itemView.setVisibility(View.VISIBLE); ViewGroup.LayoutParams params = holder.itemView.getLayoutParams(); params.height = ViewGroup.LayoutParams.WRAP_CONTENT; @@ -1590,7 +1606,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter= 0 && canStartActivity) { Post post = getItem(position); if (post != null) { - markPostRead(post); + markPostRead(post, true); canStartActivity = false; Intent intent = new Intent(mActivity, ViewPostDetailActivity.class); @@ -1706,7 +1722,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, b).apply()); + markPostsAsReadOnScrollLinearLayout.setOnClickListener(view -> markPostsAsReadOnScrollSwitch.performClick()); + + markPostsAsReadOnScrollSwitch.setOnCheckedChangeListener((compoundButton, b) -> postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, b).apply()); + hideReadPostsAutomaticallyLinearLayout.setOnClickListener(view -> hideReadPostsAutomaticallySwitch.performClick()); hideReadPostsAutomaticallySwitch.setOnCheckedChangeListener((compoundButton, b) -> postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, b).apply()); 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 a8f0aa34..8cfd5ce5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -222,6 +222,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 MARK_POSTS_AS_READ_ON_SCROLL_BASE = "_mark_posts_as_read_on_scroll"; public static final String HIDE_READ_POSTS_AUTOMATICALLY_BASE = "_hide_read_posts_automatically"; //Legacy Settings -- cgit v1.2.3