fix: harden reliability, clean up KMP compliance, and improve code quality (#5023)

This commit is contained in:
James Rich 2026-04-09 13:21:46 -05:00 committed by GitHub
parent 537029a71c
commit 14b381c1eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
53 changed files with 370 additions and 409 deletions

View file

@ -20,6 +20,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
@ -44,6 +45,12 @@ import org.meshtastic.feature.map.model.TracerouteOverlay
import org.meshtastic.proto.Position
import org.meshtastic.proto.Waypoint
/**
* Shared base ViewModel for the map feature, providing node data, waypoints, map filter preferences, and traceroute
* overlay state.
*
* Platform-specific map ViewModels (fdroid/google) extend this to add flavor-specific map provider logic.
*/
@Suppress("TooManyFunctions")
open class BaseMapViewModel(
protected val mapPrefs: MapPrefs,
@ -92,7 +99,7 @@ open class BaseMapViewModel(
.stateInWhileSubscribed(initialValue = emptyMap())
private val showOnlyFavorites = MutableStateFlow(mapPrefs.showOnlyFavorites.value)
val showOnlyFavoritesOnMap = showOnlyFavorites
val showOnlyFavoritesOnMap: StateFlow<Boolean> = showOnlyFavorites.asStateFlow()
fun toggleOnlyFavorites() {
val newValue = !showOnlyFavorites.value
@ -101,7 +108,7 @@ open class BaseMapViewModel(
}
private val showWaypoints = MutableStateFlow(mapPrefs.showWaypointsOnMap.value)
val showWaypointsOnMap = showWaypoints
val showWaypointsOnMap: StateFlow<Boolean> = showWaypoints.asStateFlow()
fun toggleShowWaypointsOnMap() {
val newValue = !showWaypoints.value
@ -110,7 +117,7 @@ open class BaseMapViewModel(
}
private val showPrecisionCircle = MutableStateFlow(mapPrefs.showPrecisionCircleOnMap.value)
val showPrecisionCircleOnMap = showPrecisionCircle
val showPrecisionCircleOnMap: StateFlow<Boolean> = showPrecisionCircle.asStateFlow()
fun toggleShowPrecisionCircleOnMap() {
val newValue = !showPrecisionCircle.value
@ -119,7 +126,7 @@ open class BaseMapViewModel(
}
private val lastHeardFilterValue = MutableStateFlow(LastHeardFilter.fromSeconds(mapPrefs.lastHeardFilter.value))
val lastHeardFilter = lastHeardFilterValue
val lastHeardFilter: StateFlow<LastHeardFilter> = lastHeardFilterValue.asStateFlow()
fun setLastHeardFilter(filter: LastHeardFilter) {
lastHeardFilterValue.value = filter
@ -128,7 +135,7 @@ open class BaseMapViewModel(
private val lastHeardTrackFilterValue =
MutableStateFlow(LastHeardFilter.fromSeconds(mapPrefs.lastHeardTrackFilter.value))
val lastHeardTrackFilter = lastHeardTrackFilterValue
val lastHeardTrackFilter: StateFlow<LastHeardFilter> = lastHeardTrackFilterValue.asStateFlow()
fun setLastHeardTrackFilter(filter: LastHeardFilter) {
lastHeardTrackFilterValue.value = filter