diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 386bca05e1..65df83504b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -273,6 +273,8 @@ class PreferencesHelper(val context: Context) { fun groupLibraryBy() = flowPrefs.getInt("group_library_by", 0) + fun showCategoryInTitle() = flowPrefs.getBoolean("category_in_title", false) + // Tutorial preferences fun shownFilterTutorial() = flowPrefs.getBoolean("shown_filter_tutorial", false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt index 3d95a6efe3..463333c127 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt @@ -85,6 +85,11 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee } show_all.bindToPreference(preferences.showAllCategories()) { controller.presenter.getLibrary() + category_show.isEnabled = it + } + category_show.isEnabled = show_all.isChecked + category_show.bindToPreference(preferences.showCategoryInTitle()) { + controller.showMiniBar() } hide_hopper.bindToPreference(preferences.hideHopper()) { controller.hideHopper(it) 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 061f40a2e3..a16a50d32a 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 @@ -177,17 +177,22 @@ class LibraryController( private var isAnimatingHopper: Boolean? = null var hasMovedHopper = preferences.shownHopperSwipeTutorial().get() private var shouldScrollToTop = false + private val showCategoryInTitle + get() = preferences.showCategoryInTitle().get() && presenter.showAllCategories private lateinit var elevateAppBar: ((Boolean) -> Unit) override fun getTitle(): String? { - return view?.context?.getString(R.string.library) + return if (!showCategoryInTitle || header_title.text.isNullOrBlank() || recycler_cover?.isClickable == true) { + view?.context?.getString(R.string.library) + } else { + header_title.text.toString() + } } private var scrollListener = object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { super.onScrolled(recyclerView, dx, dy) val recyclerCover = recycler_cover ?: return - val order = getCategoryOrder() if (!recyclerCover.isClickable && isAnimatingHopper != true) { category_hopper_frame.translationY += dy category_hopper_frame.translationY = @@ -202,13 +207,11 @@ class LibraryController( scrollDistance = 0f } } else scrollDistance = 0f - if (order != null && order != activeCategory && lastItem == null) { - preferences.lastUsedCategory().set(order) - activeCategory = order - setActiveCategory() - if (presenter.categories.size > 1 && dy != 0 && recyclerView.translationY == 0f) { - val headerItem = getHeader() ?: return - showCategoryText(headerItem.category.name) + val currentCategory = getHeader()?.category ?: return + if (currentCategory.order != activeCategory) { + saveActiveCategory(currentCategory) + if (!showCategoryInTitle && presenter.categories.size > 1 && dy != 0 && recyclerView.translationY == 0f) { + showCategoryText(currentCategory.name) } } } @@ -235,6 +238,30 @@ class LibraryController( } } + fun saveActiveCategory(category: Category) { + preferences.lastUsedCategory().set(category.order) + activeCategory = category.order + val headerItem = getHeader() ?: return + header_title.text = headerItem.category.name + setActiveCategory() + } + + private fun setActiveCategory() { + val currentCategory = presenter.categories.indexOfFirst { + if (presenter.showAllCategories) it.order == activeCategory else presenter.currentCategory == it.id + } + if (currentCategory > -1) { + category_recycler.setCategories(currentCategory) + header_title.text = presenter.categories[currentCategory].name + setTitle() + } + } + + fun showMiniBar() { + header_title.visibleIf(showCategoryInTitle) + setTitle() + } + fun showCategoryText(name: String) { textAnim?.cancel() textAnim = jumper_category_text.animate().alpha(0f).setDuration(250L).setStartDelay(2000) @@ -316,7 +343,7 @@ class LibraryController( category_recycler.onCategoryClicked = { recycler.itemAnimator = null scrollToHeader(it) - showCategories(show = false, scroll = false) + showCategories(show = false) } category_recycler.onShowAllClicked = { isChecked -> preferences.showAllCategories().set(isChecked) @@ -378,6 +405,8 @@ class LibraryController( topMargin = recycler?.paddingTop ?: 0 } header_title?.updatePaddingRelative(top = insets.systemWindowInsetTop + 2.dpToPx) + }, onLeavingController = { + header_title?.gone() }) swipe_refresh.setOnRefreshListener { @@ -690,6 +719,11 @@ class LibraryController( if (justStarted && freshStart) { scrollToHeader(activeCategory) } + recycler.post { + elevateAppBar(recycler.canScrollVertically(-1)) + setActiveCategory() + } + category_hopper_frame.visibleIf(!singleCategory && !preferences.hideHopper().get()) filter_bottom_sheet.updateButtons( showExpand = !singleCategory && presenter.showAllCategories, groupType = presenter.groupType @@ -697,22 +731,25 @@ class LibraryController( adapter.isLongPressDragEnabled = canDrag() category_recycler.setCategories(presenter.categories) filter_bottom_sheet.setExpandText(preferences.collapsedCategories().getOrDefault().isNotEmpty()) - setActiveCategory() if (shouldScrollToTop) { recycler.scrollToPosition(0) shouldScrollToTop = false } if (onRoot) { - activity?.toolbar?.setOnClickListener { - val recycler = recycler ?: return@setOnClickListener - if (singleCategory) { - recycler.scrollToPosition(0) - } else { - showCategories(recycler.translationY == 0f) + listOf(activity?.toolbar, header_title).forEach { + it?.setOnClickListener { + val recycler = recycler ?: return@setOnClickListener + if (singleCategory) { + recycler.scrollToPosition(0) + } else { + showCategories(recycler.translationY == 0f) + } + } + if (!hasMovedHopper && isAnimatingHopper == null) { + showSlideAnimation() } } - if (!hasMovedHopper && isAnimatingHopper == null) { - showSlideAnimation() + showMiniBar() } } @@ -750,7 +787,7 @@ class LibraryController( .setDuration(duration) } - private fun showCategories(show: Boolean, scroll: Boolean = true) { + private fun showCategories(show: Boolean) { recycler_cover.isClickable = show recycler_cover.isFocusable = show val full = category_layout.height.toFloat() + recycler.paddingTop @@ -761,6 +798,7 @@ class LibraryController( recycler_cover.animate().alpha(if (show) 0.75f else 0f).start() recycler.suppressLayout(show) activity?.toolbar?.showDropdown(!show) + setTitle() if (show) { category_recycler.scrollToCategory(activeCategory) fast_scroller?.hideScrollbar() @@ -773,13 +811,6 @@ class LibraryController( } } - fun setActiveCategory() { - val currentCategory = presenter.categories.indexOfFirst { - if (presenter.showAllCategories) it.order == activeCategory else presenter.currentCategory == it.id - } - category_recycler.setCategories(currentCategory) - } - private fun scrollToHeader(pos: Int) { if (!presenter.showAllCategories) { presenter.switchSection(pos) @@ -803,6 +834,11 @@ class LibraryController( else -> (-30).dpToPx }) + appbarOffset ) + (adapter.getItem(headerPosition) as? LibraryHeaderItem)?.category?.let { + saveActiveCategory(it) + } + activeCategory = pos + preferences.lastUsedCategory().set(pos) recycler.suppressLayout(false) } } @@ -984,7 +1020,6 @@ class LibraryController( val position = viewHolder?.adapterPosition ?: return swipe_refresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_DRAG if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { - activity?.appbar?.y = 0f if (lastItemPosition != null && position != lastItemPosition && lastItem == adapter.getItem( position ) @@ -1022,7 +1057,6 @@ class LibraryController( ) { recycler.scrollBy(0, recycler.paddingTop) } - activity?.appbar?.y = 0f if (lastItemPosition == toPosition) lastItemPosition = null else if (lastItemPosition == null) lastItemPosition = fromPosition } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt index 190ef11c4c..41cd90baff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt @@ -61,7 +61,8 @@ fun Controller.scrollViewWith( customPadding: Boolean = false, swipeRefreshLayout: SwipeRefreshLayout? = null, afterInsets: ((WindowInsets) -> Unit)? = null, - liftOnScroll: ((Boolean) -> Unit)? = null + liftOnScroll: ((Boolean) -> Unit)? = null, + onLeavingController: (() -> Unit)? = null ): ((Boolean) -> Unit) { var statusBarHeight = -1 activity?.appbar?.y = 0f @@ -119,7 +120,7 @@ fun Controller.scrollViewWith( if (changeType.isEnter) { elevateFunc(elevate) if (fakeToolbarView?.parent != null) { - val parent = recycler.parent as? ViewGroup ?: return + val parent = fakeToolbarView?.parent as? ViewGroup ?: return parent.removeView(fakeToolbarView) fakeToolbarView = null } @@ -145,6 +146,7 @@ fun Controller.scrollViewWith( params?.width = MATCH_PARENT v.setBackgroundColor(v.context.getResourceColor(R.attr.colorSecondary)) v.layoutParams = params + onLeavingController?.invoke() } elevationAnim?.cancel() if (activity!!.toolbar.tag == randomTag) activity!!.toolbar.setOnClickListener(null) diff --git a/app/src/main/res/layout/display_bottom_sheet.xml b/app/src/main/res/layout/display_bottom_sheet.xml index df6057ba31..872824b7d3 100644 --- a/app/src/main/res/layout/display_bottom_sheet.xml +++ b/app/src/main/res/layout/display_bottom_sheet.xml @@ -27,7 +27,7 @@ android:layout_height="wrap_content" android:paddingStart="16dp" android:paddingEnd="12dp" - android:text="@string/display_as" /> + android:text="@string/display" /> + + + android:layout_marginTop="?actionBarSize" > + + No matches found for your current filters Show all categories + Always show current category Expand all categories Collapse all categories Reorder filters