aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-12-31 09:00:25 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-12-31 09:00:25 +0000
commita6f728a96b1f3968e434678fc56ed2dd38b6b54a (patch)
treecbb0898d77d9515221ac7f7f6da733fa51e93f97 /app/src/main/java/ml
parent321f4da6230fd6197e5e0773db3a8d28b01e5215 (diff)
downloadinfinity-for-reddit-a6f728a96b1f3968e434678fc56ed2dd38b6b54a.tar
infinity-for-reddit-a6f728a96b1f3968e434678fc56ed2dd38b6b54a.tar.gz
infinity-for-reddit-a6f728a96b1f3968e434678fc56ed2dd38b6b54a.tar.bz2
infinity-for-reddit-a6f728a96b1f3968e434678fc56ed2dd38b6b54a.tar.lz
infinity-for-reddit-a6f728a96b1f3968e434678fc56ed2dd38b6b54a.tar.xz
infinity-for-reddit-a6f728a96b1f3968e434678fc56ed2dd38b6b54a.tar.zst
infinity-for-reddit-a6f728a96b1f3968e434678fc56ed2dd38b6b54a.zip
Mark posts as read on scroll.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java56
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java1
3 files changed, 49 insertions, 18 deletions
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<Post, RecyclerView
private boolean mDisableImagePreview = false;
private boolean mMarkPostsAsRead;
private boolean mMarkPostsAsReadAfterVoting;
+ private boolean mMarkPostsAsReadOnScroll;
private boolean mHideReadPostsAutomatically;
private Drawable mCommentIcon;
private NetworkState networkState;
@@ -261,6 +262,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);
+ mMarkPostsAsReadOnScroll = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false);
mHideReadPostsAutomatically = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false);
mPostLayout = postLayout;
@@ -1318,6 +1320,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
if (holder instanceof PostBaseViewHolder) {
+ if (mMarkPostsAsReadOnScroll) {
+ int position = holder.getAdapterPosition();
+ if (position < super.getItemCount() && position >= 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<Post, RecyclerView
((PostBaseViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor);
((PostBaseViewHolder) holder).downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
} else if (holder instanceof PostCompactBaseViewHolder) {
+ if (mMarkPostsAsReadOnScroll) {
+ int position = holder.getAdapterPosition();
+ if (position < super.getItemCount() && position >= 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<Post, RecyclerView
if (position >= 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<Post, RecyclerView
}
if (mMarkPostsAsReadAfterVoting) {
- markPostRead(post);
+ markPostRead(post, true);
}
if (post.isArchived()) {
@@ -1796,7 +1812,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
if (mMarkPostsAsReadAfterVoting) {
- markPostRead(post);
+ markPostRead(post, true);
}
if (post.isArchived()) {
@@ -1949,13 +1965,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
});
}
- void markPostRead(Post post) {
+ void markPostRead(Post post, boolean changePostItemColor) {
if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) {
post.markAsRead();
- cardView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor));
- titleTextView.setTextColor(mReadPostTitleColor);
- if (this instanceof PostTextTypeViewHolder) {
- ((PostTextTypeViewHolder) this).contentTextView.setTextColor(mReadPostContentColor);
+ if (changePostItemColor) {
+ cardView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor));
+ titleTextView.setTextColor(mReadPostTitleColor);
+ if (this instanceof PostTextTypeViewHolder) {
+ ((PostTextTypeViewHolder) this).contentTextView.setTextColor(mReadPostContentColor);
+ }
}
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
@@ -2077,7 +2095,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
Post post = getItem(position);
if (post != null) {
- markPostRead(post);
+ markPostRead(post, true);
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
if (post.isGfycat()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
@@ -2322,7 +2340,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
Post post = getItem(position);
if (post != null) {
- ((PostBaseViewHolder) this).markPostRead(post);
+ markPostRead(post, true);
if (post.getPostType() == Post.VIDEO_TYPE) {
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
if (post.isGfycat()) {
@@ -2604,7 +2622,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
Post post = getItem(position);
if (post != null && canStartActivity) {
- markPostRead(post);
+ markPostRead(post, true);
canStartActivity = false;
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
@@ -2623,7 +2641,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mCallback.delayTransition();
} else {
mCallback.delayTransition();
- ViewGroup.LayoutParams params = (LinearLayout.LayoutParams) bottomConstraintLayout.getLayoutParams();
+ ViewGroup.LayoutParams params = bottomConstraintLayout.getLayoutParams();
params.height = 0;
bottomConstraintLayout.setLayoutParams(params);
}
@@ -2690,7 +2708,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
Post post = getItem(position);
if (post != null) {
- markPostRead(post);
+ markPostRead(post, true);
if (post.getPostType() == Post.VIDEO_TYPE) {
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
if (post.isGfycat()) {
@@ -2756,7 +2774,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
Post post = getItem(position);
if (post != null) {
if (mMarkPostsAsReadAfterVoting) {
- markPostRead(post);
+ markPostRead(post, true);
}
if (post.isArchived()) {
@@ -2846,7 +2864,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
Post post = getItem(position);
if (post != null) {
if (mMarkPostsAsReadAfterVoting) {
- markPostRead(post);
+ markPostRead(post, true);
}
if (post.isArchived()) {
@@ -3000,11 +3018,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
});
}
- void markPostRead(Post post) {
+ void markPostRead(Post post, boolean changePostItemColor) {
if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) {
post.markAsRead();
- itemView.setBackgroundColor(mReadPostCardViewBackgroundColor);
- titleTextView.setTextColor(mReadPostTitleColor);
+ if (changePostItemColor) {
+ itemView.setBackgroundColor(mReadPostCardViewBackgroundColor);
+ titleTextView.setTextColor(mReadPostTitleColor);
+ }
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
}
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 5d5a9e16..0c12aed9 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.mark_posts_as_read_on_scroll_linear_layout_post_history_fragment)
+ LinearLayout markPostsAsReadOnScrollLinearLayout;
+ @BindView(R.id.mark_posts_as_read_on_scroll_switch_post_history_fragment)
+ SwitchMaterial markPostsAsReadOnScrollSwitch;
@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)
@@ -74,6 +78,8 @@ public class PostHistoryFragment extends Fragment {
accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false));
markPostsAsReadAfterVotingSwitch.setChecked(postHistorySharedPreferences.getBoolean(
accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false));
+ markPostsAsReadOnScrollSwitch.setChecked(postHistorySharedPreferences.getBoolean(
+ accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false));
hideReadPostsAutomaticallySwitch.setChecked(postHistorySharedPreferences.getBoolean(
accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
@@ -89,6 +95,10 @@ public class PostHistoryFragment extends Fragment {
markPostsAsReadAfterVotingSwitch.setOnCheckedChangeListener((compoundButton, b) ->
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