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

@ -18,7 +18,6 @@
package com.geeksville.mesh.model
import android.app.Application
import android.content.SharedPreferences
import android.net.Uri
import androidx.annotation.StringRes
import androidx.compose.ui.unit.Dp
@ -38,6 +37,7 @@ import com.geeksville.mesh.Portnums.PortNum
import com.geeksville.mesh.R
import com.geeksville.mesh.TelemetryProtos.Telemetry
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.android.prefs.UiPrefs
import com.geeksville.mesh.database.MeshLogRepository
import com.geeksville.mesh.database.entity.FirmwareRelease
import com.geeksville.mesh.database.entity.MeshLog
@ -47,7 +47,6 @@ import com.geeksville.mesh.repository.api.DeviceHardwareRepository
import com.geeksville.mesh.repository.api.FirmwareReleaseRepository
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
import com.geeksville.mesh.service.ServiceAction
import com.geeksville.mesh.ui.map.MAP_STYLE_ID
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@ -204,7 +203,7 @@ constructor(
private val radioConfigRepository: RadioConfigRepository,
private val deviceHardwareRepository: DeviceHardwareRepository,
private val firmwareReleaseRepository: FirmwareReleaseRepository,
private val preferences: SharedPreferences,
private val uiPrefs: UiPrefs,
) : ViewModel(),
Logging {
private val destNum = savedStateHandle.toRoute<NodesRoutes.NodeDetailGraph>().destNum
@ -234,7 +233,7 @@ constructor(
fun getUser(nodeNum: Int) = radioConfigRepository.getUser(nodeNum)
val tileSource
get() = CustomTileSource.getTileSource(preferences.getInt(MAP_STYLE_ID, 0))
get() = CustomTileSource.getTileSource(uiPrefs.mapStyle)
fun deleteLog(uuid: String) = viewModelScope.launch(dispatchers.io) { meshLogRepository.deleteLog(uuid) }

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"