mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Library fast scroll now snaps to categories
This commit is contained in:
parent
9a08175280
commit
8094345714
4 changed files with 36 additions and 2 deletions
|
@ -15,7 +15,8 @@ import eu.kanade.tachiyomi.util.system.dpToPxEnd
|
|||
import eu.kanade.tachiyomi.util.system.isLTR
|
||||
import kotlin.math.abs
|
||||
|
||||
class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
@Suppress("LeakingThis")
|
||||
open class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
FastScroller(context, attrs) {
|
||||
|
||||
var canScroll = false
|
||||
|
|
|
@ -1269,6 +1269,12 @@ class LibraryController(
|
|||
}
|
||||
}
|
||||
|
||||
fun scrollToCategory(category: Category?) {
|
||||
if (category != null && activeCategory != category.order) {
|
||||
scrollToHeader(category.order)
|
||||
}
|
||||
}
|
||||
|
||||
private fun scrollToHeader(pos: Int, removeObserver: Boolean = true) {
|
||||
if (removeObserver) {
|
||||
removeStaggeredObserver()
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import eu.kanade.tachiyomi.ui.base.MaterialFastScroll
|
||||
|
||||
class LibraryFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
MaterialFastScroll(context, attrs) {
|
||||
|
||||
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)
|
||||
var targetPos = getTargetPos(y)
|
||||
val category = when (val item = adapter.getItem(targetPos)) {
|
||||
is LibraryItem -> {
|
||||
targetPos = adapter.currentItems.indexOf(item.header)
|
||||
item.header.category
|
||||
}
|
||||
is LibraryHeaderItem -> item.category
|
||||
else -> return super.setRecyclerViewPosition(y)
|
||||
}
|
||||
adapter.controller?.scrollToCategory(category)
|
||||
updateBubbleText(targetPos)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -121,7 +121,7 @@
|
|||
|
||||
</FrameLayout>
|
||||
|
||||
<eu.kanade.tachiyomi.ui.base.MaterialFastScroll
|
||||
<eu.kanade.tachiyomi.ui.library.LibraryFastScroll
|
||||
android:id="@+id/fast_scroller"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue