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.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,14 +368,16 @@ class LibraryController(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollViewWith(recycler, swipeRefreshLayout = swipe_refresh, afterInsets = { insets ->
|
elevateAppBar =
|
||||||
category_layout?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
scrollViewWith(recycler, swipeRefreshLayout = swipe_refresh, afterInsets = { insets ->
|
||||||
topMargin = recycler?.paddingTop ?: 0
|
category_layout?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
}
|
topMargin = recycler?.paddingTop ?: 0
|
||||||
fast_scroller?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
}
|
||||||
topMargin = recycler?.paddingTop ?: 0
|
fast_scroller?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
}
|
topMargin = recycler?.paddingTop ?: 0
|
||||||
})
|
}
|
||||||
|
header_title?.updatePaddingRelative(top = insets.systemWindowInsetTop + 2.dpToPx)
|
||||||
|
})
|
||||||
|
|
||||||
swipe_refresh.setOnRefreshListener {
|
swipe_refresh.setOnRefreshListener {
|
||||||
swipe_refresh.isRefreshing = false
|
swipe_refresh.isRefreshing = false
|
||||||
|
@ -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
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Reference in a new issue