Scroll through library entries (instead of just categories) by fastscrolling then moving to the middle of the screen

maybe by the release notes i'll have a better way of explaining that

closes #1348 in a way I can live with
This commit is contained in:
Jays2Kings 2022-08-20 22:50:17 -04:00
parent dc71e1d4a2
commit 238b21c2e2

View file

@ -2,15 +2,37 @@ package eu.kanade.tachiyomi.ui.library
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.HapticFeedbackConstants
import android.view.MotionEvent
import eu.kanade.tachiyomi.ui.base.MaterialFastScroll import eu.kanade.tachiyomi.ui.base.MaterialFastScroll
import eu.kanade.tachiyomi.util.system.dpToPxEnd
import eu.kanade.tachiyomi.util.system.isLTR
import kotlin.math.abs
import kotlin.math.min
class LibraryFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : class LibraryFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
MaterialFastScroll(context, attrs) { MaterialFastScroll(context, attrs) {
private var currentX = 0f
override fun onTouchEvent(event: MotionEvent): Boolean {
val oldFastScroll = categoryFastScroll
currentX = event.x
if (categoryFastScroll != oldFastScroll && canScroll) {
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
}
return super.onTouchEvent(event)
}
private val categoryFastScroll: Boolean
get() = abs(currentX - handle.x) >= min(200, width / 2)
override fun setRecyclerViewPosition(y: Float) { override fun setRecyclerViewPosition(y: Float) {
if (recyclerView != null) { if (recyclerView != null) {
val adapter = recyclerView.adapter as? LibraryCategoryAdapter ?: return super.setRecyclerViewPosition(y) val adapter = recyclerView.adapter as? LibraryCategoryAdapter ?: return super.setRecyclerViewPosition(y)
if (adapter.isSingleCategory) return super.setRecyclerViewPosition(y) if (adapter.isSingleCategory || categoryFastScroll) {
return super.setRecyclerViewPosition(y)
}
var targetPos = getTargetPos(y) var targetPos = getTargetPos(y)
val category = when (val item = adapter.getItem(targetPos)) { val category = when (val item = adapter.getItem(targetPos)) {
is LibraryItem -> { is LibraryItem -> {
@ -24,4 +46,16 @@ class LibraryFastScroll @JvmOverloads constructor(context: Context, attrs: Attri
updateBubbleText(targetPos) updateBubbleText(targetPos)
} }
} }
override fun setBubbleAndHandlePosition(y: Float) {
super.setBubbleAndHandlePosition(y)
if (bubbleEnabled) {
bubble.translationX =
if (categoryFastScroll) {
250f * (if (resources.isLTR) -1 else 1)
} else {
currentX - handle.x
} + (-45f).dpToPxEnd(resources)
}
}
} }