Fix scroll position one-off because of the last seen indicator

multisite
Floens 10 years ago
parent 9095aef1e3
commit cac952bbae
  1. 6
      Clover/app/src/main/java/org/floens/chan/core/presenter/ThreadPresenter.java
  2. 10
      Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java
  3. 4
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java
  4. 14
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java

@ -285,8 +285,8 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
showPosts();
}
public void scrollTo(int position, boolean smooth) {
threadPresenterCallback.scrollTo(position, smooth);
public void scrollTo(int displayPosition, boolean smooth) {
threadPresenterCallback.scrollTo(displayPosition, smooth);
}
public void scrollToImage(PostImage postImage, boolean smooth) {
@ -652,7 +652,7 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
void showImages(List<PostImage> images, int index, Loadable loadable, ThumbnailView thumbnail);
void scrollTo(int position, boolean smooth);
void scrollTo(int displayPosition, boolean smooth);
void highlightPost(Post post);

@ -264,7 +264,7 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
this.postViewMode = postViewMode;
}
private int getPostPosition(int position) {
public int getPostPosition(int position) {
int postPosition = position;
if (lastSeenIndicatorPosition >= 0 && position > lastSeenIndicatorPosition) {
postPosition--;
@ -272,6 +272,14 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
return postPosition;
}
public int getScrollPosition(int displayPosition) {
int postPosition = displayPosition;
if (lastSeenIndicatorPosition >= 0 && displayPosition > lastSeenIndicatorPosition) {
postPosition++;
}
return postPosition;
}
private boolean showStatusView() {
return postAdapterCallback.getLoadable().isThreadMode();
}

@ -309,8 +309,8 @@ public class ThreadLayout extends CoordinatorLayout implements ThreadPresenter.T
}
@Override
public void scrollTo(int position, boolean smooth) {
threadListLayout.scrollTo(position, smooth);
public void scrollTo(int displayPosition, boolean smooth) {
threadListLayout.scrollTo(displayPosition, smooth);
}
@Override

@ -366,20 +366,22 @@ public class ThreadListLayout extends LinearLayout implements ReplyLayout.ReplyL
return thumbnail;
}
public void scrollTo(int position, boolean smooth) {
if (position < 0) {
position = recyclerView.getAdapter().getItemCount() - 1;
public void scrollTo(int displayPosition, boolean smooth) {
if (displayPosition < 0) {
displayPosition = recyclerView.getAdapter().getItemCount() - 1;
}
int difference = Math.abs(position - getTopAdapterPosition());
int scrollPosition = postAdapter.getScrollPosition(displayPosition);
int difference = Math.abs(scrollPosition - getTopAdapterPosition());
if (difference > MAX_SMOOTH_SCROLL_DISTANCE) {
smooth = false;
}
if (smooth) {
recyclerView.smoothScrollToPosition(position);
recyclerView.smoothScrollToPosition(scrollPosition);
} else {
recyclerView.scrollToPosition(position);
recyclerView.scrollToPosition(scrollPosition);
}
}

Loading…
Cancel
Save