fix: crash in charts, nav (#2290)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-06-28 22:32:44 +00:00 committed by GitHub
parent 4500ba0c0a
commit 9819a89b97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 9 deletions

View file

@ -117,8 +117,8 @@ data class EnvironmentMetricsState(
shouldPlot[Environment.IAQ.ordinal] = true
}
val min = minValues.minOf { it }
val max = maxValues.maxOf { it }
val min = if (minValues.isEmpty()) 0f else minValues.minOf { it }
val max = if (maxValues.isEmpty()) 0f else maxValues.maxOf { it }
val (minPressure, maxPressure) = Pair(
telemetries.minBy { it.environmentMetrics.barometricPressure },

View file

@ -19,8 +19,11 @@ 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
@ -47,6 +50,9 @@ 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
}
@ -80,15 +86,25 @@ fun NavGraph(
) {
NavHost(
navController = navController,
startDestination = if (uIViewModel.isConnected()) {
NodesRoutes.NodesGraph
} else {
ConnectionsRoutes.ConnectionsGraph
},
startDestination = Route.Dispatcher,
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)

View file

@ -473,7 +473,7 @@ private fun TopBarActions(
) {
val ourNode by viewModel.ourNodeInfo.collectAsStateWithLifecycle()
val isConnected by viewModel.isConnected.collectAsStateWithLifecycle(false)
AnimatedVisibility(ourNode != null) {
AnimatedVisibility(ourNode != null && currentDestination?.isTopLevel() == true) {
ourNode?.let {
NodeChip(
node = it,