mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Refactor: Remove dispatcher and use conditional start destination (#2309)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
8b095aba09
commit
128aceb4b7
7 changed files with 14 additions and 30 deletions
|
|
@ -19,11 +19,8 @@ package com.geeksville.mesh.navigation
|
|||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigation.NavDestination
|
||||
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||
import androidx.navigation.NavHostController
|
||||
|
|
@ -50,9 +47,6 @@ const val DEEP_LINK_BASE_URI = "meshtastic://meshtastic"
|
|||
sealed interface Graph : Route
|
||||
@Serializable
|
||||
sealed interface Route {
|
||||
@Serializable
|
||||
data object Dispatcher : Route
|
||||
|
||||
@Serializable
|
||||
data object DebugPanel : Route
|
||||
}
|
||||
|
|
@ -86,25 +80,15 @@ fun NavGraph(
|
|||
) {
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = Route.Dispatcher,
|
||||
startDestination = if (uIViewModel.isConnected()) {
|
||||
NodesRoutes.NodesGraph
|
||||
} else {
|
||||
ConnectionsRoutes.ConnectionsGraph
|
||||
},
|
||||
modifier = modifier,
|
||||
) {
|
||||
composable<Route.Dispatcher> {
|
||||
val isConnected by uIViewModel.isConnected.collectAsStateWithLifecycle(false)
|
||||
LaunchedEffect(isConnected) {
|
||||
if (isConnected) {
|
||||
navController.navigate(NodesRoutes.NodesGraph) {
|
||||
popUpTo(Route.Dispatcher) { inclusive = true }
|
||||
}
|
||||
} else {
|
||||
navController.navigate(ConnectionsRoutes.ConnectionsGraph) {
|
||||
popUpTo(Route.Dispatcher) { inclusive = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
contactsGraph(navController, uIViewModel)
|
||||
nodesGraph(navController, uIViewModel)
|
||||
nodesGraph(navController, uIViewModel,)
|
||||
mapGraph(navController, uIViewModel)
|
||||
channelsGraph(navController, uIViewModel)
|
||||
connectionsGraph(navController, uIViewModel, bluetoothViewModel)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue