mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-05-12 08:42:01 -04:00
refactor: replace string-based route with typed Enum in RadioConfigState
- 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>
This commit is contained in:
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
@@ -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<ChannelSettings> = emptyList(),
|
||||
@@ -385,7 +385,7 @@ open class RadioConfigViewModel(
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), ResponseState.Empty)
|
||||
|
||||
override val pendingRouteName: StateFlow<String> =
|
||||
_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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user