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(); showPosts();
} }
public void scrollTo(int position, boolean smooth) { public void scrollTo(int displayPosition, boolean smooth) {
threadPresenterCallback.scrollTo(position, smooth); threadPresenterCallback.scrollTo(displayPosition, smooth);
} }
public void scrollToImage(PostImage postImage, boolean 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 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); void highlightPost(Post post);

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

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

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

Loading…
Cancel
Save