MainActivity: Fix incorrect UI states when activity recreated with dialog controller (#7325)

This commit is contained in:
Ivan Iskandar 2022-06-18 04:28:07 +07:00 committed by GitHub
parent 6aee4fc464
commit 3c3d787a2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -541,26 +541,39 @@ class MainActivity : BaseActivity() {
}
private fun syncActivityViewWithController(
to: Controller? = router.backstack.lastOrNull()?.controller,
to: Controller? = null,
from: Controller? = null,
isPush: Boolean = true,
) {
if (from is DialogController || to is DialogController) {
var internalTo = to
if (internalTo == null) {
// Should go here when the activity is recreated and dialog controller is on top of the backstack
// Then we'll assume the top controller is the parent controller of this dialog
val backstack = router.backstack
internalTo = backstack.lastOrNull()?.controller
if (internalTo is DialogController || internalTo is PreferenceDialogController) {
internalTo = backstack.getOrNull(backstack.size - 2)?.controller ?: return
}
} else {
// Ignore changes for normal transactions
if (from is DialogController || internalTo is DialogController) {
return
}
if (from is PreferenceDialogController || to is PreferenceDialogController) {
if (from is PreferenceDialogController || internalTo is PreferenceDialogController) {
return
}
}
supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1)
// Always show appbar again when changing controllers
binding.appbar.setExpanded(true)
if ((from == null || from is RootController) && to !is RootController) {
if ((from == null || from is RootController) && internalTo !is RootController) {
showNav(false)
}
if (to is RootController) {
if (internalTo is RootController) {
// Always show bottom nav again when returning to a RootController
showNav(true)
}
@ -568,8 +581,8 @@ class MainActivity : BaseActivity() {
if (from is TabbedController) {
from.cleanupTabs(binding.tabs)
}
if (to is TabbedController) {
if (to.configureTabs(binding.tabs)) {
if (internalTo is TabbedController) {
if (internalTo.configureTabs(binding.tabs)) {
binding.tabs.isVisible = true
}
} else {
@ -579,9 +592,9 @@ class MainActivity : BaseActivity() {
if (from is FabController) {
from.cleanupFab(binding.fabLayout.rootFab)
}
if (to is FabController) {
if (internalTo is FabController) {
binding.fabLayout.rootFab.show()
to.configureFab(binding.fabLayout.rootFab)
internalTo.configureFab(binding.fabLayout.rootFab)
} else {
binding.fabLayout.rootFab.hide()
}
@ -599,7 +612,7 @@ class MainActivity : BaseActivity() {
}
binding.appbar.isLifted = false
} else {
to?.let {
internalTo?.let {
binding.appbar.isLifted = backstackLiftState.getOrElse(it.instanceId) { false }
}
from?.let {
@ -607,10 +620,10 @@ class MainActivity : BaseActivity() {
}
}
binding.root.isLiftAppBarOnScroll = to !is NoAppBarElevationController
binding.root.isLiftAppBarOnScroll = internalTo !is NoAppBarElevationController
binding.appbar.isTransparentWhenNotLifted = to is MangaController
binding.controllerContainer.overlapHeader = to is MangaController
binding.appbar.isTransparentWhenNotLifted = internalTo is MangaController
binding.controllerContainer.overlapHeader = internalTo is MangaController
}
}