Feat/2412 ignored nodes (#2470)

Signed-off-by: DaneEvans <dane@goneepic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
DaneEvans 2025-07-21 22:45:03 +10:00 committed by GitHub
parent ee99d79574
commit 5a6a1cb44a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 124 additions and 40 deletions

View file

@ -160,6 +160,7 @@ data class NodesUiState(
val distanceUnits: Int = 0,
val tempInFahrenheit: Boolean = false,
val showDetails: Boolean = false,
val showIgnored: Boolean = false,
) {
companion object {
val Empty = NodesUiState()
@ -310,6 +311,12 @@ class UIViewModel @Inject constructor(
private val showPrecisionCircleOnMap =
MutableStateFlow(preferences.getBoolean("show-precision-circle-on-map", true))
private val showIgnored = MutableStateFlow(preferences.getBoolean("show-ignored", false))
fun toggleShowIgnored() {
showIgnored.value = !showIgnored.value
preferences.edit { putBoolean("show-ignored", showIgnored.value) }
}
fun setSortOption(sort: NodeSortOption) {
nodeSortOption.value = sort
preferences.edit { putInt("node-sort-option", sort.ordinal) }
@ -355,6 +362,7 @@ class UIViewModel @Inject constructor(
val includeUnknown: Boolean,
val onlyOnline: Boolean,
val onlyDirect: Boolean,
val showIgnored: Boolean,
)
val nodeFilterStateFlow: Flow<NodeFilterState> = combine(
@ -362,8 +370,9 @@ class UIViewModel @Inject constructor(
includeUnknown,
onlyOnline,
onlyDirect,
) { filterText, includeUnknown, onlyOnline, onlyDirect ->
NodeFilterState(filterText, includeUnknown, onlyOnline, onlyDirect)
showIgnored,
) { filterText, includeUnknown, onlyOnline, onlyDirect, showIgnored ->
NodeFilterState(filterText, includeUnknown, onlyOnline, onlyDirect, showIgnored)
}
val nodesUiState: StateFlow<NodesUiState> = combine(
@ -382,6 +391,7 @@ class UIViewModel @Inject constructor(
distanceUnits = profile.config.display.units.number,
tempInFahrenheit = profile.moduleConfig.telemetry.environmentDisplayFahrenheit,
showDetails = showDetails,
showIgnored = filterFlow.showIgnored,
)
}.stateIn(
scope = viewModelScope,
@ -397,6 +407,9 @@ class UIViewModel @Inject constructor(
val nodeList: StateFlow<List<Node>> = nodesUiState.flatMapLatest { state ->
nodeDB.getNodes(state.sort, state.filter, state.includeUnknown, state.onlyOnline, state.onlyDirect)
.map { list ->
list.filter { it.isIgnored == state.showIgnored }
}
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),