From a4148c952d74222ad9b17a50ce0dc4361a7de447 Mon Sep 17 00:00:00 2001 From: Phil Oliver <3497406+poliver@users.noreply.github.com> Date: Tue, 16 Dec 2025 17:09:49 -0500 Subject: [PATCH] Restructure node filters (#4020) --- .../feature/node/list/NodeListViewModel.kt | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/feature/node/src/main/kotlin/org/meshtastic/feature/node/list/NodeListViewModel.kt b/feature/node/src/main/kotlin/org/meshtastic/feature/node/list/NodeListViewModel.kt index d7701fa7a..430bb5c90 100644 --- a/feature/node/src/main/kotlin/org/meshtastic/feature/node/list/NodeListViewModel.kt +++ b/feature/node/src/main/kotlin/org/meshtastic/feature/node/list/NodeListViewModel.kt @@ -39,6 +39,7 @@ import org.meshtastic.feature.node.model.isEffectivelyUnmessageable import org.meshtastic.proto.AdminProtos import org.meshtastic.proto.ConfigProtos import javax.inject.Inject +import kotlin.Boolean @HiltViewModel class NodeListViewModel @@ -66,21 +67,33 @@ constructor( private val nodeSortOption = nodeFilterPreferences.nodeSortOption private val _nodeFilterText = savedStateHandle.getStateFlow(KEY_FILTER_TEXT, "") - private val includeUnknown = nodeFilterPreferences.includeUnknown - private val excludeInfrastructure = nodeFilterPreferences.excludeInfrastructure - private val onlyOnline = nodeFilterPreferences.onlyOnline - private val onlyDirect = nodeFilterPreferences.onlyDirect - private val showIgnored = nodeFilterPreferences.showIgnored + + private val filterToggles = + combine( + nodeFilterPreferences.includeUnknown, + nodeFilterPreferences.excludeInfrastructure, + nodeFilterPreferences.onlyOnline, + nodeFilterPreferences.onlyDirect, + nodeFilterPreferences.showIgnored, + ) { includeUnknown, excludeInfrastructure, onlyOnline, onlyDirect, showIgnored -> + NodeFilterToggles( + includeUnknown = includeUnknown, + excludeInfrastructure = excludeInfrastructure, + onlyOnline = onlyOnline, + onlyDirect = onlyDirect, + showIgnored = showIgnored, + ) + } private val nodeFilter: Flow = - combine(_nodeFilterText, includeUnknown, excludeInfrastructure, onlyOnline, onlyDirect, showIgnored) { values -> + combine(_nodeFilterText, filterToggles) { filterText, filterToggles -> NodeFilterState( - filterText = values[0] as String, - includeUnknown = values[1] as Boolean, - excludeInfrastructure = values[2] as Boolean, - onlyOnline = values[3] as Boolean, - onlyDirect = values[4] as Boolean, - showIgnored = values[5] as Boolean, + filterText = filterText, + includeUnknown = filterToggles.includeUnknown, + excludeInfrastructure = filterToggles.excludeInfrastructure, + onlyOnline = filterToggles.onlyOnline, + onlyDirect = filterToggles.onlyDirect, + showIgnored = filterToggles.showIgnored, ) } val nodesUiState: StateFlow = @@ -170,3 +183,11 @@ data class NodeFilterState( val onlyDirect: Boolean = false, val showIgnored: Boolean = false, ) + +data class NodeFilterToggles( + val includeUnknown: Boolean = false, + val excludeInfrastructure: Boolean = false, + val onlyOnline: Boolean = false, + val onlyDirect: Boolean = false, + val showIgnored: Boolean = false, +)