More fixes for auto hide on library

Should be nearly perfect now
This commit is contained in:
Jays2Kings 2021-03-24 01:57:04 -04:00
parent a15d473c19
commit d846033fcf
4 changed files with 62 additions and 23 deletions

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.library
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
@ -198,6 +199,7 @@ class LibraryController(
private val showCategoryInTitle
get() = preferences.showCategoryInTitle().get() && presenter.showAllCategories
private lateinit var elevateAppBar: ((Boolean) -> Unit)
private var hopperOffset = 0f
override fun getTitle(): String? {
return if (!showCategoryInTitle || header_title.text.isNullOrBlank() || recycler_cover?.isClickable == true) {
@ -213,9 +215,8 @@ class LibraryController(
val recyclerCover = recycler_cover ?: return
if (!recyclerCover.isClickable && isAnimatingHopper != true) {
if (preferences.autohideHopper().get()) {
category_hopper_frame.translationY += dy
category_hopper_frame.translationY =
category_hopper_frame.translationY.coerceIn(0f, 50f.dpToPx)
hopperOffset += dy
hopperOffset = hopperOffset.coerceIn(0f, 55f.dpToPx)
}
up_category.alpha = if (isAtTop()) 0.25f else 1f
down_category.alpha = if (isAtBottom()) 0.25f else 1f
@ -244,13 +245,14 @@ class LibraryController(
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
val recyclerCover = recycler_cover ?: return
recycler_cover ?: return
when (newState) {
RecyclerView.SCROLL_STATE_DRAGGING -> {
fast_scroller.showScrollbar()
}
RecyclerView.SCROLL_STATE_IDLE -> {
updateHopperPosition()
updateFilterSheetY()
}
}
}
@ -260,6 +262,7 @@ class LibraryController(
val bottomBar = activity?.bottom_nav
filter_bottom_sheet ?: return
if (bottomBar != null) {
updateHopperY()
if (filter_bottom_sheet.sheetBehavior.isHidden()) {
val pad = bottomBar.translationY - bottomBar.height
filter_bottom_sheet.translationY = pad
@ -270,11 +273,16 @@ class LibraryController(
shadow2.translationY = pad
filter_bottom_sheet.updatePaddingRelative(
bottom = max(
(-bottomBar.translationY + bottomBar.height).toInt(),
(-pad).toInt(),
view?.rootWindowInsets?.getBottomGestureInsets() ?: 0
)
)
filter_bottom_sheet.sheetBehavior?.peekHeight = 60.dpToPx + filter_bottom_sheet.paddingBottom
val padding = max(
(-pad).toInt(),
view?.rootWindowInsets?.getBottomGestureInsets() ?: 0
)
filter_bottom_sheet.sheetBehavior?.peekHeight = 60.dpToPx + padding
fast_scroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = -pad.toInt()
}
@ -285,10 +293,22 @@ class LibraryController(
val shortAnimationDuration = resources?.getInteger(
android.R.integer.config_shortAnimTime
) ?: 0
category_hopper_frame.animate().translationY(
if (!show && category_hopper_frame.translationY > 25f.dpToPx) 50f.dpToPx
else 0f
).setDuration(shortAnimationDuration.toLong()).start()
if (preferences.autohideHopper().get()) {
val end = if (!show && hopperOffset > 25f.dpToPx) 55f.dpToPx else 0f
val alphaAnimation = ValueAnimator.ofFloat(hopperOffset, end)
alphaAnimation.addUpdateListener { valueAnimator ->
hopperOffset = valueAnimator.animatedValue as Float
updateHopperY()
}
alphaAnimation.addListener(
EndAnimatorListener {
hopperOffset = end
updateHopperY()
}
)
alphaAnimation.duration = shortAnimationDuration.toLong()
alphaAnimation.start()
}
}
fun saveActiveCategory(category: Category) {
@ -569,7 +589,7 @@ class LibraryController(
}
hideHopper(preferences.hideHopper().get())
category_hopper_frame.updateLayoutParams<CoordinatorLayout.LayoutParams> {
anchorGravity = Gravity.TOP or when (gravityPref) {
gravity = Gravity.TOP or when (gravityPref) {
0 -> Gravity.LEFT
2 -> Gravity.RIGHT
else -> Gravity.CENTER
@ -585,8 +605,29 @@ class LibraryController(
}
}
fun updateHopperY() {
val view = view ?: return
val listOfYs = mutableListOf(
filter_bottom_sheet.y,
activity?.bottom_nav?.y ?: filter_bottom_sheet.y
)
val insetBottom = view.rootWindowInsets?.systemWindowInsetBottom ?: 0
if (!preferences.autohideHopper().get()) {
listOfYs.add(view.height - (insetBottom).toFloat())
}
category_hopper_frame.y = -category_hopper_frame.height +
(listOfYs.minOrNull() ?: filter_bottom_sheet.y) +
hopperOffset
if (view.height - insetBottom < category_hopper_frame.y) {
jumper_category_text.translationY = -(category_hopper_frame.y - (view.height - insetBottom))
} else {
jumper_category_text.translationY = 0f
}
}
fun resetHopperY() {
category_hopper_frame.translationY = 0f
hopperOffset = 0f
}
fun hideHopper(hide: Boolean) {

View File

@ -42,9 +42,9 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
) {
if (diffX <= 0) {
controller.category_hopper_frame.updateLayoutParams<CoordinatorLayout.LayoutParams> {
anchorGravity =
gravity =
Gravity.TOP or (
if (anchorGravity == Gravity.TOP or Gravity.RIGHT) {
if (gravity == Gravity.TOP or Gravity.RIGHT) {
controller.preferences.hopperGravity().set(1)
Gravity.CENTER
} else {
@ -55,9 +55,9 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
}
} else {
controller.category_hopper_frame.updateLayoutParams<CoordinatorLayout.LayoutParams> {
anchorGravity =
Gravity.TOP or Gravity.TOP or (
if (anchorGravity == Gravity.TOP or Gravity.LEFT) {
gravity =
Gravity.TOP or (
if (gravity == Gravity.TOP or Gravity.LEFT) {
controller.preferences.hopperGravity().set(1)
Gravity.CENTER
} else {

View File

@ -115,16 +115,15 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
sheetBehavior?.addBottomSheetCallback(
object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, progress: Float) {
this@FilterBottomSheet.controller?.updateFilterSheetY()
pill.alpha = (1 - max(0f, progress)) * 0.25f
shadow2.alpha = (1 - max(0f, progress)) * 0.25f
shadow.alpha = 1 + min(0f, progress)
updateRootPadding(progress)
val bottomBar = (this@FilterBottomSheet.controller?.activity as? MainActivity)?.bottom_nav ?: return
val pad = bottomBar.translationY - bottomBar.height
translationY = pad * -min(0f, progress)
}
override fun onStateChanged(p0: View, state: Int) {
this@FilterBottomSheet.controller?.updateFilterSheetY()
stateChanged(state)
}
}
@ -190,6 +189,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
private fun stateChanged(state: Int) {
val shadow = controller?.shadow ?: return
controller?.updateHopperY()
if (state == BottomSheetBehavior.STATE_COLLAPSED) {
shadow.alpha = 1f
libraryRecyler?.updatePaddingRelative(bottom = sheetBehavior?.peekHeight ?: 0 + 10.dpToPx + bottomBarHeight)

View File

@ -117,9 +117,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:elevation="6dp"
app:layout_anchor="@id/filter_bottom_sheet"
app:layout_anchorGravity="top|center">
android:elevation="6dp">
<include layout="@layout/rounded_category_hopper" />