diff options
Diffstat (limited to 'app/src/main/java/ml')
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); |