Smooth scroll when the "n new posts" view button is clicked.

multisite
Floens 10 years ago
parent 22f94e353a
commit 97d7f59852
  1. 2
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java
  2. 10
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java

@ -409,7 +409,7 @@ public class ThreadLayout extends CoordinatorLayout implements ThreadPresenter.T
newPostsNotification.setAction(R.string.thread_new_posts_goto, new OnClickListener() { newPostsNotification.setAction(R.string.thread_new_posts_goto, new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
presenter.scrollTo(-1, false); presenter.scrollTo(-1, true);
} }
}).show(); }).show();
fixSnackbarText(getContext(), newPostsNotification); fixSnackbarText(getContext(), newPostsNotification);

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

Loading…
Cancel
Save