Prevent inserting read posts into database multiple times when clicking posts.

This commit is contained in:
Alex Ning 2020-12-08 00:18:04 +08:00
parent a4232a54bd
commit 69af53ddba

View File

@ -1880,14 +1880,16 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
void markPostRead(Post post) { void markPostRead(Post post) {
post.markAsRead(); if (!post.isRead()) {
cardView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); post.markAsRead();
titleTextView.setTextColor(mReadPostTitleColor); cardView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor));
if (this instanceof PostTextTypeViewHolder) { titleTextView.setTextColor(mReadPostTitleColor);
((PostTextTypeViewHolder) this).contentTextView.setTextColor(mReadPostContentColor); if (this instanceof PostTextTypeViewHolder) {
} ((PostTextTypeViewHolder) this).contentTextView.setTextColor(mReadPostContentColor);
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) { }
((MarkPostAsReadInterface) mActivity).markPostAsRead(post); if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
}
} }
} }
} }
@ -2933,11 +2935,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
void markPostRead(Post post) { void markPostRead(Post post) {
post.markAsRead(); if (!post.isRead()) {
itemView.setBackgroundColor(mReadPostCardViewBackgroundColor); post.markAsRead();
titleTextView.setTextColor(mReadPostTitleColor); itemView.setBackgroundColor(mReadPostCardViewBackgroundColor);
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) { titleTextView.setTextColor(mReadPostTitleColor);
((MarkPostAsReadInterface) mActivity).markPostAsRead(post); if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
}
} }
} }
} }