mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 05:27:28 +01:00
MangaController: Title fixes (#5879)
* MangaController: Move toolbar's TextView reference to ElevationAppBarLayout * MangaController: Update title alpha earlier when exiting
This commit is contained in:
@@ -3,10 +3,19 @@ package eu.kanade.tachiyomi.widget
|
||||
import android.animation.ValueAnimator
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.FloatRange
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import androidx.lifecycle.findViewTreeLifecycleOwner
|
||||
import com.google.android.material.animation.AnimationUtils
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
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
|
||||
|
||||
class ElevationAppBarLayout @JvmOverloads constructor(
|
||||
context: Context,
|
||||
@@ -18,6 +27,19 @@ class ElevationAppBarLayout @JvmOverloads constructor(
|
||||
|
||||
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 elevationAnimator: ValueAnimator? = null
|
||||
private var backgroundAlphaAnimator: ValueAnimator? = null
|
||||
|
||||
@@ -63,6 +85,29 @@ class ElevationAppBarLayout @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateBackgroundAlpha() {
|
||||
val newTransparent = if (lifted) false else isTransparentWhenNotLifted
|
||||
if (transparent != newTransparent) {
|
||||
|
||||
Reference in New Issue
Block a user