Updated logic to elevating the toolbar
This commit is contained in:
parent
8609145622
commit
4df4a5b59d
2 changed files with 20 additions and 33 deletions
|
@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.library
|
|||
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ObjectAnimator
|
||||
import android.animation.ValueAnimator
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
|
@ -177,8 +176,7 @@ class LibraryController(
|
|||
private var filterTooltip: ViewTooltip? = null
|
||||
private var isAnimatingHopper: Boolean? = null
|
||||
var hasMovedHopper = preferences.shownHopperSwipeTutorial().get()
|
||||
private var elevationAnim: ValueAnimator? = null
|
||||
private var elevate = false
|
||||
private lateinit var elevateAppBar: ((Boolean) -> Unit)
|
||||
|
||||
override fun getTitle(): String? {
|
||||
return view?.context?.getString(R.string.library)
|
||||
|
@ -188,8 +186,6 @@ class LibraryController(
|
|||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
val recyclerCover = recycler_cover ?: return
|
||||
val notAtTop = recycler.canScrollVertically(-1)
|
||||
if (notAtTop != elevate) elevateFunc(notAtTop)
|
||||
val order = getCategoryOrder()
|
||||
if (!recyclerCover.isClickable && isAnimatingHopper != true) {
|
||||
category_hopper_frame.translationY += dy
|
||||
|
@ -372,6 +368,7 @@ class LibraryController(
|
|||
}
|
||||
}
|
||||
|
||||
elevateAppBar =
|
||||
scrollViewWith(recycler, swipeRefreshLayout = swipe_refresh, afterInsets = { insets ->
|
||||
category_layout?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = recycler?.paddingTop ?: 0
|
||||
|
@ -379,6 +376,7 @@ class LibraryController(
|
|||
fast_scroller?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = recycler?.paddingTop ?: 0
|
||||
}
|
||||
header_title?.updatePaddingRelative(top = insets.systemWindowInsetTop + 2.dpToPx)
|
||||
})
|
||||
|
||||
swipe_refresh.setOnRefreshListener {
|
||||
|
@ -751,32 +749,20 @@ class LibraryController(
|
|||
category_hopper_frame.animate().translationY(translateY).start()
|
||||
recycler_cover.animate().translationY(translateY).start()
|
||||
recycler_cover.animate().alpha(if (show) 0.75f else 0f).start()
|
||||
recycler.suppressLayout(show)
|
||||
activity?.toolbar?.showDropdown(!show)
|
||||
if (show) {
|
||||
category_recycler.scrollToCategory(activeCategory)
|
||||
fast_scroller?.hideScrollbar()
|
||||
activity?.appbar?.y = 0f
|
||||
elevateFunc(false)
|
||||
activity?.dropdown?.setImageResource(R.drawable.ic_arrow_drop_up_24dp)
|
||||
elevateAppBar(false)
|
||||
filter_bottom_sheet?.sheetBehavior?.hide()
|
||||
} else {
|
||||
val notAtTop = recycler.canScrollVertically(-1)
|
||||
if (notAtTop != elevate) elevateFunc(notAtTop)
|
||||
activity?.dropdown?.setImageResource(R.drawable.ic_arrow_drop_down_24dp)
|
||||
elevateAppBar(notAtTop)
|
||||
}
|
||||
}
|
||||
|
||||
private fun elevateFunc(el: Boolean) {
|
||||
elevate = el
|
||||
elevationAnim?.cancel()
|
||||
elevationAnim = ValueAnimator.ofFloat(
|
||||
activity?.appbar?.elevation ?: 0f, if (el) 15f else 0f
|
||||
)
|
||||
elevationAnim?.addUpdateListener { valueAnimator ->
|
||||
activity?.appbar?.elevation = valueAnimator.animatedValue as Float
|
||||
}
|
||||
elevationAnim?.start()
|
||||
}
|
||||
|
||||
fun setActiveCategory() {
|
||||
val currentCategory = presenter.categories.indexOfFirst {
|
||||
if (presenter.showAllCategories) it.order == activeCategory else presenter.currentCategory == it.id
|
||||
|
|
|
@ -62,7 +62,7 @@ fun Controller.scrollViewWith(
|
|||
swipeRefreshLayout: SwipeRefreshLayout? = null,
|
||||
afterInsets: ((WindowInsets) -> Unit)? = null,
|
||||
liftOnScroll: ((Boolean) -> Unit)? = null
|
||||
) {
|
||||
): ((Boolean) -> Unit) {
|
||||
var statusBarHeight = -1
|
||||
activity?.appbar?.y = 0f
|
||||
val attrsArray = intArrayOf(R.attr.actionBarSize)
|
||||
|
@ -98,7 +98,7 @@ fun Controller.scrollViewWith(
|
|||
elevate = el
|
||||
if (liftOnScroll != null) {
|
||||
liftOnScroll.invoke(el)
|
||||
} else if (recycler.translationY == 0f) {
|
||||
} else {
|
||||
elevationAnim?.cancel()
|
||||
elevationAnim = ValueAnimator.ofFloat(
|
||||
activity?.appbar?.elevation ?: 0f, if (el) 15f else 0f
|
||||
|
@ -173,8 +173,8 @@ fun Controller.scrollViewWith(
|
|||
activity!!.appbar.y = MathUtils.clamp(
|
||||
activity!!.appbar.y, -activity!!.appbar.height.toFloat(), 0f
|
||||
)
|
||||
if ((activity!!.appbar.y <= -activity!!.appbar.height.toFloat() ||
|
||||
dy == 0 && activity!!.appbar.y == 0f) && !elevate)
|
||||
if (((activity!!.appbar.y <= -activity!!.appbar.height.toFloat() ||
|
||||
dy == 0 && activity!!.appbar.y == 0f) || dy == 0) && !elevate)
|
||||
elevateFunc(true)
|
||||
lastY = activity!!.appbar.y
|
||||
}
|
||||
|
@ -203,6 +203,7 @@ fun Controller.scrollViewWith(
|
|||
}
|
||||
}
|
||||
})
|
||||
return elevateFunc
|
||||
}
|
||||
|
||||
fun Controller.requestPermissionsSafe(permissions: Array<String>, requestCode: Int) {
|
||||
|
|
Reference in a new issue