1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-29 11:15:51 +00:00
FairEmail/patches/fast-scroller.patch

70 lines
3.4 KiB
Diff
Raw Normal View History

2020-01-26 18:17:50 +00:00
--- /home/marcel/tmp/FastScroller.java 1980-02-01 00:00:00.000000000 +0100
2020-02-16 10:26:43 +00:00
+++ app/src/main/java/androidx/recyclerview/widget/FastScrollerEx.java 2020-02-16 11:25:11.856872339 +0100
2020-01-26 18:17:50 +00:00
@@ -37,8 +37,8 @@ import java.lang.annotation.RetentionPol
/**
* Class responsible to animate and provide a fast scroller.
*/
-@VisibleForTesting
-class FastScroller extends RecyclerView.ItemDecoration implements RecyclerView.OnItemTouchListener {
+//@VisibleForTesting
+public class FastScrollerEx extends RecyclerView.ItemDecoration implements RecyclerView.OnItemTouchListener {
@IntDef({STATE_HIDDEN, STATE_VISIBLE, STATE_DRAGGING})
@Retention(RetentionPolicy.SOURCE)
private @interface State { }
@@ -135,7 +135,7 @@ class FastScroller extends RecyclerView.
}
};
- FastScroller(RecyclerView recyclerView, StateListDrawable verticalThumbDrawable,
+ public FastScrollerEx(RecyclerView recyclerView, StateListDrawable verticalThumbDrawable,
Drawable verticalTrackDrawable, StateListDrawable horizontalThumbDrawable,
Drawable horizontalTrackDrawable, int defaultWidth, int scrollbarMinimumRange,
int margin) {
@@ -359,6 +359,7 @@ class FastScroller extends RecyclerView.
(int) ((verticalVisibleLength * middleScreenPos) / verticalContentLength);
mVerticalThumbHeight = Math.min(verticalVisibleLength,
(verticalVisibleLength * verticalVisibleLength) / verticalContentLength);
+ mVerticalThumbHeight = Math.max(mVerticalThumbHeight, mVerticalThumbDrawable.getIntrinsicHeight());
}
if (mNeedHorizontalScrollbar) {
2020-02-16 10:26:43 +00:00
@@ -448,12 +449,24 @@ class FastScroller extends RecyclerView.
2020-01-26 18:17:50 +00:00
if (Math.abs(mVerticalThumbCenterY - y) < 2) {
return;
}
- int scrollingBy = scrollTo(mVerticalDragY, y, scrollbarRange,
- mRecyclerView.computeVerticalScrollRange(),
- mRecyclerView.computeVerticalScrollOffset(), mRecyclerViewHeight);
- if (scrollingBy != 0) {
- mRecyclerView.scrollBy(0, scrollingBy);
+
+ androidx.recyclerview.widget.RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
+ int count = (adapter == null ? 0 : adapter.getItemCount());
2020-02-16 10:26:43 +00:00
+ 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);
+ mRecyclerView.scrollToPosition(pos);
+ }
2020-01-26 18:17:50 +00:00
+
mVerticalDragY = y;
}
2020-02-16 10:26:43 +00:00
@@ -494,7 +507,7 @@ class FastScroller extends RecyclerView.
2020-01-26 18:17:50 +00:00
@VisibleForTesting
boolean isPointInsideVerticalThumb(float x, float y) {
return (isLayoutRTL() ? x <= mVerticalThumbWidth
- : x >= mRecyclerViewWidth - mVerticalThumbWidth)
+ : x >= mRecyclerViewWidth - mVerticalThumbWidth * 3)
&& y >= mVerticalThumbCenterY - mVerticalThumbHeight / 2
&& y <= mVerticalThumbCenterY + mVerticalThumbHeight / 2;
}