From 60bb7d919d8b25ed37671514e224f094d6283497 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 13 Apr 2020 02:26:19 -0400 Subject: [PATCH] Showing category change via the fastscroll indicator, Library title is now always "Library" --- .../tachiyomi/ui/library/LibraryController.kt | 64 +++++++++++++++---- .../res/layout/library_list_controller.xml | 7 +- .../res/layout/manga_details_controller.xml | 2 +- app/src/main/res/values/colors.xml | 2 +- 4 files changed, 57 insertions(+), 18 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 4ef7a1e185..0052770720 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 @@ -139,10 +139,7 @@ class LibraryController( private var alwaysShowScroller: Boolean = preferences.alwaysShowSeeker().getOrDefault() override fun getTitle(): String? { - return if (view != null && presenter.categories.size > 1) presenter.categories.find { - it.order == activeCategory - }?.name ?: view?.context?.getString(R.string.library) - else view?.context?.getString(R.string.library) + return view?.context?.getString(R.string.library) } private var scrollListener = object : RecyclerView.OnScrollListener() { @@ -159,7 +156,22 @@ class LibraryController( if (order != null && order != activeCategory && lastItem == null) { preferences.lastUsedCategory().set(order) activeCategory = order - setTitle() + if (presenter.categories.size > 1 && dy != 0 && abs(dy) > 75) { + val headerItem = getHeader() ?: return + val view = fast_scroller.getChildAt(0) ?: return + val index = adapter.headerItems.indexOf(headerItem) + textAnim?.cancel() + textAnim = text_view_m.animate().alpha(0f).setDuration(250L).setStartDelay(2000) + textAnim?.start() + + // fastScroll height * indicator position - center text - fastScroll padding + text_view_m.translationY = view.height * + (index.toFloat() / (adapter.headerItems.size + 1)) + - text_view_m.height / 2 + 16.dpToPx + text_view_m.translationX = 50f.dpToPx + text_view_m.alpha = 1f + text_view_m.text = headerItem.category.name + } } } @@ -206,7 +218,7 @@ class LibraryController( super.onViewCreated(view) view.applyWindowInsetsForRootController(activity!!.bottom_nav) if (!::presenter.isInitialized) presenter = LibraryPresenter(this) - fast_scroller.translationX = 25f.dpToPx + if (!alwaysShowScroller) fast_scroller.translationX = 25f.dpToPx setFastScrollBackground() adapter = LibraryCategoryAdapter(this) @@ -248,9 +260,22 @@ class LibraryController( textAnim?.start() text_view_m.translationY = indicatorCenterY.toFloat() - text_view_m.height / 2 + text_view_m.translationX = 0f text_view_m.alpha = 1f text_view_m.text = adapter.onCreateBubbleText(itemPosition) val appbar = activity?.appbar + + if (singleCategory) { + val order = when (val item = adapter.getItem(itemPosition)) { + is LibraryHeaderItem -> item + is LibraryItem -> item.header + else -> null + }?.category?.order + if (order != null) { + activeCategory = order + preferences.lastUsedCategory().set(order) + } + } appbar?.y = 0f recycler.suppressLayout(true) (recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( @@ -333,6 +358,25 @@ class LibraryController( } } + private fun getHeader(): LibraryHeaderItem? { + val position = + (recycler.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition() + if (position > 0) { + when (val item = adapter.getItem(position)) { + is LibraryHeaderItem -> return item + is LibraryItem -> return item.header + } + } else { + val fPosition = + (recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() + when (val item = adapter.getItem(fPosition)) { + is LibraryHeaderItem -> return item + is LibraryItem -> return item.header + } + } + return null + } + private fun getCategoryOrder(): Int? { val position = (recycler.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition() @@ -445,13 +489,12 @@ class LibraryController( adapter.setItems(mangaMap) singleCategory = presenter.categories.size <= 1 - setTitle() + progress.gone() if (!freshStart) { justStarted = false if (recycler_layout.alpha == 0f) recycler_layout.animate().alpha(1f).setDuration(500) .start() } else if (justStarted && freshStart) { - progress.gone() scrollToHeader(activeCategory) fast_scroller.translationX = 0f view?.post { @@ -675,9 +718,6 @@ class LibraryController( ) == null ) { recycler.scrollBy(0, recycler.paddingTop) - view?.post { - setTitle() - } } activity?.appbar?.y = 0f if (lastItemPosition == toPosition) lastItemPosition = null @@ -695,11 +735,11 @@ class LibraryController( } override fun onItemReleased(position: Int) { + lastItem = null if (adapter.selectedItemCount > 0) { lastItemPosition = null return } - lastItem = null destroyActionModeIfNeeded() // if nothing moved if (lastItemPosition == null) return diff --git a/app/src/main/res/layout/library_list_controller.xml b/app/src/main/res/layout/library_list_controller.xml index 7725b9d5e9..1501a63f8d 100644 --- a/app/src/main/res/layout/library_list_controller.xml +++ b/app/src/main/res/layout/library_list_controller.xml @@ -55,15 +55,14 @@ tools:alpha="1" android:layout_marginEnd="50dp" android:background="@drawable/round_textview_background" - android:backgroundTint="@color/md_grey_800_50" - android:padding="12dp" + android:backgroundTint="@color/md_grey_800_85" + android:padding="10dp" android:textColor="@android:color/white" app:layout_constraintEnd_toStartOf="@id/fast_scroller" app:layout_constraintTop_toTopOf="@id/fast_scroller" - tools:text="sdfsdf" /> + tools:text="Category" /> - #FAFAFA #CCCCCC #424242 - #CF424242 + #DF424242 #80448AFF