mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Refactor navigation to use NodeDetail route and fix radio settings (#4960)
This commit is contained in:
parent
c75c9b34d6
commit
6a5115b897
7 changed files with 19 additions and 28 deletions
|
|
@ -18,7 +18,9 @@ package org.meshtastic.feature.settings.navigation
|
|||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigation3.runtime.EntryProviderScope
|
||||
import androidx.navigation3.runtime.NavBackStack
|
||||
|
|
@ -70,14 +72,14 @@ import kotlin.reflect.KClass
|
|||
@Composable
|
||||
fun getRadioConfigViewModel(backStack: NavBackStack<NavKey>): RadioConfigViewModel {
|
||||
val viewModel = koinViewModel<RadioConfigViewModel>()
|
||||
LaunchedEffect(backStack) {
|
||||
val destNum =
|
||||
val destNum =
|
||||
remember(backStack.toList()) {
|
||||
backStack.lastOrNull { it is SettingsRoutes.Settings }?.let { (it as SettingsRoutes.Settings).destNum }
|
||||
?: backStack
|
||||
.lastOrNull { it is SettingsRoutes.SettingsGraph }
|
||||
?.let { (it as SettingsRoutes.SettingsGraph).destNum }
|
||||
viewModel.initDestNum(destNum)
|
||||
}
|
||||
}
|
||||
SideEffect { viewModel.initDestNum(destNum) }
|
||||
return viewModel
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +89,7 @@ fun EntryProviderScope<NavKey>.settingsGraph(backStack: NavBackStack<NavKey>) {
|
|||
SettingsMainScreen(
|
||||
settingsViewModel = koinViewModel(),
|
||||
radioConfigViewModel = getRadioConfigViewModel(backStack),
|
||||
onClickNodeChip = { backStack.add(NodesRoutes.NodeDetailGraph(it)) },
|
||||
onClickNodeChip = { backStack.add(NodesRoutes.NodeDetail(it)) },
|
||||
onNavigate = { backStack.add(it) },
|
||||
)
|
||||
}
|
||||
|
|
@ -96,7 +98,7 @@ fun EntryProviderScope<NavKey>.settingsGraph(backStack: NavBackStack<NavKey>) {
|
|||
SettingsMainScreen(
|
||||
settingsViewModel = koinViewModel(),
|
||||
radioConfigViewModel = getRadioConfigViewModel(backStack),
|
||||
onClickNodeChip = { backStack.add(NodesRoutes.NodeDetailGraph(it)) },
|
||||
onClickNodeChip = { backStack.add(NodesRoutes.NodeDetail(it)) },
|
||||
onNavigate = { backStack.add(it) },
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -433,7 +433,7 @@ open class RadioConfigViewModel(
|
|||
}
|
||||
|
||||
fun setResponseStateLoading(route: Enum<*>) {
|
||||
val destNum = destNode.value?.num ?: return
|
||||
val destNum = destNumFlow.value ?: destNode.value?.num ?: return
|
||||
|
||||
_radioConfigState.update { it.copy(route = route.name, responseState = ResponseState.Loading()) }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue