Category recycler puts active category center of view if list is scrollable

Also removed scrolling logic for opening/closing the sheet
This commit is contained in:
Jay 2020-05-18 18:02:46 -04:00
parent 511fa31798
commit 75d4d274f6
2 changed files with 12 additions and 21 deletions

View File

@ -749,30 +749,10 @@ class LibraryController(
val translateY = if (show) full else 0f val translateY = if (show) full else 0f
recycler.animate().translationY(translateY).start() recycler.animate().translationY(translateY).start()
category_hopper_frame.animate().translationY(translateY).start() category_hopper_frame.animate().translationY(translateY).start()
if (scroll) {
// Smooth scroll the recycler to hide the hidden content blocked by the app bar
val vA = ValueAnimator.ofInt(recycler.translationY.roundToInt(), translateY
.roundToInt()).apply {
var start = 0f
var last = recycler.translationY.roundToInt()
val distance = abs(recycler.translationY.roundToInt() - translateY.roundToInt())
addUpdateListener {
val diff = abs(it.animatedValue as Int - last)
last = it.animatedValue as Int
start += diff.toFloat() / distance * recycler.paddingTop.toFloat()
if (start > 1) {
recycler.scrollBy(0, start.toInt() * if (show) 1 else -1)
start %= 1
}
}
addListener(EndAnimatorListener {
fast_scroller?.hideScrollbar()
})
}.start()
}
recycler_cover.animate().translationY(translateY).start() recycler_cover.animate().translationY(translateY).start()
recycler_cover.animate().alpha(if (show) 0.75f else 0f).start() recycler_cover.animate().alpha(if (show) 0.75f else 0f).start()
if (show) { if (show) {
category_recycler.scrollToCategory(activeCategory)
fast_scroller?.hideScrollbar() fast_scroller?.hideScrollbar()
activity?.appbar?.y = 0f activity?.appbar?.y = 0f
elevateFunc(false) elevateFunc(false)

View File

@ -10,6 +10,7 @@ import com.mikepenz.fastadapter.adapters.ItemAdapter
import com.mikepenz.fastadapter.listeners.OnBindViewHolderListenerImpl import com.mikepenz.fastadapter.listeners.OnBindViewHolderListenerImpl
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.marginBottom import eu.kanade.tachiyomi.util.view.marginBottom
class CategoryRecyclerView @JvmOverloads constructor( class CategoryRecyclerView @JvmOverloads constructor(
@ -51,6 +52,16 @@ class CategoryRecyclerView @JvmOverloads constructor(
} }
} }
fun scrollToCategory(order: Int) {
val index = itemAdapter.adapterItems.indexOfFirst { it.category.order == order }
if (index > -1) {
manager.scrollToPositionWithOffset(
index,
(height - 38.dpToPx) / 2
)
}
}
fun setCategories(selected: Int) { fun setCategories(selected: Int) {
selectedCategory = selected selectedCategory = selected
for (i in 0..manager.itemCount) { for (i in 0..manager.itemCount) {