mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
MainActivity: Fix incorrect UI states when activity recreated with dialog controller (#7325)
This commit is contained in:
parent
6aee4fc464
commit
3c3d787a2b
1 changed files with 29 additions and 16 deletions
|
@ -541,15 +541,28 @@ 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) {
|
||||
return
|
||||
}
|
||||
if (from is PreferenceDialogController || to is PreferenceDialogController) {
|
||||
return
|
||||
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 || internalTo is PreferenceDialogController) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1)
|
||||
|
@ -557,10 +570,10 @@ class MainActivity : BaseActivity() {
|
|||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue