From 046efd50ddce50c4bb05c1579b005cf473d60d16 Mon Sep 17 00:00:00 2001 From: James Rich Date: Wed, 6 May 2026 13:26:26 -0500 Subject: [PATCH] refactor: replace string-based route with typed Enum in RadioConfigState MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change RadioConfigState.route from String to Enum<*>? - ChannelScreen resolves navigation target via typed cast instead of string lookup through getNavRouteFrom() - Delete dead SettingsNavUtils.kt (getNavRouteFrom now unused) - Eliminates fragile string→enum round-trip that could silently fail Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../settings/navigation/SettingsNavUtils.kt | 22 ------------------- .../settings/radio/RadioConfigViewModel.kt | 6 ++--- .../settings/radio/channel/ChannelScreen.kt | 8 ++++--- 3 files changed, 8 insertions(+), 28 deletions(-) delete mode 100644 feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/navigation/SettingsNavUtils.kt diff --git a/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/navigation/SettingsNavUtils.kt b/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/navigation/SettingsNavUtils.kt deleted file mode 100644 index 93e5763ef..000000000 --- a/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/navigation/SettingsNavUtils.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2026 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 . - */ -package org.meshtastic.feature.settings.navigation - -import org.meshtastic.core.navigation.Route - -fun getNavRouteFrom(routeName: String): Route? = - ConfigRoute.entries.find { it.name == routeName }?.route ?: ModuleRoute.entries.find { it.name == routeName }?.route diff --git a/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/radio/RadioConfigViewModel.kt b/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/radio/RadioConfigViewModel.kt index 348a895a9..0a76ba757 100644 --- a/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/radio/RadioConfigViewModel.kt +++ b/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/radio/RadioConfigViewModel.kt @@ -89,7 +89,7 @@ import org.meshtastic.core.model.ResponseState data class RadioConfigState( val isLocal: Boolean = false, val connected: Boolean = false, - val route: String = "", + val route: Enum<*>? = null, val metadata: DeviceMetadata? = null, val userConfig: User = User(), val channelList: List = emptyList(), @@ -385,7 +385,7 @@ open class RadioConfigViewModel( .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), ResponseState.Empty) override val pendingRouteName: StateFlow = - _radioConfigState.map { it.route } + _radioConfigState.map { it.route?.name.orEmpty() } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), "") override fun requestConfigLoad(routeName: String) { @@ -404,7 +404,7 @@ open class RadioConfigViewModel( fun setResponseStateLoading(route: Enum<*>) { val destNum = destNumFlow.value ?: destNode.value?.num ?: return - _radioConfigState.update { it.copy(route = route.name, responseState = ResponseState.Loading()) } + _radioConfigState.update { it.copy(route = route, responseState = ResponseState.Loading()) } loadJob?.cancel() loadJob = viewModelScope.launch { diff --git a/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/radio/channel/ChannelScreen.kt b/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/radio/channel/ChannelScreen.kt index b99de7248..243b80348 100644 --- a/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/radio/channel/ChannelScreen.kt +++ b/feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/radio/channel/ChannelScreen.kt @@ -93,7 +93,7 @@ import org.meshtastic.core.ui.util.rememberQrCodePainter import org.meshtastic.core.ui.util.rememberShowToastResource import org.meshtastic.feature.settings.channel.ChannelViewModel import org.meshtastic.feature.settings.navigation.ConfigRoute -import org.meshtastic.feature.settings.navigation.getNavRouteFrom +import org.meshtastic.feature.settings.navigation.ModuleRoute import org.meshtastic.feature.settings.radio.RadioConfigViewModel import org.meshtastic.core.ui.component.PacketResponseStateDialog import org.meshtastic.proto.ChannelSet @@ -140,10 +140,12 @@ fun ChannelScreen( radioConfigViewModel.clearPacketResponse() }, onComplete = { - getNavRouteFrom(radioConfigState.route)?.let { route -> + val navRoute = (radioConfigState.route as? ConfigRoute)?.route + ?: (radioConfigState.route as? ModuleRoute)?.route + if (navRoute != null) { isWaiting = false radioConfigViewModel.clearPacketResponse() - onNavigate(route) + onNavigate(navRoute) } }, )