mirror of
https://github.com/Michatec/michas-droid.git
synced 2026-05-31 02:12:42 +02:00
Improve fast scrolling
This commit is contained in:
@@ -79,6 +79,7 @@ class ProductsFragment(): Fragment(), CursorOwner.Callback {
|
|||||||
isMotionEventSplittingEnabled = false
|
isMotionEventSplittingEnabled = false
|
||||||
isVerticalScrollBarEnabled = false
|
isVerticalScrollBarEnabled = false
|
||||||
setHasFixedSize(true)
|
setHasFixedSize(true)
|
||||||
|
recycledViewPool.setMaxRecycledViews(ProductsAdapter.ViewType.PRODUCT.ordinal, 30)
|
||||||
adapter = ProductsAdapter { screenActivity.navigateProduct(it.packageName) }
|
adapter = ProductsAdapter { screenActivity.navigateProduct(it.packageName) }
|
||||||
addItemDecoration(DividerItemDecoration(context,
|
addItemDecoration(DividerItemDecoration(context,
|
||||||
DividerItemDecoration.fixed(context.resources.sizeScaled(72), 0)))
|
DividerItemDecoration.fixed(context.resources.sizeScaled(72), 0)))
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class RecyclerFastScroller(private val recyclerView: RecyclerView) {
|
|||||||
|
|
||||||
private val thumbDrawable = recyclerView.context.getDrawableFromAttr(android.R.attr.fastScrollThumbDrawable)
|
private val thumbDrawable = recyclerView.context.getDrawableFromAttr(android.R.attr.fastScrollThumbDrawable)
|
||||||
private val trackDrawable = recyclerView.context.getDrawableFromAttr(android.R.attr.fastScrollTrackDrawable)
|
private val trackDrawable = recyclerView.context.getDrawableFromAttr(android.R.attr.fastScrollTrackDrawable)
|
||||||
|
private val minTrackSize = recyclerView.resources.sizeScaled(32)
|
||||||
|
|
||||||
private data class FastScrolling(val startAtThumbOffset: Float?, val startY: Float, val currentY: Float)
|
private data class FastScrolling(val startAtThumbOffset: Float?, val startY: Float, val currentY: Float)
|
||||||
|
|
||||||
@@ -129,8 +130,8 @@ class RecyclerFastScroller(private val recyclerView: RecyclerView) {
|
|||||||
}
|
}
|
||||||
event.action == MotionEvent.ACTION_DOWN -> {
|
event.action == MotionEvent.ACTION_DOWN -> {
|
||||||
val rtl = recyclerView.layoutDirection == RecyclerView.LAYOUT_DIRECTION_RTL
|
val rtl = recyclerView.layoutDirection == RecyclerView.LAYOUT_DIRECTION_RTL
|
||||||
val maxWidth = max(thumbDrawable.intrinsicWidth, trackDrawable.intrinsicWidth)
|
val trackWidth = max(minTrackSize, max(thumbDrawable.intrinsicWidth, trackDrawable.intrinsicWidth))
|
||||||
val atThumbVertical = if (rtl) event.x <= maxWidth else event.x >= recyclerView.width - maxWidth
|
val atThumbVertical = if (rtl) event.x <= trackWidth else event.x >= recyclerView.width - trackWidth
|
||||||
atThumbVertical && run {
|
atThumbVertical && run {
|
||||||
withScroll { itemHeight, thumbHeight, range ->
|
withScroll { itemHeight, thumbHeight, range ->
|
||||||
val offset = currentOffset(itemHeight, range)
|
val offset = currentOffset(itemHeight, range)
|
||||||
|
|||||||
Reference in New Issue
Block a user