mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 03:07:25 +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:
parent
b00e8768dc
commit
b45c322729
@ -14,13 +14,11 @@ import android.view.MenuInflater
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.annotation.FloatRange
|
import androidx.annotation.FloatRange
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.children
|
|
||||||
import androidx.core.view.doOnLayout
|
import androidx.core.view.doOnLayout
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
@ -94,6 +92,7 @@ import eu.kanade.tachiyomi.util.view.getCoordinates
|
|||||||
import eu.kanade.tachiyomi.util.view.shrinkOnScroll
|
import eu.kanade.tachiyomi.util.view.shrinkOnScroll
|
||||||
import eu.kanade.tachiyomi.util.view.snack
|
import eu.kanade.tachiyomi.util.view.snack
|
||||||
import eu.kanade.tachiyomi.widget.materialdialogs.QuadStateTextView
|
import eu.kanade.tachiyomi.widget.materialdialogs.QuadStateTextView
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import reactivecircus.flowbinding.recyclerview.scrollEvents
|
import reactivecircus.flowbinding.recyclerview.scrollEvents
|
||||||
@ -148,8 +147,6 @@ class MangaController :
|
|||||||
private val preferences: PreferencesHelper by injectLazy()
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
private val coverCache: CoverCache by injectLazy()
|
private val coverCache: CoverCache by injectLazy()
|
||||||
|
|
||||||
private var toolbarTextView: TextView? = null
|
|
||||||
|
|
||||||
private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null
|
private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null
|
||||||
private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null
|
private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null
|
||||||
private var chaptersAdapter: ChaptersAdapter? = null
|
private var chaptersAdapter: ChaptersAdapter? = null
|
||||||
@ -198,6 +195,10 @@ class MangaController :
|
|||||||
// Hide toolbar title on enter
|
// Hide toolbar title on enter
|
||||||
if (type.isEnter) {
|
if (type.isEnter) {
|
||||||
updateToolbarTitleAlpha()
|
updateToolbarTitleAlpha()
|
||||||
|
} else {
|
||||||
|
// Cancel listeners early
|
||||||
|
viewScope.cancel()
|
||||||
|
updateToolbarTitleAlpha(1F)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,11 +345,7 @@ class MangaController :
|
|||||||
|
|
||||||
private fun updateToolbarTitleAlpha(@FloatRange(from = 0.0, to = 1.0) alpha: Float? = null) {
|
private fun updateToolbarTitleAlpha(@FloatRange(from = 0.0, to = 1.0) alpha: Float? = null) {
|
||||||
val scrolledList = binding.fullRecycler ?: binding.infoRecycler!!
|
val scrolledList = binding.fullRecycler ?: binding.infoRecycler!!
|
||||||
if (toolbarTextView == null) {
|
(activity as? MainActivity)?.binding?.appbar?.titleTextAlpha = when {
|
||||||
toolbarTextView = (activity as? MainActivity)?.binding?.toolbar?.children
|
|
||||||
?.find { it is TextView } as? TextView
|
|
||||||
}
|
|
||||||
toolbarTextView?.alpha = when {
|
|
||||||
// Specific alpha provided
|
// Specific alpha provided
|
||||||
alpha != null -> alpha
|
alpha != null -> alpha
|
||||||
|
|
||||||
@ -412,8 +409,6 @@ class MangaController :
|
|||||||
chaptersAdapter = null
|
chaptersAdapter = null
|
||||||
settingsSheet = null
|
settingsSheet = null
|
||||||
addSnackbar?.dismiss()
|
addSnackbar?.dismiss()
|
||||||
updateToolbarTitleAlpha(1F)
|
|
||||||
toolbarTextView = null
|
|
||||||
super.onDestroyView(view)
|
super.onDestroyView(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,19 @@ package eu.kanade.tachiyomi.widget
|
|||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
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.animation.AnimationUtils
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import com.google.android.material.appbar.MaterialToolbar
|
import com.google.android.material.appbar.MaterialToolbar
|
||||||
import eu.kanade.tachiyomi.R
|
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(
|
class ElevationAppBarLayout @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
@ -18,6 +27,19 @@ class ElevationAppBarLayout @JvmOverloads constructor(
|
|||||||
|
|
||||||
private val toolbar by lazy { findViewById<MaterialToolbar>(R.id.toolbar) }
|
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 elevationAnimator: ValueAnimator? = null
|
||||||
private var backgroundAlphaAnimator: 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() {
|
private fun updateBackgroundAlpha() {
|
||||||
val newTransparent = if (lifted) false else isTransparentWhenNotLifted
|
val newTransparent = if (lifted) false else isTransparentWhenNotLifted
|
||||||
if (transparent != newTransparent) {
|
if (transparent != newTransparent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user