mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-13 12:38:58 +01:00
Remove some dead code
This commit is contained in:
@@ -1,214 +0,0 @@
|
||||
@file:Suppress("PackageDirectoryMismatch")
|
||||
|
||||
package com.google.android.material.appbar
|
||||
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ValueAnimator
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.animation.LinearInterpolator
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.FloatRange
|
||||
import androidx.core.graphics.withTranslation
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import androidx.lifecycle.findViewTreeLifecycleOwner
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import dev.chrisbanes.insetter.applyInsetter
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.view.findChild
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.HierarchyChangeEvent
|
||||
import reactivecircus.flowbinding.android.view.hierarchyChangeEvents
|
||||
|
||||
/**
|
||||
* [AppBarLayout] with our own lift state handler and custom title alpha.
|
||||
*
|
||||
* Inside this package to access some package-private methods.
|
||||
*/
|
||||
class TachiyomiAppBarLayout @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
) : AppBarLayout(context, attrs) {
|
||||
|
||||
private var lifted = true
|
||||
|
||||
private val toolbar by lazy { findViewById<MaterialToolbar>(R.id.toolbar) }
|
||||
|
||||
@FloatRange(from = 0.0, to = 1.0)
|
||||
var titleTextAlpha = 1F
|
||||
set(value) {
|
||||
field = value
|
||||
titleTextView?.alpha = field
|
||||
}
|
||||
|
||||
private var titleTextView: TextView? = null
|
||||
set(value) {
|
||||
field = value
|
||||
field?.alpha = titleTextAlpha
|
||||
}
|
||||
|
||||
private var animatorSet: AnimatorSet? = null
|
||||
|
||||
private var statusBarForegroundAnimator: ValueAnimator? = null
|
||||
private var currentOffset = 0
|
||||
|
||||
var isTransparentWhenNotLifted = false
|
||||
set(value) {
|
||||
if (field != value) {
|
||||
field = value
|
||||
updateStates()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabled. Lift on scroll is handled manually with [eu.kanade.tachiyomi.widget.TachiyomiCoordinatorLayout]
|
||||
*/
|
||||
override fun isLiftOnScroll(): Boolean = false
|
||||
|
||||
override fun isLifted(): Boolean = lifted
|
||||
|
||||
override fun setLifted(lifted: Boolean): Boolean {
|
||||
return if (this.lifted != lifted) {
|
||||
this.lifted = lifted
|
||||
updateStates()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun setLiftedState(lifted: Boolean, force: Boolean): Boolean = false
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
super.draw(canvas)
|
||||
canvas.withTranslation(y = -currentOffset.toFloat()) {
|
||||
statusBarForeground?.draw(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
|
||||
super.onLayout(changed, l, t, r, b)
|
||||
statusBarForeground?.setBounds(0, 0, width, paddingTop)
|
||||
}
|
||||
|
||||
override fun onOffsetChanged(offset: Int) {
|
||||
currentOffset = offset
|
||||
super.onOffsetChanged(offset)
|
||||
|
||||
// Show status bar foreground when offset
|
||||
val foreground = (statusBarForeground as? MaterialShapeDrawable) ?: return
|
||||
val start = foreground.alpha
|
||||
val end = if (offset != 0) 255 else 0
|
||||
|
||||
statusBarForegroundAnimator?.cancel()
|
||||
if (animatorSet?.isRunning == true) {
|
||||
foreground.alpha = end
|
||||
return
|
||||
}
|
||||
if (start != end) {
|
||||
statusBarForegroundAnimator = ValueAnimator.ofInt(start, end).apply {
|
||||
duration = resources.getInteger(R.integer.app_bar_elevation_anim_duration).toLong()
|
||||
interpolator = LINEAR_INTERPOLATOR
|
||||
addUpdateListener {
|
||||
foreground.alpha = it.animatedValue as Int
|
||||
}
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
toolbar.background.alpha = 0 // Use app bar background
|
||||
|
||||
titleTextView = toolbar.findChild<TextView>()
|
||||
findViewTreeLifecycleOwner()?.lifecycle?.coroutineScope?.let { scope ->
|
||||
toolbar.hierarchyChangeEvents()
|
||||
.onEach {
|
||||
when (it) {
|
||||
is HierarchyChangeEvent.ChildAdded -> {
|
||||
if (it.child is TextView) {
|
||||
titleTextView = it.child as TextView
|
||||
}
|
||||
}
|
||||
is HierarchyChangeEvent.ChildRemoved -> {
|
||||
if (it.child == titleTextView) {
|
||||
titleTextView = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setStatusBarForeground(drawable: Drawable?) {
|
||||
super.setStatusBarForeground(drawable)
|
||||
setWillNotDraw(statusBarForeground == null)
|
||||
}
|
||||
|
||||
@SuppressLint("Recycle")
|
||||
private fun updateStates() {
|
||||
val animators = mutableListOf<ValueAnimator>()
|
||||
|
||||
val fromElevation = elevation
|
||||
val toElevation = if (lifted) {
|
||||
resources.getDimension(R.dimen.design_appbar_elevation)
|
||||
} else {
|
||||
0F
|
||||
}
|
||||
if (fromElevation != toElevation) {
|
||||
ValueAnimator.ofFloat(fromElevation, toElevation).apply {
|
||||
addUpdateListener {
|
||||
elevation = it.animatedValue as Float
|
||||
(statusBarForeground as? MaterialShapeDrawable)?.elevation = it.animatedValue as Float
|
||||
}
|
||||
animators.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
val transparent = if (lifted) false else isTransparentWhenNotLifted
|
||||
val fromAlpha = (background as? MaterialShapeDrawable)?.alpha ?: background.alpha
|
||||
val toAlpha = if (transparent) 0 else 255
|
||||
if (fromAlpha != toAlpha) {
|
||||
ValueAnimator.ofInt(fromAlpha, toAlpha).apply {
|
||||
addUpdateListener {
|
||||
val value = it.animatedValue as Int
|
||||
background.alpha = value
|
||||
}
|
||||
animators.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
if (animators.isNotEmpty()) {
|
||||
animatorSet?.cancel()
|
||||
animatorSet = AnimatorSet().apply {
|
||||
duration = resources.getInteger(R.integer.app_bar_elevation_anim_duration).toLong()
|
||||
interpolator = LINEAR_INTERPOLATOR
|
||||
playTogether(*animators.toTypedArray())
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
statusBarForeground = MaterialShapeDrawable.createWithElevationOverlay(context)
|
||||
applyInsetter {
|
||||
type(navigationBars = true) {
|
||||
margin(horizontal = true)
|
||||
}
|
||||
type(statusBars = true) {
|
||||
padding(top = true)
|
||||
}
|
||||
ignoreVisibility(true)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LINEAR_INTERPOLATOR = LinearInterpolator()
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.coordinatorlayout.R
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.doOnLayout
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.customview.view.AbsSavedState
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import eu.kanade.tachiyomi.util.system.isTabletUi
|
||||
import eu.kanade.tachiyomi.util.view.findChild
|
||||
|
||||
/**
|
||||
* [CoordinatorLayout] with its own app bar lift state handler.
|
||||
* This parent view checks for the app bar lift state from the following:
|
||||
*
|
||||
* 1. When nested scroll detected, lift state will be decided from the nested
|
||||
* scroll target. (See [onNestedScroll])
|
||||
*
|
||||
* With those conditions, this view expects the following direct child:
|
||||
*
|
||||
* 1. An [AppBarLayout].
|
||||
*/
|
||||
class TachiyomiCoordinatorLayout @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.coordinatorLayoutStyle,
|
||||
) : CoordinatorLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private var appBarLayout: AppBarLayout? = null
|
||||
private var tabLayout: TabLayout? = null
|
||||
|
||||
override fun onNestedScroll(
|
||||
target: View,
|
||||
dxConsumed: Int,
|
||||
dyConsumed: Int,
|
||||
dxUnconsumed: Int,
|
||||
dyUnconsumed: Int,
|
||||
type: Int,
|
||||
consumed: IntArray,
|
||||
) {
|
||||
super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed)
|
||||
// Disable elevation overlay when tabs are visible
|
||||
if (context.isTabletUi().not()) {
|
||||
if (target is ComposeView) {
|
||||
val scrollCondition = if (type == ViewCompat.TYPE_NON_TOUCH) {
|
||||
dyUnconsumed >= 0
|
||||
} else {
|
||||
dyConsumed != 0 || dyUnconsumed >= 0
|
||||
}
|
||||
appBarLayout?.isLifted = scrollCondition && tabLayout?.isVisible == false
|
||||
} else {
|
||||
appBarLayout?.isLifted = (dyConsumed != 0 || dyUnconsumed >= 0) && tabLayout?.isVisible == false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
appBarLayout = findChild()
|
||||
tabLayout = appBarLayout?.findChild()
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
appBarLayout = null
|
||||
tabLayout = null
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(): Parcelable? {
|
||||
val superState = super.onSaveInstanceState()
|
||||
return if (superState != null) {
|
||||
SavedState(superState).also {
|
||||
it.appBarLifted = appBarLayout?.isLifted ?: false
|
||||
}
|
||||
} else {
|
||||
superState
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(state: Parcelable?) {
|
||||
if (state is SavedState) {
|
||||
super.onRestoreInstanceState(state.superState)
|
||||
doOnLayout {
|
||||
appBarLayout?.isLifted = state.appBarLifted
|
||||
}
|
||||
} else {
|
||||
super.onRestoreInstanceState(state)
|
||||
}
|
||||
}
|
||||
|
||||
internal class SavedState : AbsSavedState {
|
||||
var appBarLifted = false
|
||||
|
||||
constructor(superState: Parcelable) : super(superState)
|
||||
|
||||
constructor(source: Parcel, loader: ClassLoader?) : super(source, loader) {
|
||||
appBarLifted = source.readByte().toInt() == 1
|
||||
}
|
||||
|
||||
override fun writeToParcel(out: Parcel, flags: Int) {
|
||||
super.writeToParcel(out, flags)
|
||||
out.writeByte((if (appBarLifted) 1 else 0).toByte())
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.ClassLoaderCreator<SavedState> = object : Parcelable.ClassLoaderCreator<SavedState> {
|
||||
override fun createFromParcel(source: Parcel, loader: ClassLoader): SavedState {
|
||||
return SavedState(source, loader)
|
||||
}
|
||||
|
||||
override fun createFromParcel(source: Parcel): SavedState {
|
||||
return SavedState(source, null)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<SavedState> {
|
||||
return newArray(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
|
||||
/**
|
||||
* [AppBarLayout.ScrollingViewBehavior] that lets the app bar overlaps the scrolling child.
|
||||
*/
|
||||
class TachiyomiScrollingViewBehavior : AppBarLayout.ScrollingViewBehavior() {
|
||||
|
||||
var shouldHeaderOverlap = false
|
||||
|
||||
override fun shouldHeaderOverlapScrollingChild(): Boolean {
|
||||
return shouldHeaderOverlap
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user