mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 18:01:49 +01:00
Adding elevation to appbar on scroll
I'd love to just do this with coordiator but alas...
This commit is contained in:
parent
e87f0c48ce
commit
d09d3e0bda
@ -145,6 +145,9 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
|
||||
.BottomSheetCallback() {
|
||||
override fun onSlide(bottomSheet: View, progress: Float) {
|
||||
shadow2.alpha = (1 - max(0f, progress)) * 0.25f
|
||||
activity?.appbar?.elevation = max(progress * 15f,
|
||||
if (recycler.canScrollVertically(-1)) 15f else 0f)
|
||||
|
||||
sheet_layout.alpha = 1 - progress
|
||||
activity?.appbar?.y = max(activity!!.appbar.y, -headerHeight * (1 - progress))
|
||||
val oldShow = showingExtenions
|
||||
|
@ -229,6 +229,7 @@ class MangaDetailsController : BaseController,
|
||||
var statusBarHeight = -1
|
||||
swipe_refresh.setStyle()
|
||||
swipe_refresh.setDistanceToTriggerSync(70.dpToPx)
|
||||
activity!!.appbar.elevation = 0f
|
||||
|
||||
recycler.doOnApplyWindowInsets { v, insets, _ ->
|
||||
headerHeight = appbarHeight + insets.systemWindowInsetTop
|
||||
|
@ -136,6 +136,9 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
||||
override fun onSlide(bottomSheet: View, progress: Float) {
|
||||
shadow2.alpha = (1 - abs(progress)) * 0.25f
|
||||
shadow.alpha = (1 - abs(progress)) * 0.5f
|
||||
if (progress >= 0) activity?.appbar?.elevation = max(
|
||||
progress * 15f, if (recycler.canScrollVertically(-1)) 15f else 0f
|
||||
)
|
||||
sheet_layout.alpha = 1 - progress
|
||||
activity?.appbar?.y = max(activity!!.appbar.y, -headerHeight * (1 - progress))
|
||||
val oldShow = showingDownloads
|
||||
|
@ -15,8 +15,7 @@ import com.bluelinelabs.conductor.ControllerChangeType
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.base.controller.BaseController
|
||||
import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener
|
||||
import eu.kanade.tachiyomi.util.view.applyWindowInsetsForController
|
||||
import eu.kanade.tachiyomi.util.view.scrollViewWith
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.subscriptions.CompositeSubscription
|
||||
@ -35,8 +34,7 @@ abstract class SettingsController : PreferenceController() {
|
||||
untilDestroySubscriptions = CompositeSubscription()
|
||||
}
|
||||
val view = super.onCreateView(inflater, container, savedInstanceState)
|
||||
view.applyWindowInsetsForController()
|
||||
listView.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener)
|
||||
scrollViewWith(listView, padBottom = true)
|
||||
return view
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
package eu.kanade.tachiyomi.util.view
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
@ -30,6 +31,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import com.bluelinelabs.conductor.Controller
|
||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||
import com.bluelinelabs.conductor.ControllerChangeType
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
@ -353,6 +356,31 @@ fun Controller.scrollViewWith(
|
||||
statusBarHeight = insets.systemWindowInsetTop
|
||||
afterInsets?.invoke(insets)
|
||||
}
|
||||
var elevationAnim: ValueAnimator? = null
|
||||
var elevate = false
|
||||
val elevateFunc: (Boolean) -> Unit = { el ->
|
||||
elevate = el
|
||||
elevationAnim?.cancel()
|
||||
elevationAnim = ValueAnimator.ofFloat(
|
||||
activity!!.appbar.elevation, if (el) 15f else 0f
|
||||
)
|
||||
elevationAnim?.addUpdateListener { valueAnimator ->
|
||||
activity!!.appbar.elevation = valueAnimator.animatedValue as Float
|
||||
}
|
||||
elevationAnim?.start()
|
||||
}
|
||||
addLifecycleListener(object : Controller.LifecycleListener() {
|
||||
override fun onChangeStart(
|
||||
controller: Controller,
|
||||
changeHandler: ControllerChangeHandler,
|
||||
changeType: ControllerChangeType
|
||||
) {
|
||||
super.onChangeStart(controller, changeHandler, changeType)
|
||||
if (changeType.isEnter)
|
||||
elevateFunc(elevate)
|
||||
}
|
||||
})
|
||||
elevateFunc(recycler.canScrollVertically(-1))
|
||||
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
@ -365,11 +393,15 @@ fun Controller.scrollViewWith(
|
||||
) ?: 0
|
||||
activity!!.appbar.animate().y(0f).setDuration(shortAnimationDuration.toLong())
|
||||
.start()
|
||||
if (elevate) elevateFunc(false)
|
||||
} else {
|
||||
activity!!.appbar.y -= dy
|
||||
activity!!.appbar.y = clamp(
|
||||
activity!!.appbar.y, -activity!!.appbar.height.toFloat(), 0f
|
||||
)
|
||||
if ((activity!!.appbar.y <= -activity!!.appbar.height.toFloat() ||
|
||||
dy == 0 && activity!!.appbar.y == 0f) && !elevate)
|
||||
elevateFunc(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -393,6 +425,10 @@ fun Controller.scrollViewWith(
|
||||
if (closerToTop && !atTop) (-activity!!.appbar.height.toFloat())
|
||||
else 0f
|
||||
).setDuration(shortAnimationDuration.toLong()).start()
|
||||
if (recycler.canScrollVertically(-1) && !elevate)
|
||||
elevateFunc(true)
|
||||
else if (!recycler.canScrollVertically(-1) && elevate)
|
||||
elevateFunc(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user