Fix toolbar title alpha (#5910)

(cherry picked from commit cfd1b4a6c6ae55118a985ec5cb1f7858cc3a3e87)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt
This commit is contained in:
Ivan Iskandar 2021-09-17 04:39:13 +07:00 committed by Jobobby04
parent 4ac2873a57
commit 6af5f085cf

View File

@ -225,6 +225,16 @@ class MangaController :
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()
}
}
// EXH -->
val smartSearchConfig: SourceController.SmartSearchConfig? = args.getParcelable(
SMART_SEARCH_CONFIG_EXTRA
@ -245,15 +255,12 @@ class MangaController :
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeStarted(handler, type)
// Hide toolbar title on enter
if (type.isEnter) {
updateToolbarTitleAlpha()
} else if (!type.isPush) {
// Cancel listeners early
viewScope.cancel()
updateToolbarTitleAlpha(1F)
// No need to update alpha for cover dialog
if (dialog == null) {
updateToolbarTitleAlpha(if (type.isEnter) 0F else 1F)
}
recyclerViewUpdatesToolbarTitleAlpha(type.isEnter)
}
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
@ -316,19 +323,15 @@ class MangaController :
)
)
it.scrollEvents()
.onEach { updateToolbarTitleAlpha() }
.launchIn(viewScope)
// Skips directly to chapters list if navigated to from the library
it.post {
if (!fromSource && preferences.jumpToChapters()) {
(it.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(1, 0)
}
// Delayed in case we need to jump to chapters
it.post {
updateToolbarTitleAlpha()
val mainActivityAppBar = (activity as? MainActivity)?.binding?.appbar
(it.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
1,
mainActivityAppBar?.height ?: 0
)
mainActivityAppBar?.isLifted = true
}
}
@ -365,27 +368,15 @@ class MangaController :
}
}
}
// Tablet layout
binding.infoRecycler?.let {
it.adapter = ConcatAdapter(
listOfNotNull(
mangaInfoAdapter,
mangaInfoButtonsAdapter
)
binding.infoRecycler?.adapter = ConcatAdapter(
listOfNotNull(
mangaInfoAdapter,
mangaInfoButtonsAdapter
)
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)
}
)
binding.chaptersRecycler?.adapter = ConcatAdapter(chaptersHeaderAdapter, chaptersAdapter)
chaptersAdapter?.fastScroller = binding.fastScroller
@ -418,6 +409,20 @@ class MangaController :
.launchIn(viewScope)
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) {
@ -478,6 +483,7 @@ class MangaController :
}
override fun onDestroyView(view: View) {
recyclerViewUpdatesToolbarTitleAlpha(false)
destroyActionModeIfNeeded()
binding.actionToolbar.destroy()
mangaInfoAdapter = null