refactor: harden main shell state
This commit is contained in:
@@ -82,6 +82,10 @@ class MainViewModelImpl(
|
||||
private var openNotificationsSettings = false
|
||||
private var openAppSettings = false
|
||||
|
||||
init {
|
||||
listenLongPollState()
|
||||
}
|
||||
|
||||
override fun onError(error: BaseError) {
|
||||
when (error) {
|
||||
BaseError.SessionExpired,
|
||||
@@ -205,8 +209,6 @@ class MainViewModelImpl(
|
||||
|
||||
Log.d("MainViewModel", "currentAccount: $currentAccount")
|
||||
|
||||
listenLongPollState()
|
||||
|
||||
if (currentAccount != null) {
|
||||
UserConfig.apply {
|
||||
this.userId = currentAccount.userId
|
||||
|
||||
@@ -45,6 +45,7 @@ import dev.meloda.fast.friends.navigation.friendsScreen
|
||||
import dev.meloda.fast.model.BaseError
|
||||
import dev.meloda.fast.model.BottomNavigationItem
|
||||
import dev.meloda.fast.navigation.MainGraph
|
||||
import dev.meloda.fast.profile.navigation.Profile
|
||||
import dev.meloda.fast.profile.navigation.profileScreen
|
||||
import dev.meloda.fast.ui.theme.LocalBottomPadding
|
||||
import dev.meloda.fast.ui.theme.LocalHazeState
|
||||
@@ -69,15 +70,18 @@ fun MainScreen(
|
||||
val theme = LocalThemeConfig.current
|
||||
val hazeState = remember { HazeState(true) }
|
||||
val navController = rememberNavController()
|
||||
|
||||
var selectedItemIndex by rememberSaveable {
|
||||
mutableIntStateOf(1)
|
||||
val defaultTabIndex = remember(navigationItems) {
|
||||
navigationItems.indexOfFirst { it.route == ConvoGraph }.takeIf { it >= 0 } ?: 0
|
||||
}
|
||||
|
||||
BackHandler(enabled = selectedItemIndex != 1) {
|
||||
var selectedItemIndex by rememberSaveable {
|
||||
mutableIntStateOf(defaultTabIndex)
|
||||
}
|
||||
|
||||
BackHandler(enabled = selectedItemIndex != defaultTabIndex) {
|
||||
val currentRoute = navigationItems[selectedItemIndex].route
|
||||
|
||||
selectedItemIndex = 1
|
||||
selectedItemIndex = defaultTabIndex
|
||||
navController.navigate(navigationItems[selectedItemIndex].route) {
|
||||
popUpTo(route = currentRoute) {
|
||||
inclusive = true
|
||||
@@ -127,7 +131,7 @@ fun MainScreen(
|
||||
}
|
||||
},
|
||||
icon = {
|
||||
if (index == navigationItems.size - 1) {
|
||||
if (item.route == Profile) {
|
||||
var isLoading by remember {
|
||||
mutableStateOf(true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user