mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
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:
parent
dc71e1d4a2
commit
238b21c2e2
1 changed files with 35 additions and 1 deletions
|
@ -2,15 +2,37 @@ package eu.kanade.tachiyomi.ui.library
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.MotionEvent
|
||||
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) :
|
||||
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) {
|
||||
if (recyclerView != null) {
|
||||
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)
|
||||
val category = when (val item = adapter.getItem(targetPos)) {
|
||||
is LibraryItem -> {
|
||||
|
@ -24,4 +46,16 @@ class LibraryFastScroll @JvmOverloads constructor(context: Context, attrs: Attri
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue