mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 20:31:02 -05:00
Fix toolbar title alpha (#5910)
This commit is contained in:
parent
d45fefd6f0
commit
cfd1b4a6c6
1 changed files with 38 additions and 34 deletions
|
@ -92,10 +92,8 @@ 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.scrollStateChanges
|
import reactivecircus.flowbinding.recyclerview.scrollStateChanges
|
||||||
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
@ -181,6 +179,16 @@ class MangaController :
|
||||||
|
|
||||||
private var dialog: MangaFullCoverDialog? = null
|
private var dialog: MangaFullCoverDialog? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For [recyclerViewUpdatesToolbarTitleAlpha]
|
||||||
|
*/
|
||||||
|
private var recyclerViewToolbarTitleAlphaUpdaterAdded = false
|
||||||
|
private val recyclerViewToolbarTitleAlphaUpdater = object : RecyclerView.OnScrollListener() {
|
||||||
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
|
updateToolbarTitleAlpha()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
}
|
}
|
||||||
|
@ -191,15 +199,12 @@ class MangaController :
|
||||||
|
|
||||||
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||||
super.onChangeStarted(handler, type)
|
super.onChangeStarted(handler, type)
|
||||||
|
|
||||||
// Hide toolbar title on enter
|
// Hide toolbar title on enter
|
||||||
if (type.isEnter) {
|
// No need to update alpha for cover dialog
|
||||||
updateToolbarTitleAlpha()
|
if (dialog == null) {
|
||||||
} else if (!type.isPush) {
|
updateToolbarTitleAlpha(if (type.isEnter) 0F else 1F)
|
||||||
// Cancel listeners early
|
|
||||||
viewScope.cancel()
|
|
||||||
updateToolbarTitleAlpha(1F)
|
|
||||||
}
|
}
|
||||||
|
recyclerViewUpdatesToolbarTitleAlpha(type.isEnter)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||||
|
@ -250,19 +255,15 @@ class MangaController :
|
||||||
binding.fullRecycler?.let {
|
binding.fullRecycler?.let {
|
||||||
it.adapter = ConcatAdapter(mangaInfoAdapter, chaptersHeaderAdapter, chaptersAdapter)
|
it.adapter = ConcatAdapter(mangaInfoAdapter, chaptersHeaderAdapter, chaptersAdapter)
|
||||||
|
|
||||||
it.scrollEvents()
|
|
||||||
.onEach { updateToolbarTitleAlpha() }
|
|
||||||
.launchIn(viewScope)
|
|
||||||
|
|
||||||
// Skips directly to chapters list if navigated to from the library
|
// Skips directly to chapters list if navigated to from the library
|
||||||
it.post {
|
it.post {
|
||||||
if (!fromSource && preferences.jumpToChapters()) {
|
if (!fromSource && preferences.jumpToChapters()) {
|
||||||
(it.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(1, 0)
|
val mainActivityAppBar = (activity as? MainActivity)?.binding?.appbar
|
||||||
}
|
(it.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
|
||||||
|
1,
|
||||||
// Delayed in case we need to jump to chapters
|
mainActivityAppBar?.height ?: 0
|
||||||
it.post {
|
)
|
||||||
updateToolbarTitleAlpha()
|
mainActivityAppBar?.isLifted = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,22 +300,10 @@ class MangaController :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tablet layout
|
// Tablet layout
|
||||||
binding.infoRecycler?.let {
|
binding.infoRecycler?.adapter = mangaInfoAdapter
|
||||||
it.adapter = mangaInfoAdapter
|
binding.chaptersRecycler?.adapter = ConcatAdapter(chaptersHeaderAdapter, chaptersAdapter)
|
||||||
|
|
||||||
it.scrollEvents()
|
|
||||||
.onEach { updateToolbarTitleAlpha() }
|
|
||||||
.launchIn(viewScope)
|
|
||||||
|
|
||||||
// Delayed in case we need to jump to chapters
|
|
||||||
it.post {
|
|
||||||
updateToolbarTitleAlpha()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
binding.chaptersRecycler?.let {
|
|
||||||
it.adapter = ConcatAdapter(chaptersHeaderAdapter, chaptersAdapter)
|
|
||||||
}
|
|
||||||
|
|
||||||
chaptersAdapter?.fastScroller = binding.fastScroller
|
chaptersAdapter?.fastScroller = binding.fastScroller
|
||||||
|
|
||||||
|
@ -339,6 +328,20 @@ class MangaController :
|
||||||
trackSheet = TrackSheet(this, manga!!, (activity as MainActivity).supportFragmentManager)
|
trackSheet = TrackSheet(this, manga!!, (activity as MainActivity).supportFragmentManager)
|
||||||
|
|
||||||
updateFilterIconState()
|
updateFilterIconState()
|
||||||
|
recyclerViewUpdatesToolbarTitleAlpha(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun recyclerViewUpdatesToolbarTitleAlpha(enable: Boolean) {
|
||||||
|
val recycler = binding.fullRecycler ?: binding.infoRecycler ?: return
|
||||||
|
if (enable) {
|
||||||
|
if (!recyclerViewToolbarTitleAlphaUpdaterAdded) {
|
||||||
|
recycler.addOnScrollListener(recyclerViewToolbarTitleAlphaUpdater)
|
||||||
|
recyclerViewToolbarTitleAlphaUpdaterAdded = true
|
||||||
|
}
|
||||||
|
} else if (recyclerViewToolbarTitleAlphaUpdaterAdded) {
|
||||||
|
recycler.removeOnScrollListener(recyclerViewToolbarTitleAlphaUpdater)
|
||||||
|
recyclerViewToolbarTitleAlphaUpdaterAdded = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -399,6 +402,7 @@ class MangaController :
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView(view: View) {
|
override fun onDestroyView(view: View) {
|
||||||
|
recyclerViewUpdatesToolbarTitleAlpha(false)
|
||||||
destroyActionModeIfNeeded()
|
destroyActionModeIfNeeded()
|
||||||
binding.actionToolbar.destroy()
|
binding.actionToolbar.destroy()
|
||||||
mangaInfoAdapter = null
|
mangaInfoAdapter = null
|
||||||
|
|
Loading…
Reference in a new issue