Don't hide read posts after initial post loading even if Hide Read Posts Automatically is enabled.

This commit is contained in:
Alex Ning 2021-01-18 23:37:08 +08:00
parent f13d4576e1
commit ea837718bf
3 changed files with 14 additions and 6 deletions

View File

@ -407,7 +407,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
Post post = getItem(position); Post post = getItem(position);
if (post != null) { if (post != null) {
if (post.isRead()) { if (post.isRead()) {
if (mHideReadPostsAutomatically || position < mHideReadPostsIndex) { if ((mHideReadPostsAutomatically && !post.isHiddenManuallyByUser()) || position < mHideReadPostsIndex) {
post.hidePostInRecyclerView(); post.hidePostInRecyclerView();
holder.itemView.setVisibility(View.GONE); holder.itemView.setVisibility(View.GONE);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams(); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
@ -736,7 +736,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
Post post = getItem(position); Post post = getItem(position);
if (post != null) { if (post != null) {
if (post.isRead()) { if (post.isRead()) {
if (mHideReadPostsAutomatically || position < mHideReadPostsIndex) { if ((mHideReadPostsAutomatically && !post.isHiddenManuallyByUser()) || position < mHideReadPostsIndex) {
post.hidePostInRecyclerView(); post.hidePostInRecyclerView();
holder.itemView.setVisibility(View.GONE); holder.itemView.setVisibility(View.GONE);
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams(); ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
@ -1980,7 +1980,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
void markPostRead(Post post, boolean changePostItemColor) { void markPostRead(Post post, boolean changePostItemColor) {
if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) { if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) {
post.markAsRead(); post.markAsRead(true);
if (changePostItemColor) { if (changePostItemColor) {
cardView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); cardView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor));
titleTextView.setTextColor(mReadPostTitleColor); titleTextView.setTextColor(mReadPostTitleColor);
@ -3033,7 +3033,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
void markPostRead(Post post, boolean changePostItemColor) { void markPostRead(Post post, boolean changePostItemColor) {
if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) { if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) {
post.markAsRead(); post.markAsRead(true);
if (changePostItemColor) { if (changePostItemColor) {
itemView.setBackgroundColor(mReadPostCardViewBackgroundColor); itemView.setBackgroundColor(mReadPostCardViewBackgroundColor);
titleTextView.setTextColor(mReadPostTitleColor); titleTextView.setTextColor(mReadPostTitleColor);

View File

@ -565,7 +565,7 @@ public class ParsePost {
JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
Post post = parseBasicData(data); Post post = parseBasicData(data);
if (readPostHashSet != null && readPostHashSet.contains(ReadPost.convertPost(post))) { if (readPostHashSet != null && readPostHashSet.contains(ReadPost.convertPost(post))) {
post.markAsRead(); post.markAsRead(false);
} }
if (PostFilter.isPostAllowed(post, postFilter)) { if (PostFilter.isPostAllowed(post, postFilter)) {
newPosts.add(post); newPosts.add(post);

View File

@ -73,6 +73,7 @@ public class Post implements Parcelable {
private boolean isCrosspost; private boolean isCrosspost;
private boolean isRead; private boolean isRead;
private boolean isHiddenInRecyclerView = false; private boolean isHiddenInRecyclerView = false;
private boolean isHiddenManuallyByUser = false;
private String crosspostParentId; private String crosspostParentId;
private ArrayList<Preview> previews = new ArrayList<>(); private ArrayList<Preview> previews = new ArrayList<>();
private ArrayList<Gallery> gallery = new ArrayList<>(); private ArrayList<Gallery> gallery = new ArrayList<>();
@ -189,6 +190,7 @@ public class Post implements Parcelable {
isCrosspost = in.readByte() != 0; isCrosspost = in.readByte() != 0;
isRead = in.readByte() != 0; isRead = in.readByte() != 0;
isHiddenInRecyclerView = in.readByte() != 0; isHiddenInRecyclerView = in.readByte() != 0;
isHiddenManuallyByUser = in.readByte() != 0;
crosspostParentId = in.readString(); crosspostParentId = in.readString();
in.readTypedList(previews, Preview.CREATOR); in.readTypedList(previews, Preview.CREATOR);
in.readTypedList(gallery, Gallery.CREATOR); in.readTypedList(gallery, Gallery.CREATOR);
@ -452,8 +454,9 @@ public class Post implements Parcelable {
return isCrosspost; return isCrosspost;
} }
public void markAsRead() { public void markAsRead(boolean isHiddenManuallyByUser) {
isRead = true; isRead = true;
this.isHiddenManuallyByUser = isHiddenManuallyByUser;
} }
public boolean isRead() { public boolean isRead() {
@ -468,6 +471,10 @@ public class Post implements Parcelable {
isHiddenInRecyclerView = true; isHiddenInRecyclerView = true;
} }
public boolean isHiddenManuallyByUser() {
return isHiddenManuallyByUser;
}
public String getCrosspostParentId() { public String getCrosspostParentId() {
return crosspostParentId; return crosspostParentId;
} }
@ -534,6 +541,7 @@ public class Post implements Parcelable {
parcel.writeByte((byte) (isCrosspost ? 1 : 0)); parcel.writeByte((byte) (isCrosspost ? 1 : 0));
parcel.writeByte((byte) (isRead ? 1 : 0)); parcel.writeByte((byte) (isRead ? 1 : 0));
parcel.writeByte((byte) (isHiddenInRecyclerView ? 1 : 0)); parcel.writeByte((byte) (isHiddenInRecyclerView ? 1 : 0));
parcel.writeByte((byte) (isHiddenManuallyByUser ? 1 : 0));
parcel.writeString(crosspostParentId); parcel.writeString(crosspostParentId);
parcel.writeTypedList(previews); parcel.writeTypedList(previews);
parcel.writeTypedList(gallery); parcel.writeTypedList(gallery);