mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: Provide Navigation to Input Timezone (#2003)
This commit is contained in:
parent
43b6e54bbb
commit
e4313e0bd3
7 changed files with 153 additions and 56 deletions
|
|
@ -27,17 +27,27 @@ import com.geeksville.mesh.model.UIViewModel
|
|||
import com.geeksville.mesh.ui.sharing.ChannelScreen
|
||||
import com.geeksville.mesh.ui.radioconfig.components.ChannelConfigScreen
|
||||
import com.geeksville.mesh.ui.radioconfig.components.LoRaConfigScreen
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
sealed interface ChannelsRoutes {
|
||||
@Serializable
|
||||
data object ChannelsGraph : Graph
|
||||
|
||||
@Serializable
|
||||
data object Channels : Route
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigation graph for for the top level ChannelScreen - [Route.Channels].
|
||||
* Navigation graph for for the top level ChannelScreen - [ChannelsRoutes.Channels].
|
||||
*/
|
||||
fun NavGraphBuilder.channelsGraph(navController: NavHostController, uiViewModel: UIViewModel) {
|
||||
navigation<Graph.ChannelsGraph>(
|
||||
startDestination = Route.Channels,
|
||||
navigation<ChannelsRoutes.ChannelsGraph>(
|
||||
startDestination = ChannelsRoutes.Channels,
|
||||
) {
|
||||
composable<Route.Channels> { backStackEntry ->
|
||||
composable<ChannelsRoutes.Channels> { backStackEntry ->
|
||||
val parentEntry = remember(backStackEntry) {
|
||||
navController.getBackStackEntry<Graph.ChannelsGraph>()
|
||||
navController.getBackStackEntry<ChannelsRoutes.ChannelsGraph>()
|
||||
}
|
||||
ChannelScreen(
|
||||
viewModel = uiViewModel,
|
||||
|
|
@ -55,7 +65,7 @@ private fun NavGraphBuilder.configRoutes(
|
|||
ConfigRoute.entries.forEach { configRoute ->
|
||||
composable(configRoute.route::class) { backStackEntry ->
|
||||
val parentEntry = remember(backStackEntry) {
|
||||
navController.getBackStackEntry<Graph.ChannelsGraph>()
|
||||
navController.getBackStackEntry<ChannelsRoutes.ChannelsGraph>()
|
||||
}
|
||||
when (configRoute) {
|
||||
ConfigRoute.CHANNELS -> ChannelConfigScreen(hiltViewModel(parentEntry))
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.geeksville.mesh.navigation
|
||||
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navDeepLink
|
||||
import androidx.navigation.navigation
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.geeksville.mesh.ui.connections.ConnectionsScreen
|
||||
import com.geeksville.mesh.ui.radioconfig.components.LoRaConfigScreen
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
sealed interface ConnectionsRoutes {
|
||||
@Serializable
|
||||
data object ConnectionsGraph : Graph
|
||||
|
||||
@Serializable
|
||||
data object Connections : Route
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigation graph for for the top level ConnectionsScreen - [ConnectionsRoutes.Connections].
|
||||
*/
|
||||
fun NavGraphBuilder.connectionsGraph(navController: NavHostController, uiViewModel: UIViewModel) {
|
||||
navigation<ConnectionsRoutes.ConnectionsGraph>(
|
||||
startDestination = ConnectionsRoutes.Connections,
|
||||
) {
|
||||
composable<ConnectionsRoutes.Connections>(
|
||||
deepLinks = listOf(
|
||||
navDeepLink {
|
||||
uriPattern = "$DEEP_LINK_BASE_URI/connections"
|
||||
action = "android.intent.action.VIEW"
|
||||
}
|
||||
)
|
||||
) { backStackEntry ->
|
||||
val parentEntry = remember(backStackEntry) {
|
||||
navController.getBackStackEntry<ConnectionsRoutes.ConnectionsGraph>()
|
||||
}
|
||||
ConnectionsScreen(
|
||||
uiViewModel,
|
||||
radioConfigViewModel = hiltViewModel(parentEntry),
|
||||
onNavigateToRadioConfig = { navController.navigate(Route.RadioConfig()) },
|
||||
onNavigateToNodeDetails = { navController.navigate(Route.NodeDetail(it)) },
|
||||
onConfigNavigate = { route -> navController.navigate(route) }
|
||||
)
|
||||
}
|
||||
configRoutes(navController)
|
||||
}
|
||||
}
|
||||
|
||||
private fun NavGraphBuilder.configRoutes(
|
||||
navController: NavHostController,
|
||||
) {
|
||||
ConfigRoute.entries.forEach { configRoute ->
|
||||
composable(configRoute.route::class) { backStackEntry ->
|
||||
val parentEntry = remember(backStackEntry) {
|
||||
navController.getBackStackEntry<ConnectionsRoutes.ConnectionsGraph>()
|
||||
}
|
||||
when (configRoute) {
|
||||
ConfigRoute.LORA -> LoRaConfigScreen(hiltViewModel(parentEntry))
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,6 @@ import androidx.navigation.toRoute
|
|||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.geeksville.mesh.ui.TopLevelDestination.Companion.isTopLevel
|
||||
import com.geeksville.mesh.ui.connections.ConnectionsScreen
|
||||
import com.geeksville.mesh.ui.contact.ContactsScreen
|
||||
import com.geeksville.mesh.ui.debug.DebugScreen
|
||||
import com.geeksville.mesh.ui.map.MapView
|
||||
|
|
@ -53,9 +52,6 @@ const val DEEP_LINK_BASE_URI = "meshtastic://meshtastic"
|
|||
|
||||
@Serializable
|
||||
sealed interface Graph : Route {
|
||||
@Serializable
|
||||
data class ChannelsGraph(val destNum: Int?)
|
||||
|
||||
@Serializable
|
||||
data class NodeDetailGraph(val destNum: Int) : Graph
|
||||
|
||||
|
|
@ -74,12 +70,6 @@ sealed interface Route {
|
|||
@Serializable
|
||||
data object Map : Route
|
||||
|
||||
@Serializable
|
||||
data object Channels : Route
|
||||
|
||||
@Serializable
|
||||
data object Connections : Route
|
||||
|
||||
@Serializable
|
||||
data object DebugPanel : Route
|
||||
|
||||
|
|
@ -221,7 +211,7 @@ fun NavGraph(
|
|||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = if (uIViewModel.bondedAddress.isNullOrBlank()) {
|
||||
Route.Connections
|
||||
ConnectionsRoutes.ConnectionsGraph
|
||||
} else {
|
||||
Route.Contacts
|
||||
},
|
||||
|
|
@ -246,26 +236,8 @@ fun NavGraph(
|
|||
|
||||
channelsGraph(navController, uIViewModel)
|
||||
|
||||
composable<Route.Connections>(
|
||||
deepLinks = listOf(
|
||||
navDeepLink {
|
||||
uriPattern = "$DEEP_LINK_BASE_URI/connections"
|
||||
action = "android.intent.action.VIEW"
|
||||
}
|
||||
)
|
||||
) { backStackEntry ->
|
||||
ConnectionsScreen(
|
||||
uIViewModel,
|
||||
onNavigateToRadioConfig = {
|
||||
navController.navigate(Route.RadioConfig()) {
|
||||
popUpTo(Route.Connections) {
|
||||
inclusive = false
|
||||
}
|
||||
}
|
||||
},
|
||||
onNavigateToNodeDetails = { navController.navigate(Route.NodeDetail(it)) }
|
||||
)
|
||||
}
|
||||
connectionsGraph(navController, uIViewModel)
|
||||
|
||||
composable<Route.DebugPanel> {
|
||||
DebugScreen()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue