Fix manga title disappearing in toolbar when pushing another controller

(cherry picked from commit 12ff37d052ccb27b04c84c506c6cb9643fe18f8e)
This commit is contained in:
arkon 2020-08-02 17:46:15 -04:00 committed by Jobobby04
parent 4c20ba38cb
commit 01137bf476

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
@ -137,7 +140,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 mangaInfoItemAdapter: MangaInfoItemAdapter? = null private var mangaInfoItemAdapter: MangaInfoItemAdapter? = null
@ -183,6 +185,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) {
@ -252,7 +267,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)
} }
} }
@ -291,18 +305,14 @@ class MangaController :
else -> min(binding.recycler.computeVerticalScrollOffset(), 255) else -> min(binding.recycler.computeVerticalScrollOffset(), 255)
} }
if (calculatedAlpha != toolbarTextAlpha) { activity?.toolbar?.setTitleTextColor(
toolbarTextAlpha = calculatedAlpha Color.argb(
calculatedAlpha,
activity?.toolbar?.setTitleTextColor( toolbarTextColor.red,
Color.argb( toolbarTextColor.green,
toolbarTextAlpha, toolbarTextColor.blue
Color.red(toolbarTextColor),
Color.green(toolbarTextColor),
Color.blue(toolbarTextColor)
)
) )
} )
} }
private fun updateFilterIconState() { private fun updateFilterIconState() {