mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-29 04:17:12 +01:00
Fix lazy mode after hiding read posts.
This commit is contained in:
parent
59baa9c51c
commit
13107b9193
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user