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

View File

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

View File

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

View File

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