list: fix poor fast scroll empty state handling

This commit is contained in:
Alexander Capehart 2025-01-04 11:03:35 -07:00
parent 171c0c795e
commit 533702ca1e
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 16 additions and 12 deletions

View file

@ -108,7 +108,7 @@ abstract class DetailFragment<P : MusicParent, C : Music> :
detailContent.translationY = spacingSmall * (1 - inRatio) detailContent.translationY = spacingSmall * (1 - inRatio)
// Enable fast scrolling once fully collapsed // Enable fast scrolling once fully collapsed
binding.detailRecycler.thumbEnabled = ratio == 1f binding.detailRecycler.fastScrollingEnabled = ratio == 1f
} }
abstract fun onOpenParentMenu() abstract fun onOpenParentMenu()

View file

@ -31,7 +31,6 @@ import android.view.ViewConfiguration
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowInsets import android.view.WindowInsets
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.TextView
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import androidx.core.view.updatePaddingRelative import androidx.core.view.updatePaddingRelative
@ -100,7 +99,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
private var showingThumb = false private var showingThumb = false
private val hideThumbRunnable = Runnable { private val hideThumbRunnable = Runnable {
if (!dragging) { if (!dragging) {
hideScrollbar() hideThumb()
} }
} }
@ -144,7 +143,9 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
private var dragStartY = 0f private var dragStartY = 0f
private var dragStartThumbOffset = 0 private var dragStartThumbOffset = 0
var thumbEnabled = true private var fastScrollingPossible = true
var fastScrollingEnabled = true
set(value) { set(value) {
if (field == value) { if (field == value) {
return return
@ -153,7 +154,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
field = value field = value
if (!value) { if (!value) {
removeCallbacks(hideThumbRunnable) removeCallbacks(hideThumbRunnable)
hideScrollbar() hideThumb()
hidePopup() hidePopup()
} }
@ -220,7 +221,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
// --- RECYCLERVIEW EVENT MANAGEMENT --- // --- RECYCLERVIEW EVENT MANAGEMENT ---
private fun onPreDraw() { private fun onPreDraw() {
updateScrollbarState() updateThumbState()
thumbView.layoutDirection = layoutDirection thumbView.layoutDirection = layoutDirection
thumbView.measure( thumbView.measure(
@ -311,7 +312,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
override fun onScrolled(dx: Int, dy: Int) { override fun onScrolled(dx: Int, dy: Int) {
super.onScrolled(dx, dy) super.onScrolled(dx, dy)
updateScrollbarState() updateThumbState()
// Measure or layout events result in a fake onScrolled call. Ignore those. // Measure or layout events result in a fake onScrolled call. Ignore those.
if (dx == 0 && dy == 0) { if (dx == 0 && dy == 0) {
@ -329,11 +330,14 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
return insets return insets
} }
private fun updateScrollbarState() { private fun updateThumbState() {
// Then calculate the thumb position, which is just: // Then calculate the thumb position, which is just:
// [proportion of scroll position to scroll range] * [total thumb range] // [proportion of scroll position to scroll range] * [total thumb range]
val offsetY = computeVerticalScrollOffset() val offsetY = computeVerticalScrollOffset()
if (computeVerticalScrollRange() < height || childCount == 0) { if (computeVerticalScrollRange() < height || childCount == 0) {
fastScrollingPossible = false
hideThumb()
hidePopup()
return return
} }
val extentY = computeVerticalScrollExtent() val extentY = computeVerticalScrollExtent()
@ -342,7 +346,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
} }
private fun onItemTouch(event: MotionEvent): Boolean { private fun onItemTouch(event: MotionEvent): Boolean {
if (!thumbEnabled) { if (!fastScrollingEnabled || !fastScrollingPossible) {
dragging = false dragging = false
return false return false
} }
@ -427,7 +431,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
} }
private fun showScrollbar() { private fun showScrollbar() {
if (!thumbEnabled) { if (!fastScrollingEnabled || !fastScrollingPossible) {
return return
} }
if (showingThumb) { if (showingThumb) {
@ -439,7 +443,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
thumbAnimator = thumbSlider.slideIn(thumbView).also { it.start() } thumbAnimator = thumbSlider.slideIn(thumbView).also { it.start() }
} }
private fun hideScrollbar() { private fun hideThumb() {
if (!showingThumb) { if (!showingThumb) {
return return
} }
@ -450,7 +454,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
} }
private fun showPopup() { private fun showPopup() {
if (!thumbEnabled) { if (!fastScrollingEnabled || !fastScrollingPossible) {
return return
} }
if (showingPopup) { if (showingPopup) {