MangaController: Change the workaround for title alpha (#7277)

Now checks for the backstack for any dialog controller when a push exit occurs
before restoring the title alpha.
This commit is contained in:
Ivan Iskandar 2022-06-18 04:28:50 +07:00 committed by GitHub
parent 3c3d787a2b
commit ae88252cb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,7 +26,6 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import coil.imageLoader
import coil.request.ImageRequest
import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
@ -182,8 +181,6 @@ class MangaController :
private var trackSheet: TrackSheet? = null
private var dialog: DialogController? = null
/**
* For [recyclerViewUpdatesToolbarTitleAlpha]
*/
@ -206,8 +203,10 @@ class MangaController :
super.onChangeStarted(handler, type)
// Hide toolbar title on enter
// No need to update alpha for cover dialog
if (dialog == null) {
updateToolbarTitleAlpha(if (type.isEnter) 0F else 1F)
if (!type.isEnter) {
if (!type.isPush || router.backstack.lastOrNull()?.controller !is DialogController) {
updateToolbarTitleAlpha(1f)
}
}
recyclerViewUpdatesToolbarTitleAlpha(type.isEnter)
}
@ -623,17 +622,8 @@ class MangaController :
}
private fun showChangeCategoryDialog(manga: Manga, categories: List<Category>, preselected: Array<Int>) {
if (dialog != null) return
dialog = ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
dialog?.addLifecycleListener(
object : LifecycleListener() {
override fun postDestroy(controller: Controller) {
super.postDestroy(controller)
dialog = null
}
},
)
dialog?.showDialog(router)
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
.showDialog(router)
}
override fun updateCategoriesForMangas(mangas: List<Manga>, addCategories: List<Category>, removeCategories: List<Category>) {
@ -731,18 +721,9 @@ class MangaController :
}
fun showFullCoverDialog() {
if (dialog != null) return
val manga = manga ?: return
dialog = MangaFullCoverDialog(this, manga)
dialog?.addLifecycleListener(
object : LifecycleListener() {
override fun postDestroy(controller: Controller) {
super.postDestroy(controller)
dialog = null
}
},
)
dialog?.showDialog(router)
MangaFullCoverDialog(this, manga)
.showDialog(router)
}
fun shareCover() {
@ -838,7 +819,7 @@ class MangaController :
fun onSetCoverSuccess() {
mangaInfoAdapter?.notifyItemChanged(0, this)
(dialog as? MangaFullCoverDialog)?.setImage(manga)
(router.backstack.lastOrNull()?.controller as? MangaFullCoverDialog)?.setImage(manga)
activity?.toast(R.string.cover_updated)
}