aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-12-08 10:40:19 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-12-08 10:40:19 +0000
commit13107b919333092c4e1b48c6c0da50be3d31acc2 (patch)
tree24c946ed76e3ed612ceee1e091aa47e2ce97288e /app
parent59baa9c51cb0f18c39e7c78a56fc26e755971dcc (diff)
downloadinfinity-for-reddit-13107b919333092c4e1b48c6c0da50be3d31acc2.tar
infinity-for-reddit-13107b919333092c4e1b48c6c0da50be3d31acc2.tar.gz
infinity-for-reddit-13107b919333092c4e1b48c6c0da50be3d31acc2.tar.bz2
infinity-for-reddit-13107b919333092c4e1b48c6c0da50be3d31acc2.tar.lz
infinity-for-reddit-13107b919333092c4e1b48c6c0da50be3d31acc2.tar.xz
infinity-for-reddit-13107b919333092c4e1b48c6c0da50be3d31acc2.tar.zst
infinity-for-reddit-13107b919333092c4e1b48c6c0da50be3d31acc2.zip
Fix lazy mode after hiding read posts.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java11
3 files changed, 31 insertions, 4 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 9d9e890d..8a8eef99 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -396,6 +396,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (post != null) {
if (post.isRead()) {
if (position < mHideReadPostsIndex) {
+ post.hidePostInRecyclerView();
holder.itemView.setVisibility(View.GONE);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.height = 0;
@@ -717,6 +718,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (post != null) {
if (post.isRead()) {
if (position < mHideReadPostsIndex) {
+ post.hidePostInRecyclerView();
holder.itemView.setVisibility(View.GONE);
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
params.height = 0;
@@ -1218,6 +1220,20 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mHideReadPostsIndex = getItemCount();
}
+ public int getNextItemPositionWithoutBeingHidden(int fromPosition) {
+ int temp = fromPosition;
+ while (temp >= 0 && temp < super.getItemCount()) {
+ Post post = getItem(temp);
+ if (post != null && post.isHiddenInRecyclerView()) {
+ temp++;
+ } else {
+ break;
+ }
+ }
+
+ return temp;
+ }
+
private boolean hasExtraRow() {
return networkState != null && networkState.getStatus() != NetworkState.Status.SUCCESS;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index c682e181..948bd0d9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -331,20 +331,20 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void run() {
- if (isInLazyMode && !isLazyModePaused) {
+ if (isInLazyMode && !isLazyModePaused && mAdapter != null) {
int nPosts = mAdapter.getItemCount();
if (getCurrentPosition() == -1) {
if (mLinearLayoutManager != null) {
- setCurrentPosition(mLinearLayoutManager.findFirstVisibleItemPosition());
+ setCurrentPosition(mAdapter.getNextItemPositionWithoutBeingHidden(mLinearLayoutManager.findFirstVisibleItemPosition()));
} else {
int[] into = new int[2];
- setCurrentPosition(mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[1]);
+ setCurrentPosition(mAdapter.getNextItemPositionWithoutBeingHidden(mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[1]));
}
}
if (getCurrentPosition() != RecyclerView.NO_POSITION && nPosts > getCurrentPosition()) {
incrementCurrentPosition();
- smoothScroller.setTargetPosition(getCurrentPosition());
+ smoothScroller.setTargetPosition(mAdapter.getNextItemPositionWithoutBeingHidden(getCurrentPosition()));
if (mLinearLayoutManager != null) {
mLinearLayoutManager.startSmoothScroll(smoothScroller);
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java
index 582c398d..c96c325a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java
@@ -72,6 +72,7 @@ public class Post implements Parcelable {
private boolean saved;
private boolean isCrosspost;
private boolean isRead;
+ private boolean isHiddenInRecyclerView = false;
private String crosspostParentId;
private ArrayList<Preview> previews = new ArrayList<>();
private ArrayList<Gallery> gallery = new ArrayList<>();
@@ -187,6 +188,7 @@ public class Post implements Parcelable {
saved = in.readByte() != 0;
isCrosspost = in.readByte() != 0;
isRead = in.readByte() != 0;
+ isHiddenInRecyclerView = in.readByte() != 0;
crosspostParentId = in.readString();
in.readTypedList(previews, Preview.CREATOR);
in.readTypedList(gallery, Gallery.CREATOR);
@@ -458,6 +460,14 @@ public class Post implements Parcelable {
return isRead;
}
+ public boolean isHiddenInRecyclerView() {
+ return isHiddenInRecyclerView;
+ }
+
+ public void hidePostInRecyclerView() {
+ isHiddenInRecyclerView = true;
+ }
+
public String getCrosspostParentId() {
return crosspostParentId;
}
@@ -523,6 +533,7 @@ public class Post implements Parcelable {
parcel.writeByte((byte) (saved ? 1 : 0));
parcel.writeByte((byte) (isCrosspost ? 1 : 0));
parcel.writeByte((byte) (isRead ? 1 : 0));
+ parcel.writeByte((byte) (isHiddenInRecyclerView ? 1 : 0));
parcel.writeString(crosspostParentId);
parcel.writeTypedList(previews);
parcel.writeTypedList(gallery);