2024-11-26 08:38:12 -03:00
|
|
|
/*
|
2025-01-02 06:50:26 -03:00
|
|
|
* Copyright (c) 2025 Meshtastic LLC
|
2024-11-26 08:38:12 -03:00
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-01-11 09:08:34 -03:00
|
|
|
package com.geeksville.mesh.navigation
|
2021-02-13 21:35:57 -08:00
|
|
|
|
2025-05-15 08:05:30 -05:00
|
|
|
import androidx.annotation.StringRes
|
2023-04-17 17:13:26 -03:00
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.ui.Modifier
|
2025-05-15 08:05:30 -05:00
|
|
|
import androidx.hilt.navigation.compose.hiltViewModel
|
|
|
|
|
import androidx.navigation.NavDestination
|
|
|
|
|
import androidx.navigation.NavDestination.Companion.hasRoute
|
2023-09-11 21:37:53 -03:00
|
|
|
import androidx.navigation.NavHostController
|
2023-04-17 17:13:26 -03:00
|
|
|
import androidx.navigation.compose.NavHost
|
2025-05-15 08:05:30 -05:00
|
|
|
import androidx.navigation.compose.composable
|
2023-04-17 17:13:26 -03:00
|
|
|
import androidx.navigation.compose.rememberNavController
|
2023-03-02 21:59:22 -03:00
|
|
|
import com.geeksville.mesh.R
|
2025-06-22 23:26:04 +00:00
|
|
|
import com.geeksville.mesh.model.BluetoothViewModel
|
2025-05-15 08:05:30 -05:00
|
|
|
import com.geeksville.mesh.model.UIViewModel
|
|
|
|
|
import com.geeksville.mesh.ui.TopLevelDestination.Companion.isTopLevel
|
2025-05-29 18:18:45 -05:00
|
|
|
import com.geeksville.mesh.ui.debug.DebugScreen
|
2025-08-13 12:51:19 -05:00
|
|
|
import com.geeksville.mesh.ui.map.MapViewModel
|
2025-05-15 08:05:30 -05:00
|
|
|
import kotlinx.serialization.Serializable
|
|
|
|
|
|
|
|
|
|
enum class AdminRoute(@StringRes val title: Int) {
|
|
|
|
|
REBOOT(R.string.reboot),
|
|
|
|
|
SHUTDOWN(R.string.shutdown),
|
|
|
|
|
FACTORY_RESET(R.string.factory_reset),
|
|
|
|
|
NODEDB_RESET(R.string.nodedb_reset),
|
2024-06-23 08:24:29 -03:00
|
|
|
}
|
|
|
|
|
|
2025-05-15 08:05:30 -05:00
|
|
|
const val DEEP_LINK_BASE_URI = "meshtastic://meshtastic"
|
2024-04-15 17:56:47 -03:00
|
|
|
|
2025-08-12 17:19:40 -05:00
|
|
|
@Serializable sealed interface Graph : Route
|
|
|
|
|
|
2025-05-15 08:05:30 -05:00
|
|
|
@Serializable
|
|
|
|
|
sealed interface Route {
|
2025-08-12 17:19:40 -05:00
|
|
|
@Serializable data object DebugPanel : Route
|
2022-11-08 23:11:18 -03:00
|
|
|
}
|
2023-04-17 17:13:26 -03:00
|
|
|
|
2025-08-12 17:19:40 -05:00
|
|
|
fun NavDestination.isConfigRoute(): Boolean =
|
|
|
|
|
ConfigRoute.entries.any { hasRoute(it.route::class) } || ModuleRoute.entries.any { hasRoute(it.route::class) }
|
2025-05-15 08:05:30 -05:00
|
|
|
|
2025-08-12 17:19:40 -05:00
|
|
|
fun NavDestination.isNodeDetailRoute(): Boolean = NodeDetailRoute.entries.any { hasRoute(it.route::class) }
|
2025-05-15 08:05:30 -05:00
|
|
|
|
2025-08-12 17:19:40 -05:00
|
|
|
fun NavDestination.showLongNameTitle(): Boolean = !this.isTopLevel() &&
|
|
|
|
|
(
|
|
|
|
|
this.hasRoute<RadioConfigRoutes.RadioConfig>() ||
|
|
|
|
|
this.hasRoute<NodesRoutes.NodeDetail>() ||
|
|
|
|
|
this.isConfigRoute() ||
|
|
|
|
|
this.isNodeDetailRoute()
|
|
|
|
|
)
|
2025-05-15 08:05:30 -05:00
|
|
|
|
|
|
|
|
@Suppress("LongMethod")
|
2023-04-17 17:13:26 -03:00
|
|
|
@Composable
|
2024-10-20 08:48:30 -03:00
|
|
|
fun NavGraph(
|
2024-10-16 18:18:12 -03:00
|
|
|
modifier: Modifier = Modifier,
|
2025-05-15 08:05:30 -05:00
|
|
|
uIViewModel: UIViewModel = hiltViewModel(),
|
2025-06-22 23:26:04 +00:00
|
|
|
bluetoothViewModel: BluetoothViewModel = hiltViewModel(),
|
2025-08-13 12:51:19 -05:00
|
|
|
mapViewModel: MapViewModel = hiltViewModel(),
|
2025-05-15 08:05:30 -05:00
|
|
|
navController: NavHostController = rememberNavController(),
|
2023-09-11 21:26:42 -03:00
|
|
|
) {
|
2025-08-20 18:43:14 -04:00
|
|
|
NavHost(navController = navController, startDestination = ConnectionsRoutes.ConnectionsGraph, modifier = modifier) {
|
2025-06-06 20:45:26 +00:00
|
|
|
contactsGraph(navController, uIViewModel)
|
2025-08-12 17:19:40 -05:00
|
|
|
nodesGraph(navController, uIViewModel)
|
2025-08-13 12:51:19 -05:00
|
|
|
mapGraph(navController, uIViewModel, mapViewModel)
|
2025-05-30 17:50:45 -07:00
|
|
|
channelsGraph(navController, uIViewModel)
|
2025-06-22 23:26:04 +00:00
|
|
|
connectionsGraph(navController, uIViewModel, bluetoothViewModel)
|
2025-06-06 20:45:26 +00:00
|
|
|
composable<Route.DebugPanel> { DebugScreen() }
|
2025-05-28 15:57:38 -05:00
|
|
|
radioConfigGraph(navController, uIViewModel)
|
2023-04-17 17:13:26 -03:00
|
|
|
}
|
|
|
|
|
}
|