list: make fast scroll thumb less intrusive

This commit is contained in:
Alexander Capehart 2025-01-02 12:08:13 -07:00
parent be666069fc
commit ecc8d8750a
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 19 additions and 29 deletions

View file

@ -72,8 +72,9 @@ class FastScrollRecyclerView
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) : constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
AuxioRecyclerView(context, attrs, defStyleAttr) { AuxioRecyclerView(context, attrs, defStyleAttr) {
// Thumb // Thumb
private val thumbSize = context.getDimenPixels(R.dimen.size_touchable_small) private val thumbWidth = context.getDimenPixels(R.dimen.spacing_mid_medium)
private val slider = MaterialSlider(context, thumbSize) private val thumbHeight = context.getDimenPixels(R.dimen.size_touchable_medium)
private val slider = MaterialSlider(context, thumbWidth)
private var thumbAnimator: Animator? = null private var thumbAnimator: Animator? = null
private val thumbView = private val thumbView =
@ -174,16 +175,16 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
thumbView.layoutDirection = layoutDirection thumbView.layoutDirection = layoutDirection
thumbView.measure( thumbView.measure(
MeasureSpec.makeMeasureSpec(thumbSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(thumbWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(thumbSize, MeasureSpec.EXACTLY)) MeasureSpec.makeMeasureSpec(thumbHeight, MeasureSpec.EXACTLY))
val thumbTop = thumbPadding.top + thumbOffset val thumbTop = thumbPadding.top + thumbOffset
val thumbLeft = val thumbLeft =
if (isRtl) { if (isRtl) {
thumbPadding.left thumbPadding.left
} else { } else {
width - thumbPadding.right - thumbSize width - thumbPadding.right - thumbWidth
} }
thumbView.layout(thumbLeft, thumbTop, thumbLeft + thumbSize, thumbTop + thumbSize) thumbView.layout(thumbLeft, thumbTop, thumbLeft + thumbWidth, thumbTop + thumbHeight)
} }
override fun onScrolled(dx: Int, dy: Int) { override fun onScrolled(dx: Int, dy: Int) {
@ -233,8 +234,9 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
if (thumbView.isUnder(eventX, eventY, minTouchTargetSize)) { if (thumbView.isUnder(eventX, eventY, minTouchTargetSize)) {
dragStartThumbOffset = thumbOffset dragStartThumbOffset = thumbOffset
} else if (eventX > thumbView.right - thumbSize / 4) { } else if (eventX > thumbView.right - thumbWidth / 4) {
dragStartThumbOffset = (eventY - thumbPadding.top - thumbSize / 2f).toInt() dragStartThumbOffset =
(eventY - thumbPadding.top - thumbHeight / 2f).toInt()
scrollToThumbOffset(dragStartThumbOffset) scrollToThumbOffset(dragStartThumbOffset)
} else { } else {
return false return false
@ -252,7 +254,8 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
dragStartThumbOffset = thumbOffset dragStartThumbOffset = thumbOffset
} else { } else {
dragStartY = eventY dragStartY = eventY
dragStartThumbOffset = (eventY - thumbPadding.top - thumbSize / 2f).toInt() dragStartThumbOffset =
(eventY - thumbPadding.top - thumbHeight / 2f).toInt()
scrollToThumbOffset(dragStartThumbOffset) scrollToThumbOffset(dragStartThumbOffset)
} }
@ -319,7 +322,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
private val thumbOffsetRange: Int private val thumbOffsetRange: Int
get() { get() {
return height - thumbPadding.top - thumbPadding.bottom - thumbSize return height - thumbPadding.top - thumbPadding.bottom - thumbHeight
} }
/** An interface to provide text to use in the popup when fast-scrolling. */ /** An interface to provide text to use in the popup when fast-scrolling. */

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,840L300,660L358,602L480,724L602,602L660,660L480,840ZM358,362L300,304L480,124L660,304L602,362L480,240L358,362Z"/>
</vector>

View file

@ -3,9 +3,8 @@
android:shape="rectangle" android:shape="rectangle"
android:tint="?attr/colorSecondary"> android:tint="?attr/colorSecondary">
<corners android:topLeftRadius="24dp" android:bottomLeftRadius="24dp" /> <corners android:radius="8dp" />
<size <size
android:width="48dp" android:width="4dp" />
android:height="48dp" />
<solid android:color="@android:color/white" /> <solid android:color="@android:color/white" />
</shape> </shape>

View file

@ -2,14 +2,13 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto" android:padding="@dimen/spacing_tiny"
android:background="@drawable/ui_scroll_thumb"> xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView <ImageView
android:layout_width="@dimen/size_touchable_small" android:layout_width="wrap_content"
android:layout_height="@dimen/size_touchable_small" android:layout_height="@dimen/size_touchable_small"
app:tint="?attr/colorOnSecondary"
android:scaleType="centerInside" android:scaleType="centerInside"
android:src="@drawable/ic_scroll_24" /> android:src="@drawable/ui_scroll_thumb" />
</FrameLayout> </FrameLayout>