mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
Pressing category button in hopper opens a mini category jump sheet
instead of opening backdrop
This commit is contained in:
parent
b3069b191e
commit
2413d4c91e
@ -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)
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -36,6 +36,7 @@ class MaterialMenuSheet(
|
||||
items: List<MenuSheetItem>,
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
android:backgroundTint="?android:attr/colorBackground">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
<eu.kanade.tachiyomi.ui.base.MaxHeightScrollView
|
||||
android:id="@+id/menu_scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -25,7 +25,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</eu.kanade.tachiyomi.ui.base.MaxHeightScrollView>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/title_layout"
|
||||
@ -60,6 +60,7 @@
|
||||
tools:text="Title Text" />
|
||||
|
||||
<View
|
||||
android:id="@+id/bottom_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/divider"
|
||||
|
@ -91,6 +91,7 @@
|
||||
<string name="category_with_name_exists">A category with that name already exists!</string>
|
||||
<string name="category_deleted">Category deleted</string>
|
||||
<string name="long_press_category">Press and hold to edit a category</string>
|
||||
<string name="jump_to_category">Jump to category</string>
|
||||
|
||||
<!-- Updates -->
|
||||
<string name="update">Update</string>
|
||||
|
Loading…
Reference in New Issue
Block a user