1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-03 13:44:40 +00:00

Fast scroll single item

This commit is contained in:
M66B 2020-02-16 11:26:43 +01:00
parent c1f95b261b
commit 573b38fd11
2 changed files with 31 additions and 12 deletions

View file

@ -450,12 +450,22 @@ public class FastScrollerEx extends RecyclerView.ItemDecoration implements Recyc
return; return;
} }
int scrollbarLength = scrollbarRange[1] - scrollbarRange[0];
float percentage = (scrollbarLength == 0 ? 0 : y / (float) scrollbarLength);
androidx.recyclerview.widget.RecyclerView.Adapter adapter = mRecyclerView.getAdapter(); androidx.recyclerview.widget.RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
int count = (adapter == null ? 0 : adapter.getItemCount()); int count = (adapter == null ? 0 : adapter.getItemCount());
if (count == 1) {
int scrollingBy = scrollTo(mVerticalDragY, y, scrollbarRange,
mRecyclerView.computeVerticalScrollRange(),
mRecyclerView.computeVerticalScrollOffset(), mRecyclerViewHeight);
if (scrollingBy != 0) {
mRecyclerView.scrollBy(0, scrollingBy);
}
}
else {
int scrollbarLength = scrollbarRange[1] - scrollbarRange[0];
float percentage = (scrollbarLength == 0 ? 0 : y / (float) scrollbarLength);
int pos = Math.round(count * percentage); int pos = Math.round(count * percentage);
mRecyclerView.scrollToPosition(pos); mRecyclerView.scrollToPosition(pos);
}
mVerticalDragY = y; mVerticalDragY = y;
} }

View file

@ -1,5 +1,5 @@
--- /home/marcel/tmp/FastScroller.java 1980-02-01 00:00:00.000000000 +0100 --- /home/marcel/tmp/FastScroller.java 1980-02-01 00:00:00.000000000 +0100
+++ app/src/main/java/androidx/recyclerview/widget/FastScrollerEx.java 2020-01-26 19:12:27.775546398 +0100 +++ app/src/main/java/androidx/recyclerview/widget/FastScrollerEx.java 2020-02-16 11:25:11.856872339 +0100
@@ -37,8 +37,8 @@ import java.lang.annotation.RetentionPol @@ -37,8 +37,8 @@ import java.lang.annotation.RetentionPol
/** /**
* Class responsible to animate and provide a fast scroller. * Class responsible to animate and provide a fast scroller.
@ -28,7 +28,7 @@
} }
if (mNeedHorizontalScrollbar) { if (mNeedHorizontalScrollbar) {
@@ -448,12 +449,14 @@ class FastScroller extends RecyclerView. @@ -448,12 +449,24 @@ class FastScroller extends RecyclerView.
if (Math.abs(mVerticalThumbCenterY - y) < 2) { if (Math.abs(mVerticalThumbCenterY - y) < 2) {
return; return;
} }
@ -37,19 +37,28 @@
- mRecyclerView.computeVerticalScrollOffset(), mRecyclerViewHeight); - mRecyclerView.computeVerticalScrollOffset(), mRecyclerViewHeight);
- if (scrollingBy != 0) { - if (scrollingBy != 0) {
- mRecyclerView.scrollBy(0, scrollingBy); - mRecyclerView.scrollBy(0, scrollingBy);
- }
+ +
+ int scrollbarLength = scrollbarRange[1] - scrollbarRange[0];
+ float percentage = (scrollbarLength == 0 ? 0 : y / (float) scrollbarLength);
+ androidx.recyclerview.widget.RecyclerView.Adapter adapter = mRecyclerView.getAdapter(); + androidx.recyclerview.widget.RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
+ int count = (adapter == null ? 0 : adapter.getItemCount()); + int count = (adapter == null ? 0 : adapter.getItemCount());
+ if (count == 1) {
+ int scrollingBy = scrollTo(mVerticalDragY, y, scrollbarRange,
+ mRecyclerView.computeVerticalScrollRange(),
+ mRecyclerView.computeVerticalScrollOffset(), mRecyclerViewHeight);
+ if (scrollingBy != 0) {
+ mRecyclerView.scrollBy(0, scrollingBy);
+ }
}
+ else {
+ int scrollbarLength = scrollbarRange[1] - scrollbarRange[0];
+ float percentage = (scrollbarLength == 0 ? 0 : y / (float) scrollbarLength);
+ int pos = Math.round(count * percentage); + int pos = Math.round(count * percentage);
+ mRecyclerView.scrollToPosition(pos); + mRecyclerView.scrollToPosition(pos);
+ }
+ +
mVerticalDragY = y; mVerticalDragY = y;
} }
@@ -494,7 +497,7 @@ class FastScroller extends RecyclerView. @@ -494,7 +507,7 @@ class FastScroller extends RecyclerView.
@VisibleForTesting @VisibleForTesting
boolean isPointInsideVerticalThumb(float x, float y) { boolean isPointInsideVerticalThumb(float x, float y) {
return (isLayoutRTL() ? x <= mVerticalThumbWidth return (isLayoutRTL() ? x <= mVerticalThumbWidth