Migrate (mostly) maps prefs to repo (#2776)

This commit is contained in:
Phil Oliver 2025-08-18 17:45:23 -04:00 committed by GitHub
parent 4be0cd7f81
commit 6cb0196a6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 23 additions and 43 deletions

View file

@ -17,10 +17,9 @@
package com.geeksville.mesh.ui.map
import android.content.SharedPreferences
import androidx.core.content.edit
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.geeksville.mesh.android.prefs.UiPrefs
import com.geeksville.mesh.database.NodeRepository
import com.geeksville.mesh.database.PacketRepository
import com.geeksville.mesh.database.entity.Packet
@ -35,7 +34,7 @@ import kotlinx.coroutines.flow.stateIn
@Suppress("TooManyFunctions")
abstract class BaseMapViewModel(
protected val preferences: SharedPreferences,
protected val uiPrefs: UiPrefs,
nodeRepository: NodeRepository,
packetRepository: PacketRepository,
) : ViewModel() {
@ -62,28 +61,27 @@ abstract class BaseMapViewModel(
}
.stateIn(scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), initialValue = emptyMap())
private val showOnlyFavorites = MutableStateFlow(preferences.getBoolean("only-favorites", false))
private val showOnlyFavorites = MutableStateFlow(uiPrefs.showOnlyFavorites)
private val showWaypointsOnMap = MutableStateFlow(preferences.getBoolean("show-waypoints-on-map", true))
private val showWaypointsOnMap = MutableStateFlow(uiPrefs.showWaypointsOnMap)
private val showPrecisionCircleOnMap =
MutableStateFlow(preferences.getBoolean("show-precision-circle-on-map", true))
private val showPrecisionCircleOnMap = MutableStateFlow(uiPrefs.showPrecisionCircleOnMap)
fun toggleOnlyFavorites() {
val current = showOnlyFavorites.value
preferences.edit { putBoolean("only-favorites", !current) }
uiPrefs.showOnlyFavorites = !current
showOnlyFavorites.value = !current
}
fun toggleShowWaypointsOnMap() {
val current = showWaypointsOnMap.value
preferences.edit { putBoolean("show-waypoints-on-map", !current) }
uiPrefs.showWaypointsOnMap = !current
showWaypointsOnMap.value = !current
}
fun toggleShowPrecisionCircleOnMap() {
val current = showPrecisionCircleOnMap.value
preferences.edit { putBoolean("show-precision-circle-on-map", !current) }
uiPrefs.showPrecisionCircleOnMap = !current
showPrecisionCircleOnMap.value = !current
}

View file

@ -1,20 +0,0 @@
/*
* Copyright (c) 2025 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 com.geeksville.mesh.ui.map
const val MAP_STYLE_ID = "map_style_id"