From 2413d4c91eacc6be1fe56038ed6d5772ffbb0da9 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 23 May 2020 15:50:50 -0400 Subject: [PATCH] Pressing category button in hopper opens a mini category jump sheet instead of opening backdrop --- .../tachiyomi/ui/base/MaxHeightScrollView.kt | 19 +++++++++ .../tachiyomi/ui/library/LibraryController.kt | 14 ++++++- .../tachiyomi/ui/library/MaterialMenuSheet.kt | 40 ++++++++++++------- app/src/main/res/layout/bottom_menu_sheet.xml | 5 ++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/base/MaxHeightScrollView.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaxHeightScrollView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaxHeightScrollView.kt new file mode 100644 index 0000000000..bc8f5749d6 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaxHeightScrollView.kt @@ -0,0 +1,19 @@ +package eu.kanade.tachiyomi.ui.base + +import android.content.Context +import android.util.AttributeSet +import androidx.core.widget.NestedScrollView + +class MaxHeightScrollView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + NestedScrollView(context, attrs) { + var maxHeight = -1 + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + val heightS = if (maxHeight > 0) { + MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST) + } else { + heightMeasureSpec + } + super.onMeasure(widthMeasureSpec, heightS) + } +} 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 f729a0aa2d..192500fb1b 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 @@ -481,7 +481,19 @@ class LibraryController( true } category_button.setOnClickListener { - showCategories(!recycler_cover.isClickable) + val items = presenter.categories.map { category -> + MaterialMenuSheet.MenuSheetItem(category.order, text = category.name) + } + MaterialMenuSheet( + activity!!, + items, + it.context.getString(R.string.jump_to_category), + activeCategory, + 300.dpToPx + ) { _, item -> + scrollToHeader(item) + true + }.show() } category_button.setOnLongClickListener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/MaterialMenuSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/MaterialMenuSheet.kt index d945a1c18c..59a8c5ebc4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/MaterialMenuSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/MaterialMenuSheet.kt @@ -36,6 +36,7 @@ class MaterialMenuSheet( items: List, title: String? = null, selectedId: Int? = null, + maxHeight: Int? = null, onMenuItemClicked: (MaterialMenuSheet, Int) -> Boolean ) : BottomSheetDialog @@ -50,6 +51,10 @@ class MaterialMenuSheet( if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !context.isInNightMode() && !activity.window.decorView.rootWindowInsets.hasSideNavBar()) { window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR } + maxHeight?.let { + menu_scroll_view.maxHeight = it + menu_scroll_view.requestLayout() + } var currentIndex: Int? = null items.forEachIndexed { index, item -> @@ -76,6 +81,9 @@ class MaterialMenuSheet( setText(item.textRes) } setCompoundDrawablesRelativeWithIntrinsicBounds(item.drawable, 0, 0, 0) + if (item.drawable == 0) { + textSize = 14f + } if (item.id == selectedId) { currentIndex = index setTextColorRes(R.color.colorAccent) @@ -103,23 +111,27 @@ class MaterialMenuSheet( } } - var isNotElevated = false + var isElevated = false var elevationAnimator: ValueAnimator? = null + + fun elevate(elevate: Boolean) { + elevationAnimator?.cancel() + isElevated = elevate + elevationAnimator?.cancel() + elevationAnimator = ObjectAnimator.ofFloat( + title_layout, "elevation", title_layout.elevation, if (elevate) 10f else 0f + ) + ObjectAnimator.ofFloat( + bottom_divider, "alpha", bottom_divider.alpha, if (elevate) 0f else 1f + ).start() + elevationAnimator?.start() + } + elevate(menu_scroll_view.canScrollVertically(-1)) if (title_layout.isVisible()) { menu_scroll_view.setOnScrollChangeListener { _: View?, _: Int, _: Int, _: Int, _: Int -> - val atTop = !menu_scroll_view.canScrollVertically(-1) - if (atTop != isNotElevated) { - elevationAnimator?.cancel() - isNotElevated = atTop - elevationAnimator?.cancel() - elevationAnimator = ObjectAnimator.ofFloat( - title_layout, - "elevation", - title_layout.elevation, - if (atTop) 0f else 10f.dpToPx - ) - elevationAnimator?.duration = 100 - elevationAnimator?.start() + val notAtTop = menu_scroll_view.canScrollVertically(-1) + if (notAtTop != isElevated) { + elevate(notAtTop) } } } diff --git a/app/src/main/res/layout/bottom_menu_sheet.xml b/app/src/main/res/layout/bottom_menu_sheet.xml index a7541e6802..12327ea801 100644 --- a/app/src/main/res/layout/bottom_menu_sheet.xml +++ b/app/src/main/res/layout/bottom_menu_sheet.xml @@ -9,7 +9,7 @@ app:layout_constraintVertical_chainStyle="packed" android:backgroundTint="?android:attr/colorBackground"> - - + A category with that name already exists! Category deleted Press and hold to edit a category + Jump to category Update