mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix: harden reliability, clean up KMP compliance, and improve code quality (#5023)
This commit is contained in:
parent
537029a71c
commit
14b381c1eb
53 changed files with 370 additions and 409 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue