mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-02-06 22:02:37 -05: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:
@@ -210,7 +210,7 @@ class MetricsViewModel @Inject constructor(
|
||||
private val firmwareReleaseRepository: FirmwareReleaseRepository,
|
||||
private val preferences: SharedPreferences,
|
||||
) : ViewModel(), Logging {
|
||||
private val destNum = savedStateHandle.toRoute<NodesRoutes.NodeDetail>().destNum
|
||||
private val destNum = savedStateHandle.toRoute<NodesRoutes.NodeDetailGraph>().destNum
|
||||
|
||||
private fun MeshLog.hasValidTraceroute(): Boolean = with(fromRadio.packet) {
|
||||
hasDecoded() && decoded.wantResponse && from == 0 && to == destNum
|
||||
|
||||
@@ -66,7 +66,7 @@ fun NavGraphBuilder.connectionsGraph(
|
||||
bluetoothViewModel = bluetoothViewModel,
|
||||
radioConfigViewModel = hiltViewModel(parentEntry),
|
||||
onNavigateToRadioConfig = { navController.navigate(RadioConfigRoutes.RadioConfig()) },
|
||||
onNavigateToNodeDetails = { navController.navigate(NodesRoutes.NodeDetail(it)) },
|
||||
onNavigateToNodeDetails = { navController.navigate(NodesRoutes.NodeDetailGraph(it)) },
|
||||
onConfigNavigate = { route -> navController.navigate(route) }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ fun NavGraphBuilder.contactsGraph(
|
||||
message = args.message,
|
||||
viewModel = uiViewModel,
|
||||
navigateToMessages = { navController.navigate(ContactsRoutes.Messages(it)) },
|
||||
navigateToNodeDetails = { navController.navigate(NodesRoutes.NodeDetail(it)) },
|
||||
navigateToNodeDetails = { navController.navigate(NodesRoutes.NodeDetailGraph(it)) },
|
||||
onNavigateBack = navController::navigateUp,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ fun NavGraphBuilder.mapGraph(
|
||||
MapView(
|
||||
model = uiViewModel,
|
||||
navigateToNodeDetails = {
|
||||
navController.navigate(NodesRoutes.NodeDetail(it))
|
||||
navController.navigate(NodesRoutes.NodeDetailGraph(it))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -55,7 +55,7 @@ sealed class NodesRoutes {
|
||||
data object NodesGraph : Graph
|
||||
|
||||
@Serializable
|
||||
data object NodeDetailGraph : Graph
|
||||
data class NodeDetailGraph(val destNum: Int? = null) : Graph
|
||||
|
||||
@Serializable
|
||||
data class NodeDetail(val destNum: Int? = null) : Route
|
||||
@@ -102,7 +102,7 @@ fun NavGraphBuilder.nodesGraph(
|
||||
navController.navigate(ContactsRoutes.Messages(it))
|
||||
},
|
||||
navigateToNodeDetails = {
|
||||
navController.navigate(NodesRoutes.NodeDetail(it))
|
||||
navController.navigate(NodesRoutes.NodeDetailGraph(it))
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -115,7 +115,7 @@ fun NavGraphBuilder.nodeDetailGraph(
|
||||
uiViewModel: UIViewModel,
|
||||
) {
|
||||
navigation<NodesRoutes.NodeDetailGraph>(
|
||||
startDestination = NodesRoutes.NodeDetail()
|
||||
startDestination = NodesRoutes.NodeDetail(),
|
||||
) {
|
||||
composable<NodesRoutes.NodeDetail> { backStackEntry ->
|
||||
val parentEntry = remember(backStackEntry) {
|
||||
|
||||
@@ -277,7 +277,7 @@ fun MainScreen(
|
||||
when (action) {
|
||||
is NodeMenuAction.MoreDetails -> {
|
||||
navController.navigate(
|
||||
NodesRoutes.NodeDetail(
|
||||
NodesRoutes.NodeDetailGraph(
|
||||
action.node.num
|
||||
),
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user