mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: encapsulate NodeDetail navigation
This commit is contained in:
parent
0d5157eb36
commit
e196bfb683
3 changed files with 126 additions and 48 deletions
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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.NavController
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.compose.composable
|
||||
import com.geeksville.mesh.model.MetricsViewModel
|
||||
import com.geeksville.mesh.ui.NodeDetailScreen
|
||||
import com.geeksville.mesh.ui.components.DeviceMetricsScreen
|
||||
import com.geeksville.mesh.ui.components.EnvironmentMetricsScreen
|
||||
import com.geeksville.mesh.ui.components.NodeMapScreen
|
||||
import com.geeksville.mesh.ui.components.PositionLogScreen
|
||||
import com.geeksville.mesh.ui.components.SignalMetricsScreen
|
||||
import com.geeksville.mesh.ui.components.TracerouteLogScreen
|
||||
|
||||
fun NavGraphBuilder.addNodDetailSection(navController: NavController) {
|
||||
composable<Route.NodeDetail> {
|
||||
NodeDetailScreen(
|
||||
onNavigate = navController::navigate,
|
||||
)
|
||||
}
|
||||
composable<Route.DeviceMetrics> {
|
||||
val parentEntry = remember { navController.getBackStackEntry<Route.NodeDetail>() }
|
||||
DeviceMetricsScreen(
|
||||
viewModel = hiltViewModel<MetricsViewModel>(parentEntry),
|
||||
)
|
||||
}
|
||||
composable<Route.NodeMap> {
|
||||
val parentEntry = remember { navController.getBackStackEntry<Route.NodeDetail>() }
|
||||
NodeMapScreen(
|
||||
viewModel = hiltViewModel<MetricsViewModel>(parentEntry),
|
||||
)
|
||||
}
|
||||
composable<Route.PositionLog> {
|
||||
val parentEntry = remember { navController.getBackStackEntry<Route.NodeDetail>() }
|
||||
PositionLogScreen(
|
||||
viewModel = hiltViewModel<MetricsViewModel>(parentEntry),
|
||||
)
|
||||
}
|
||||
composable<Route.EnvironmentMetrics> {
|
||||
val parentEntry = remember { navController.getBackStackEntry<Route.NodeDetail>() }
|
||||
EnvironmentMetricsScreen(
|
||||
viewModel = hiltViewModel<MetricsViewModel>(parentEntry),
|
||||
)
|
||||
}
|
||||
composable<Route.SignalMetrics> {
|
||||
val parentEntry = remember { navController.getBackStackEntry<Route.NodeDetail>() }
|
||||
SignalMetricsScreen(
|
||||
viewModel = hiltViewModel<MetricsViewModel>(parentEntry),
|
||||
)
|
||||
}
|
||||
composable<Route.TracerouteLog> {
|
||||
val parentEntry = remember { navController.getBackStackEntry<Route.NodeDetail>() }
|
||||
TracerouteLogScreen(
|
||||
viewModel = hiltViewModel<MetricsViewModel>(parentEntry),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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.navigation.NavController
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.toRoute
|
||||
import com.geeksville.mesh.ui.ShareScreen
|
||||
|
||||
fun NavController.navigateToSharedMessage(contactKey: String, message: String) {
|
||||
navigate(Route.Messages(contactKey, message)) {
|
||||
popUpTo<Route.Share> { inclusive = true }
|
||||
}
|
||||
}
|
||||
|
||||
fun NavGraphBuilder.shareScreen(
|
||||
navigateUp: () -> Unit,
|
||||
onConfirm: (String, String) -> Unit
|
||||
) {
|
||||
composable<Route.Share> { backStackEntry ->
|
||||
val message = backStackEntry.toRoute<Route.Share>().message
|
||||
ShareScreen(
|
||||
navigateUp = navigateUp,
|
||||
) { contactKey -> onConfirm(contactKey, message) }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue