Fix manga title disappearing in toolbar when pushing another controller

This commit is contained in:
arkon 2020-08-02 17:46:15 -04:00
parent 4857073f30
commit 12ff37d052

View file

@ -14,6 +14,9 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode import androidx.appcompat.view.ActionMode
import androidx.core.graphics.blue
import androidx.core.graphics.green
import androidx.core.graphics.red
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.ConcatAdapter import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -122,7 +125,6 @@ class MangaController :
private val coverCache: CoverCache by injectLazy() private val coverCache: CoverCache by injectLazy()
private val toolbarTextColor by lazy { view!!.context.getResourceColor(R.attr.colorOnPrimary) } private val toolbarTextColor by lazy { view!!.context.getResourceColor(R.attr.colorOnPrimary) }
private var toolbarTextAlpha = 255
private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null
private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null
@ -157,6 +159,19 @@ class MangaController :
setHasOptionsMenu(true) setHasOptionsMenu(true)
} }
override fun getTitle(): String? {
return manga?.title
}
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeStarted(handler, type)
// Hide toolbar title on enter
if (type.isEnter) {
updateToolbarTitleAlpha()
}
}
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) { override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeEnded(handler, type) super.onChangeEnded(handler, type)
if (manga == null || source == null) { if (manga == null || source == null) {
@ -204,7 +219,6 @@ class MangaController :
// Delayed in case we need to jump to chapters // Delayed in case we need to jump to chapters
binding.recycler.post { binding.recycler.post {
updateToolbarTitleAlpha() updateToolbarTitleAlpha()
setTitle(manga?.title)
} }
} }
@ -243,19 +257,15 @@ class MangaController :
else -> min(binding.recycler.computeVerticalScrollOffset(), 255) else -> min(binding.recycler.computeVerticalScrollOffset(), 255)
} }
if (calculatedAlpha != toolbarTextAlpha) {
toolbarTextAlpha = calculatedAlpha
activity?.toolbar?.setTitleTextColor( activity?.toolbar?.setTitleTextColor(
Color.argb( Color.argb(
toolbarTextAlpha, calculatedAlpha,
Color.red(toolbarTextColor), toolbarTextColor.red,
Color.green(toolbarTextColor), toolbarTextColor.green,
Color.blue(toolbarTextColor) toolbarTextColor.blue
) )
) )
} }
}
private fun updateFilterIconState() { private fun updateFilterIconState() {
chaptersHeaderAdapter?.setHasActiveFilters(settingsSheet?.filters?.hasActiveFilters() == true) chaptersHeaderAdapter?.setHasActiveFilters(settingsSheet?.filters?.hasActiveFilters() == true)