mirror of
https://github.com/mihonapp/mihon.git
synced 2025-07-16 04:33:18 +02:00
Workaround cleanup (#6350)
* Remove material-components workaround that was fixed upstream * Remove unused toolbar workaround * Fix cover dialog navigation icon
This commit is contained in:
@ -1,93 +0,0 @@
|
||||
package com.google.android.material.appbar
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import android.view.View
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.marginTop
|
||||
import eu.kanade.tachiyomi.util.system.animatorDurationScale
|
||||
import eu.kanade.tachiyomi.util.view.findChild
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
/**
|
||||
* Hide toolbar on scroll behavior for [AppBarLayout].
|
||||
*
|
||||
* Inside this package to access some package-private methods.
|
||||
*/
|
||||
class HideToolbarOnScrollBehavior : AppBarLayout.Behavior() {
|
||||
|
||||
@ViewCompat.NestedScrollType
|
||||
private var lastStartedType: Int = 0
|
||||
|
||||
private var offsetAnimator: ValueAnimator? = null
|
||||
|
||||
private var toolbarHeight: Int = 0
|
||||
|
||||
override fun onStartNestedScroll(
|
||||
parent: CoordinatorLayout,
|
||||
child: AppBarLayout,
|
||||
directTargetChild: View,
|
||||
target: View,
|
||||
nestedScrollAxes: Int,
|
||||
type: Int
|
||||
): Boolean {
|
||||
lastStartedType = type
|
||||
offsetAnimator?.cancel()
|
||||
return super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes, type)
|
||||
}
|
||||
|
||||
override fun onStopNestedScroll(
|
||||
parent: CoordinatorLayout,
|
||||
layout: AppBarLayout,
|
||||
target: View,
|
||||
type: Int
|
||||
) {
|
||||
super.onStopNestedScroll(parent, layout, target, type)
|
||||
if (toolbarHeight == 0) {
|
||||
toolbarHeight = layout.findChild<Toolbar>()?.height ?: 0
|
||||
}
|
||||
if (lastStartedType == ViewCompat.TYPE_TOUCH || type == ViewCompat.TYPE_NON_TOUCH) {
|
||||
animateToolbarVisibility(
|
||||
parent,
|
||||
layout,
|
||||
getTopBottomOffsetForScrollingSibling(layout) > -toolbarHeight / 2
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFlingFinished(parent: CoordinatorLayout, layout: AppBarLayout) {
|
||||
super.onFlingFinished(parent, layout)
|
||||
animateToolbarVisibility(
|
||||
parent,
|
||||
layout,
|
||||
getTopBottomOffsetForScrollingSibling(layout) > -toolbarHeight / 2
|
||||
)
|
||||
}
|
||||
|
||||
private fun getTopBottomOffsetForScrollingSibling(abl: AppBarLayout): Int {
|
||||
return topBottomOffsetForScrollingSibling - abl.marginTop
|
||||
}
|
||||
|
||||
private fun animateToolbarVisibility(
|
||||
coordinatorLayout: CoordinatorLayout,
|
||||
child: AppBarLayout,
|
||||
isVisible: Boolean
|
||||
) {
|
||||
val current = getTopBottomOffsetForScrollingSibling(child)
|
||||
val target = if (isVisible) 0 else -toolbarHeight
|
||||
if (current == target) return
|
||||
|
||||
offsetAnimator?.cancel()
|
||||
offsetAnimator = ValueAnimator().apply {
|
||||
interpolator = DecelerateInterpolator()
|
||||
duration = (150 * child.context.animatorDurationScale).roundToLong()
|
||||
addUpdateListener {
|
||||
setHeaderTopBottomOffset(coordinatorLayout, child, it.animatedValue as Int)
|
||||
}
|
||||
setIntValues(current, target)
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
@ -7,12 +7,10 @@ import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.FloatRange
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import androidx.lifecycle.findViewTreeLifecycleOwner
|
||||
import com.google.android.material.animation.AnimationUtils
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import com.google.android.material.shape.getStateAlpha
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.view.findChild
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@ -53,7 +51,7 @@ class TachiyomiAppBarLayout @JvmOverloads constructor(
|
||||
private val offsetListener = OnOffsetChangedListener { appBarLayout, verticalOffset ->
|
||||
// Show status bar foreground when offset
|
||||
val foreground = (appBarLayout?.statusBarForeground as? MaterialShapeDrawable) ?: return@OnOffsetChangedListener
|
||||
val start = foreground.getStateAlpha()
|
||||
val start = foreground.alpha
|
||||
val end = if (verticalOffset != 0) 255 else 0
|
||||
|
||||
statusBarForegroundAnimator?.cancel()
|
||||
@ -81,8 +79,6 @@ class TachiyomiAppBarLayout @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getBehavior(): CoordinatorLayout.Behavior<AppBarLayout> = HideToolbarOnScrollBehavior()
|
||||
|
||||
/**
|
||||
* Disabled. Lift on scroll is handled manually with [eu.kanade.tachiyomi.widget.TachiyomiCoordinatorLayout]
|
||||
*/
|
||||
@ -154,7 +150,7 @@ class TachiyomiAppBarLayout @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
val transparent = if (lifted) false else isTransparentWhenNotLifted
|
||||
val fromAlpha = (background as? MaterialShapeDrawable)?.getStateAlpha() ?: background.alpha
|
||||
val fromAlpha = (background as? MaterialShapeDrawable)?.alpha ?: background.alpha
|
||||
val toAlpha = if (transparent) 0 else 255
|
||||
if (fromAlpha != toAlpha) {
|
||||
ValueAnimator.ofInt(fromAlpha, toAlpha).apply {
|
||||
|
@ -1,10 +0,0 @@
|
||||
package com.google.android.material.shape
|
||||
|
||||
/**
|
||||
* Use this instead of [MaterialShapeDrawable.getAlpha].
|
||||
*
|
||||
* https://github.com/material-components/material-components-android/issues/1796
|
||||
*/
|
||||
fun MaterialShapeDrawable.getStateAlpha(): Int {
|
||||
return (constantState as? MaterialShapeDrawable.MaterialShapeDrawableState)?.alpha ?: alpha
|
||||
}
|
@ -157,7 +157,7 @@ class WebViewActivity : BaseViewBindingActivity<WebviewActivityBinding>() {
|
||||
backItem?.isEnabled = binding.webview.canGoBack()
|
||||
forwardItem?.isEnabled = binding.webview.canGoForward()
|
||||
|
||||
val iconTintColor = getResourceColor(R.attr.colorOnToolbar)
|
||||
val iconTintColor = getResourceColor(R.attr.colorOnSurface)
|
||||
val translucentIconTintColor = ColorUtils.setAlphaComponent(iconTintColor, 127)
|
||||
backItem?.icon?.setTint(if (binding.webview.canGoBack()) iconTintColor else translucentIconTintColor)
|
||||
forwardItem?.icon?.setTint(if (binding.webview.canGoForward()) iconTintColor else translucentIconTintColor)
|
||||
|
Reference in New Issue
Block a user