Updated logic to elevating the toolbar

This commit is contained in:
Jay 2020-05-18 23:26:05 -04:00
parent 8609145622
commit 4df4a5b59d
2 changed files with 20 additions and 33 deletions

View File

@ -2,7 +2,6 @@ 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.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
@ -177,8 +176,7 @@ class LibraryController(
private var filterTooltip: ViewTooltip? = null private var filterTooltip: ViewTooltip? = null
private var isAnimatingHopper: Boolean? = null private var isAnimatingHopper: Boolean? = null
var hasMovedHopper = preferences.shownHopperSwipeTutorial().get() var hasMovedHopper = preferences.shownHopperSwipeTutorial().get()
private var elevationAnim: ValueAnimator? = null private lateinit var elevateAppBar: ((Boolean) -> Unit)
private var elevate = false
override fun getTitle(): String? { override fun getTitle(): String? {
return view?.context?.getString(R.string.library) return view?.context?.getString(R.string.library)
@ -188,8 +186,6 @@ class LibraryController(
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy) super.onScrolled(recyclerView, dx, dy)
val recyclerCover = recycler_cover ?: return val recyclerCover = recycler_cover ?: return
val notAtTop = recycler.canScrollVertically(-1)
if (notAtTop != elevate) elevateFunc(notAtTop)
val order = getCategoryOrder() val order = getCategoryOrder()
if (!recyclerCover.isClickable && isAnimatingHopper != true) { if (!recyclerCover.isClickable && isAnimatingHopper != true) {
category_hopper_frame.translationY += dy category_hopper_frame.translationY += dy
@ -372,6 +368,7 @@ class LibraryController(
} }
} }
elevateAppBar =
scrollViewWith(recycler, swipeRefreshLayout = swipe_refresh, afterInsets = { insets -> scrollViewWith(recycler, swipeRefreshLayout = swipe_refresh, afterInsets = { insets ->
category_layout?.updateLayoutParams<ViewGroup.MarginLayoutParams> { category_layout?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = recycler?.paddingTop ?: 0 topMargin = recycler?.paddingTop ?: 0
@ -379,6 +376,7 @@ class LibraryController(
fast_scroller?.updateLayoutParams<ViewGroup.MarginLayoutParams> { fast_scroller?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = recycler?.paddingTop ?: 0 topMargin = recycler?.paddingTop ?: 0
} }
header_title?.updatePaddingRelative(top = insets.systemWindowInsetTop + 2.dpToPx)
}) })
swipe_refresh.setOnRefreshListener { swipe_refresh.setOnRefreshListener {
@ -751,32 +749,20 @@ class LibraryController(
category_hopper_frame.animate().translationY(translateY).start() category_hopper_frame.animate().translationY(translateY).start()
recycler_cover.animate().translationY(translateY).start() recycler_cover.animate().translationY(translateY).start()
recycler_cover.animate().alpha(if (show) 0.75f else 0f).start() recycler_cover.animate().alpha(if (show) 0.75f else 0f).start()
recycler.suppressLayout(show)
activity?.toolbar?.showDropdown(!show)
if (show) { if (show) {
category_recycler.scrollToCategory(activeCategory) category_recycler.scrollToCategory(activeCategory)
fast_scroller?.hideScrollbar() fast_scroller?.hideScrollbar()
activity?.appbar?.y = 0f activity?.appbar?.y = 0f
elevateFunc(false) elevateAppBar(false)
activity?.dropdown?.setImageResource(R.drawable.ic_arrow_drop_up_24dp)
filter_bottom_sheet?.sheetBehavior?.hide() filter_bottom_sheet?.sheetBehavior?.hide()
} else { } else {
val notAtTop = recycler.canScrollVertically(-1) val notAtTop = recycler.canScrollVertically(-1)
if (notAtTop != elevate) elevateFunc(notAtTop) elevateAppBar(notAtTop)
activity?.dropdown?.setImageResource(R.drawable.ic_arrow_drop_down_24dp)
} }
} }
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() { fun setActiveCategory() {
val currentCategory = presenter.categories.indexOfFirst { val currentCategory = presenter.categories.indexOfFirst {
if (presenter.showAllCategories) it.order == activeCategory else presenter.currentCategory == it.id if (presenter.showAllCategories) it.order == activeCategory else presenter.currentCategory == it.id

View File

@ -62,7 +62,7 @@ fun Controller.scrollViewWith(
swipeRefreshLayout: SwipeRefreshLayout? = null, swipeRefreshLayout: SwipeRefreshLayout? = null,
afterInsets: ((WindowInsets) -> Unit)? = null, afterInsets: ((WindowInsets) -> Unit)? = null,
liftOnScroll: ((Boolean) -> Unit)? = null liftOnScroll: ((Boolean) -> Unit)? = null
) { ): ((Boolean) -> Unit) {
var statusBarHeight = -1 var statusBarHeight = -1
activity?.appbar?.y = 0f activity?.appbar?.y = 0f
val attrsArray = intArrayOf(R.attr.actionBarSize) val attrsArray = intArrayOf(R.attr.actionBarSize)
@ -98,7 +98,7 @@ fun Controller.scrollViewWith(
elevate = el elevate = el
if (liftOnScroll != null) { if (liftOnScroll != null) {
liftOnScroll.invoke(el) liftOnScroll.invoke(el)
} else if (recycler.translationY == 0f) { } else {
elevationAnim?.cancel() elevationAnim?.cancel()
elevationAnim = ValueAnimator.ofFloat( elevationAnim = ValueAnimator.ofFloat(
activity?.appbar?.elevation ?: 0f, if (el) 15f else 0f activity?.appbar?.elevation ?: 0f, if (el) 15f else 0f
@ -173,8 +173,8 @@ fun Controller.scrollViewWith(
activity!!.appbar.y = MathUtils.clamp( activity!!.appbar.y = MathUtils.clamp(
activity!!.appbar.y, -activity!!.appbar.height.toFloat(), 0f activity!!.appbar.y, -activity!!.appbar.height.toFloat(), 0f
) )
if ((activity!!.appbar.y <= -activity!!.appbar.height.toFloat() || if (((activity!!.appbar.y <= -activity!!.appbar.height.toFloat() ||
dy == 0 && activity!!.appbar.y == 0f) && !elevate) dy == 0 && activity!!.appbar.y == 0f) || dy == 0) && !elevate)
elevateFunc(true) elevateFunc(true)
lastY = activity!!.appbar.y lastY = activity!!.appbar.y
} }
@ -203,6 +203,7 @@ fun Controller.scrollViewWith(
} }
} }
}) })
return elevateFunc
} }
fun Controller.requestPermissionsSafe(permissions: Array<String>, requestCode: Int) { fun Controller.requestPermissionsSafe(permissions: Array<String>, requestCode: Int) {