Refactor: Inject BluetoothViewModel into ConnectionsScreen (#2228)

This commit is contained in:
James Rich 2025-06-22 23:26:04 +00:00 committed by GitHub
parent 1d165a5dc3
commit ca3c787e71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 17 deletions

View file

@ -24,6 +24,7 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import androidx.navigation.navDeepLink
import androidx.navigation.navigation
import com.geeksville.mesh.model.BluetoothViewModel
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.ui.connections.ConnectionsScreen
import com.geeksville.mesh.ui.radioconfig.components.LoRaConfigScreen
@ -41,7 +42,11 @@ sealed class ConnectionsRoutes {
/**
* Navigation graph for for the top level ConnectionsScreen - [ConnectionsRoutes.Connections].
*/
fun NavGraphBuilder.connectionsGraph(navController: NavHostController, uiViewModel: UIViewModel) {
fun NavGraphBuilder.connectionsGraph(
navController: NavHostController,
uiViewModel: UIViewModel,
bluetoothViewModel: BluetoothViewModel
) {
navigation<ConnectionsRoutes.ConnectionsGraph>(
startDestination = ConnectionsRoutes.Connections,
) {
@ -57,7 +62,8 @@ fun NavGraphBuilder.connectionsGraph(navController: NavHostController, uiViewMod
navController.getBackStackEntry<ConnectionsRoutes.ConnectionsGraph>()
}
ConnectionsScreen(
uiViewModel,
uiViewModel = uiViewModel,
bluetoothViewModel = bluetoothViewModel,
radioConfigViewModel = hiltViewModel(parentEntry),
onNavigateToRadioConfig = { navController.navigate(RadioConfigRoutes.RadioConfig()) },
onNavigateToNodeDetails = { navController.navigate(NodesRoutes.NodeDetail(it)) },

View file

@ -28,6 +28,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.geeksville.mesh.R
import com.geeksville.mesh.model.BluetoothViewModel
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.ui.TopLevelDestination.Companion.isTopLevel
import com.geeksville.mesh.ui.debug.DebugScreen
@ -74,6 +75,7 @@ fun NavDestination.showLongNameTitle(): Boolean {
fun NavGraph(
modifier: Modifier = Modifier,
uIViewModel: UIViewModel = hiltViewModel(),
bluetoothViewModel: BluetoothViewModel = hiltViewModel(),
navController: NavHostController = rememberNavController(),
) {
NavHost(
@ -89,7 +91,7 @@ fun NavGraph(
nodesGraph(navController, uIViewModel,)
mapGraph(navController, uIViewModel)
channelsGraph(navController, uIViewModel)
connectionsGraph(navController, uIViewModel)
connectionsGraph(navController, uIViewModel, bluetoothViewModel)
composable<Route.DebugPanel> { DebugScreen() }
radioConfigGraph(navController, uIViewModel)
}