2020-06-15 13:57:42 +00:00
|
|
|
--- ./support/recyclerview/recyclerview/src/main/java/androidx/recyclerview/widget/FastScroller.java 2020-03-23 17:03:46.092122318 +0100
|
|
|
|
+++ ./email/app/src/main/java/androidx/recyclerview/widget/FastScrollerEx.java 2020-04-24 21:08:55.544011257 +0200
|
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;
|
|
|
|
}
|