mirror of
https://github.com/mihonapp/mihon.git
synced 2024-10-31 21:20:59 -04:00
43 lines
1.3 KiB
Kotlin
43 lines
1.3 KiB
Kotlin
package eu.kanade.tachiyomi.widget
|
|
|
|
import android.animation.ObjectAnimator
|
|
import android.animation.StateListAnimator
|
|
import android.content.Context
|
|
import android.util.AttributeSet
|
|
import com.google.android.material.R
|
|
import com.google.android.material.appbar.AppBarLayout
|
|
|
|
class ElevationAppBarLayout @JvmOverloads constructor(
|
|
context: Context,
|
|
attrs: AttributeSet? = null
|
|
) : AppBarLayout(context, attrs) {
|
|
|
|
private var origStateAnimator: StateListAnimator? = null
|
|
|
|
init {
|
|
origStateAnimator = stateListAnimator
|
|
}
|
|
|
|
fun enableElevation(liftOnScroll: Boolean) {
|
|
stateListAnimator = origStateAnimator
|
|
isLiftOnScroll = liftOnScroll
|
|
}
|
|
|
|
fun disableElevation() {
|
|
stateListAnimator = StateListAnimator().apply {
|
|
val objAnimator = ObjectAnimator.ofFloat(this, "elevation", 0f)
|
|
|
|
// Enabled and collapsible, but not collapsed means not elevated
|
|
addState(
|
|
intArrayOf(android.R.attr.enabled, R.attr.state_collapsible, -R.attr.state_collapsed),
|
|
objAnimator
|
|
)
|
|
|
|
// Default enabled state
|
|
addState(intArrayOf(android.R.attr.enabled), objAnimator)
|
|
|
|
// Disabled state
|
|
addState(IntArray(0), objAnimator)
|
|
}
|
|
}
|
|
}
|