From 75d4d274f63112a65e4befa19639bc93fc56b0bc Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 18 May 2020 18:02:46 -0400 Subject: [PATCH] Category recycler puts active category center of view if list is scrollable Also removed scrolling logic for opening/closing the sheet --- .../tachiyomi/ui/library/LibraryController.kt | 22 +------------------ .../library/category/CategoryRecyclerView.kt | 11 ++++++++++ 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 6909a1d87b..76cfaf4dea 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -749,30 +749,10 @@ class LibraryController( val translateY = if (show) full else 0f recycler.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().alpha(if (show) 0.75f else 0f).start() if (show) { + category_recycler.scrollToCategory(activeCategory) fast_scroller?.hideScrollbar() activity?.appbar?.y = 0f elevateFunc(false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt index 3c7822a2de..00d338da05 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt @@ -10,6 +10,7 @@ import com.mikepenz.fastadapter.adapters.ItemAdapter import com.mikepenz.fastadapter.listeners.OnBindViewHolderListenerImpl import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category +import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.view.marginBottom 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) { selectedCategory = selected for (i in 0..manager.itemCount) {