mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-13 03:17:48 -04:00
Migrate remaining prefs usages to repo (#2777)
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.geeksville.mesh.ui.map
|
||||
|
||||
import com.geeksville.mesh.android.prefs.UiPrefs
|
||||
import com.geeksville.mesh.android.prefs.MapPrefs
|
||||
import com.geeksville.mesh.database.NodeRepository
|
||||
import com.geeksville.mesh.database.PacketRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -27,14 +27,14 @@ import javax.inject.Inject
|
||||
class MapViewModel
|
||||
@Inject
|
||||
constructor(
|
||||
uiPrefs: UiPrefs,
|
||||
mapPrefs: MapPrefs,
|
||||
packetRepository: PacketRepository,
|
||||
nodeRepository: NodeRepository,
|
||||
) : BaseMapViewModel(uiPrefs, nodeRepository, packetRepository) {
|
||||
) : BaseMapViewModel(mapPrefs, nodeRepository, packetRepository) {
|
||||
|
||||
var mapStyleId: Int
|
||||
get() = uiPrefs.mapStyle
|
||||
get() = mapPrefs.mapStyle
|
||||
set(value) {
|
||||
uiPrefs.mapStyle = value
|
||||
mapPrefs.mapStyle = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package com.geeksville.mesh
|
||||
|
||||
import android.os.Debug
|
||||
import com.geeksville.mesh.android.AppPrefs
|
||||
import com.geeksville.mesh.android.BuildUtils.isEmulator
|
||||
import com.geeksville.mesh.android.GeeksvilleApplication
|
||||
import com.geeksville.mesh.android.prefs.AnalyticsPrefs
|
||||
@@ -41,8 +40,7 @@ class MeshUtilApplication : GeeksvilleApplication() {
|
||||
// leave off when running in the debugger
|
||||
if (!isEmulator && (!BuildConfig.DEBUG || !Debug.isDebuggerConnected())) {
|
||||
val crashlytics = FirebaseCrashlytics.getInstance()
|
||||
val pref = AppPrefs(this)
|
||||
crashlytics.setUserId(pref.getInstallId()) // be able to group all bugs per anonymous user
|
||||
crashlytics.setUserId(analyticsPrefs.installId) // be able to group all bugs per anonymous user
|
||||
|
||||
fun sendCrashReports() {
|
||||
if (isAnalyticsAllowed) {
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
|
||||
package com.geeksville.mesh.analytics
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import com.geeksville.mesh.android.AppPrefs
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.google.firebase.Firebase
|
||||
import com.google.firebase.analytics.FirebaseAnalytics
|
||||
@@ -36,16 +34,11 @@ class DataPair(val name: String, valueIn: Any?) {
|
||||
}
|
||||
|
||||
/** Implement our analytics API using Firebase Analytics */
|
||||
class FirebaseAnalytics(context: Context) :
|
||||
class FirebaseAnalytics(installId: String) :
|
||||
AnalyticsProvider,
|
||||
Logging {
|
||||
|
||||
val t = Firebase.analytics
|
||||
|
||||
init {
|
||||
val pref = AppPrefs(context)
|
||||
t.setUserId(pref.getInstallId())
|
||||
}
|
||||
val t = Firebase.analytics.apply { setUserId(installId) }
|
||||
|
||||
override fun setEnabled(on: Boolean) {
|
||||
t.setAnalyticsCollectionEnabled(on)
|
||||
|
||||
@@ -133,7 +133,7 @@ abstract class GeeksvilleApplication :
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
val firebaseAnalytics = FirebaseAnalytics(this)
|
||||
val firebaseAnalytics = FirebaseAnalytics(analyticsPrefs.installId)
|
||||
analytics = firebaseAnalytics
|
||||
|
||||
// Set analytics per prefs
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.android.prefs
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Qualifier
|
||||
import javax.inject.Singleton
|
||||
|
||||
// Pref store qualifiers are private to prevent prefs stores from being injected directly.
|
||||
// Consuming code should always inject one of the prefs repositories.
|
||||
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
private annotation class GoogleMapsSharedPreferences
|
||||
|
||||
@InstallIn(SingletonComponent::class)
|
||||
@Module
|
||||
object GoogleMapsModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@GoogleMapsSharedPreferences
|
||||
fun provideGoogleMapsSharedPreferences(@ApplicationContext context: Context): SharedPreferences =
|
||||
context.getSharedPreferences("google_maps_prefs", Context.MODE_PRIVATE)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideGoogleMapsPrefs(@GoogleMapsSharedPreferences sharedPreferences: SharedPreferences): GoogleMapsPrefs =
|
||||
GoogleMapsPrefsImpl(sharedPreferences)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.android.prefs
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import com.google.maps.android.compose.MapType
|
||||
|
||||
/** Interface for prefs specific to Google Maps. For general map prefs, see MapPrefs. */
|
||||
interface GoogleMapsPrefs {
|
||||
var selectedGoogleMapType: String?
|
||||
var selectedCustomTileUrl: String?
|
||||
}
|
||||
|
||||
class GoogleMapsPrefsImpl(prefs: SharedPreferences) : GoogleMapsPrefs {
|
||||
override var selectedGoogleMapType: String? by
|
||||
NullableStringPrefDelegate(prefs, "selected_google_map_type", MapType.NORMAL.name)
|
||||
override var selectedCustomTileUrl: String? by NullableStringPrefDelegate(prefs, "selected_custom_tile_url", null)
|
||||
}
|
||||
@@ -18,13 +18,12 @@
|
||||
package com.geeksville.mesh.ui.map
|
||||
|
||||
import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.geeksville.mesh.ConfigProtos
|
||||
import com.geeksville.mesh.android.BuildUtils.debug
|
||||
import com.geeksville.mesh.android.prefs.UiPrefs
|
||||
import com.geeksville.mesh.android.prefs.GoogleMapsPrefs
|
||||
import com.geeksville.mesh.android.prefs.MapPrefs
|
||||
import com.geeksville.mesh.database.NodeRepository
|
||||
import com.geeksville.mesh.database.PacketRepository
|
||||
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
|
||||
@@ -61,8 +60,6 @@ import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val TILE_SIZE = 256
|
||||
private const val PREF_SELECTED_GOOGLE_MAP_TYPE = "selected_google_map_type"
|
||||
private const val PREF_SELECTED_CUSTOM_TILE_URL = "selected_custom_tile_url"
|
||||
|
||||
@Serializable
|
||||
data class MapCameraPosition(
|
||||
@@ -79,13 +76,13 @@ class MapViewModel
|
||||
@Inject
|
||||
constructor(
|
||||
private val application: Application,
|
||||
uiPrefs: UiPrefs,
|
||||
private val preferences: SharedPreferences,
|
||||
mapPrefs: MapPrefs,
|
||||
private val googleMapsPrefs: GoogleMapsPrefs,
|
||||
nodeRepository: NodeRepository,
|
||||
packetRepository: PacketRepository,
|
||||
radioConfigRepository: RadioConfigRepository,
|
||||
private val customTileProviderRepository: CustomTileProviderRepository,
|
||||
) : BaseMapViewModel(uiPrefs, nodeRepository, packetRepository) {
|
||||
) : BaseMapViewModel(mapPrefs, nodeRepository, packetRepository) {
|
||||
|
||||
private val _errorFlow = MutableSharedFlow<String>()
|
||||
val errorFlow: SharedFlow<String> = _errorFlow.asSharedFlow()
|
||||
@@ -187,7 +184,7 @@ constructor(
|
||||
if (configToRemove != null && _selectedCustomTileProviderUrl.value == configToRemove.urlTemplate) {
|
||||
_selectedCustomTileProviderUrl.value = null
|
||||
// Also clear from prefs
|
||||
preferences.edit { remove(PREF_SELECTED_CUSTOM_TILE_URL) }
|
||||
googleMapsPrefs.selectedCustomTileUrl = null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,26 +194,24 @@ constructor(
|
||||
if (!isValidTileUrlTemplate(config.urlTemplate)) {
|
||||
Timber.tag("MapViewModel").w("Attempted to select invalid URL template: ${config.urlTemplate}")
|
||||
_selectedCustomTileProviderUrl.value = null
|
||||
preferences.edit { remove(PREF_SELECTED_CUSTOM_TILE_URL) }
|
||||
googleMapsPrefs.selectedCustomTileUrl = null
|
||||
return
|
||||
}
|
||||
_selectedCustomTileProviderUrl.value = config.urlTemplate
|
||||
_selectedGoogleMapType.value = MapType.NORMAL // Reset to a default or keep last? For now, reset.
|
||||
preferences.edit {
|
||||
putString(PREF_SELECTED_CUSTOM_TILE_URL, config.urlTemplate).remove(PREF_SELECTED_GOOGLE_MAP_TYPE)
|
||||
}
|
||||
googleMapsPrefs.selectedCustomTileUrl = config.urlTemplate
|
||||
googleMapsPrefs.selectedGoogleMapType = null
|
||||
} else {
|
||||
_selectedCustomTileProviderUrl.value = null
|
||||
preferences.edit { remove(PREF_SELECTED_CUSTOM_TILE_URL) }
|
||||
googleMapsPrefs.selectedCustomTileUrl = null
|
||||
}
|
||||
}
|
||||
|
||||
fun setSelectedGoogleMapType(mapType: MapType) {
|
||||
_selectedGoogleMapType.value = mapType
|
||||
_selectedCustomTileProviderUrl.value = null // Clear custom selection
|
||||
preferences.edit {
|
||||
putString(PREF_SELECTED_GOOGLE_MAP_TYPE, mapType.name).remove(PREF_SELECTED_CUSTOM_TILE_URL)
|
||||
}
|
||||
googleMapsPrefs.selectedGoogleMapType = mapType.name
|
||||
googleMapsPrefs.selectedCustomTileUrl = null
|
||||
}
|
||||
|
||||
fun createUrlTileProvider(urlString: String): TileProvider? {
|
||||
@@ -254,7 +249,7 @@ constructor(
|
||||
}
|
||||
|
||||
private fun loadPersistedMapType() {
|
||||
val savedCustomUrl = preferences.getString(PREF_SELECTED_CUSTOM_TILE_URL, null)
|
||||
val savedCustomUrl = googleMapsPrefs.selectedCustomTileUrl
|
||||
if (savedCustomUrl != null) {
|
||||
// Check if this custom provider still exists
|
||||
if (
|
||||
@@ -265,18 +260,18 @@ constructor(
|
||||
_selectedGoogleMapType.value = MapType.NORMAL // Default, as custom is active
|
||||
} else {
|
||||
// The saved custom URL is no longer valid or doesn't exist, remove preference
|
||||
preferences.edit { remove(PREF_SELECTED_CUSTOM_TILE_URL) }
|
||||
googleMapsPrefs.selectedCustomTileUrl = null
|
||||
// Fallback to default Google Map type
|
||||
_selectedGoogleMapType.value = MapType.NORMAL
|
||||
}
|
||||
} else {
|
||||
val savedGoogleMapTypeName = preferences.getString(PREF_SELECTED_GOOGLE_MAP_TYPE, MapType.NORMAL.name)
|
||||
val savedGoogleMapTypeName = googleMapsPrefs.selectedGoogleMapType
|
||||
try {
|
||||
_selectedGoogleMapType.value = MapType.valueOf(savedGoogleMapTypeName ?: MapType.NORMAL.name)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Timber.e(e, "Invalid saved Google Map type: $savedGoogleMapTypeName")
|
||||
_selectedGoogleMapType.value = MapType.NORMAL // Fallback in case of invalid stored name
|
||||
preferences.edit { remove(PREF_SELECTED_GOOGLE_MAP_TYPE) }
|
||||
googleMapsPrefs.selectedGoogleMapType = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
package com.geeksville.mesh
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
@@ -32,9 +30,6 @@ import dagger.hilt.components.SingletonComponent
|
||||
@InstallIn(SingletonComponent::class)
|
||||
@Module
|
||||
object ApplicationModule {
|
||||
@Provides
|
||||
fun provideSharedPreferences(application: Application): SharedPreferences =
|
||||
application.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
|
||||
|
||||
@Provides fun provideProcessLifecycleOwner(): LifecycleOwner = ProcessLifecycleOwner.get()
|
||||
|
||||
|
||||
@@ -1,127 +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.android
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import java.util.UUID
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
/**
|
||||
* Created by kevinh on 1/4/15.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* A delegate for "foo by FloatPref"
|
||||
*/
|
||||
class FloatPref {
|
||||
fun get(thisRef: AppPrefs, prop: KProperty<Float>): Float = thisRef.getPrefs().getFloat(thisRef.makeName(prop.name), java.lang.Float.MIN_VALUE)
|
||||
|
||||
fun set(thisRef: AppPrefs, prop: KProperty<Float>, value: Float) {
|
||||
thisRef.setPrefs { e -> e.putFloat(thisRef.makeName(prop.name), value)}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A delegate for "foo by StringPref"
|
||||
*/
|
||||
class StringPref(val default: String) {
|
||||
fun get(thisRef: AppPrefs, prop: KProperty<String>): String = thisRef.getPrefs().getString(thisRef.makeName(prop.name), default)!!
|
||||
|
||||
fun set(thisRef: AppPrefs, prop: KProperty<String>, value: String) {
|
||||
thisRef.setPrefs { e ->
|
||||
e.putString(thisRef.makeName(prop.name), value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A mixin for accessing android prefs for the app
|
||||
*/
|
||||
public open class AppPrefs(val context: Context) {
|
||||
|
||||
companion object {
|
||||
private val baseName = "appPrefs_"
|
||||
}
|
||||
|
||||
fun makeName(s: String) = baseName + s
|
||||
|
||||
fun getPrefs() = context.getSharedPreferences("prefs", Context.MODE_PRIVATE)
|
||||
|
||||
fun setPrefs(body: (SharedPreferences.Editor) -> Unit) {
|
||||
val e = getPrefs().edit()
|
||||
body(e)
|
||||
e.commit()
|
||||
}
|
||||
|
||||
fun incPref(name: String) {
|
||||
setPrefs { e ->
|
||||
e.putInt(name, 1 + getPrefs().getInt(name, 0))
|
||||
}
|
||||
}
|
||||
|
||||
fun removePref(name: String) {
|
||||
setPrefs { e ->
|
||||
e.remove(name)
|
||||
}
|
||||
}
|
||||
|
||||
fun putPref(name: String, b: Boolean) {
|
||||
setPrefs { e ->
|
||||
e.putBoolean(name, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun putPref(name: String, b: Float) {
|
||||
setPrefs { e ->
|
||||
e.putFloat(name, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun putPref(name: String, b: Int) {
|
||||
setPrefs { e ->
|
||||
e.putInt(name, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun putPref(name: String, b: Set<String>) {
|
||||
setPrefs { e ->
|
||||
e.putStringSet(name, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun putPref(name: String, b: String) {
|
||||
setPrefs { e ->
|
||||
e.putString(name, b)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a persistent installation ID
|
||||
*/
|
||||
fun getInstallId(): String {
|
||||
var r = getPrefs().getString(makeName("installId"), "")!!
|
||||
if(r == "") {
|
||||
r = UUID.randomUUID().toString()
|
||||
putPref(makeName("installId"), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,19 @@
|
||||
package com.geeksville.mesh.android.prefs
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import java.util.UUID
|
||||
|
||||
interface AnalyticsPrefs {
|
||||
var analyticsAllowed: Boolean
|
||||
val installId: String
|
||||
}
|
||||
|
||||
class AnalyticsPrefsImpl(prefs: SharedPreferences) : AnalyticsPrefs {
|
||||
override var analyticsAllowed: Boolean by PrefDelegate(prefs, "allowed", true)
|
||||
// Having an additional app prefs store is maintaining the existing behavior.
|
||||
class AnalyticsPrefsImpl(analyticsPrefs: SharedPreferences, appPrefs: SharedPreferences) : AnalyticsPrefs {
|
||||
override var analyticsAllowed: Boolean by PrefDelegate(analyticsPrefs, "allowed", true)
|
||||
|
||||
private var _installId: String? by NullableStringPrefDelegate(appPrefs, "appPrefs_install_id", null)
|
||||
|
||||
override val installId: String
|
||||
get() = _installId ?: UUID.randomUUID().toString().also { _installId = it }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.android.prefs
|
||||
|
||||
import android.content.SharedPreferences
|
||||
|
||||
/** Interface for general map prefs. For Google-specific prefs, see GoogleMapsPrefs. */
|
||||
interface MapPrefs {
|
||||
var mapStyle: Int
|
||||
var showOnlyFavorites: Boolean
|
||||
var showWaypointsOnMap: Boolean
|
||||
var showPrecisionCircleOnMap: Boolean
|
||||
}
|
||||
|
||||
class MapPrefsImpl(prefs: SharedPreferences) : MapPrefs {
|
||||
override var mapStyle: Int by PrefDelegate(prefs, "map_style_id", 0)
|
||||
override var showOnlyFavorites: Boolean by PrefDelegate(prefs, "show_only_favorites", false)
|
||||
override var showWaypointsOnMap: Boolean by PrefDelegate(prefs, "show_waypoints", true)
|
||||
override var showPrecisionCircleOnMap: Boolean by PrefDelegate(prefs, "show_precision_circle", true)
|
||||
}
|
||||
@@ -34,10 +34,18 @@ import javax.inject.Singleton
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
private annotation class AnalyticsSharedPreferences
|
||||
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
private annotation class AppSharedPreferences
|
||||
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
private annotation class CustomEmojiSharedPreferences
|
||||
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
private annotation class MapSharedPreferences
|
||||
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
private annotation class MapConsentSharedPreferences
|
||||
@@ -69,12 +77,24 @@ object PrefsModule {
|
||||
fun provideAnalyticsSharedPreferences(@ApplicationContext context: Context): SharedPreferences =
|
||||
context.getSharedPreferences("analytics-prefs", Context.MODE_PRIVATE)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@AppSharedPreferences
|
||||
fun provideAppSharedPreferences(@ApplicationContext context: Context): SharedPreferences =
|
||||
context.getSharedPreferences("prefs", Context.MODE_PRIVATE)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@CustomEmojiSharedPreferences
|
||||
fun provideCustomEmojiSharedPreferences(@ApplicationContext context: Context): SharedPreferences =
|
||||
context.getSharedPreferences("org.geeksville.emoji.prefs", Context.MODE_PRIVATE)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@MapSharedPreferences
|
||||
fun provideMapSharedPreferences(@ApplicationContext context: Context): SharedPreferences =
|
||||
context.getSharedPreferences("map_prefs", Context.MODE_PRIVATE)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@MapConsentSharedPreferences
|
||||
@@ -107,14 +127,21 @@ object PrefsModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAnalyticsPrefs(@AnalyticsSharedPreferences sharedPreferences: SharedPreferences): AnalyticsPrefs =
|
||||
AnalyticsPrefsImpl(sharedPreferences)
|
||||
fun provideAnalyticsPrefs(
|
||||
@AnalyticsSharedPreferences analyticsPreferences: SharedPreferences,
|
||||
@AppSharedPreferences appPreferences: SharedPreferences,
|
||||
): AnalyticsPrefs = AnalyticsPrefsImpl(analyticsPreferences, appPreferences)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideCustomEmojiPrefs(@CustomEmojiSharedPreferences sharedPreferences: SharedPreferences): CustomEmojiPrefs =
|
||||
CustomEmojiPrefsImpl(sharedPreferences)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideMapPrefs(@MapSharedPreferences sharedPreferences: SharedPreferences): MapPrefs =
|
||||
MapPrefsImpl(sharedPreferences)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideMapConsentPrefs(@MapConsentSharedPreferences sharedPreferences: SharedPreferences): MapConsentPrefs =
|
||||
|
||||
@@ -36,15 +36,6 @@ interface UiPrefs {
|
||||
var showIgnored: Boolean
|
||||
var showQuickChat: Boolean
|
||||
|
||||
// region Map prefs
|
||||
|
||||
var showOnlyFavorites: Boolean
|
||||
var showWaypointsOnMap: Boolean
|
||||
var showPrecisionCircleOnMap: Boolean
|
||||
var mapStyle: Int
|
||||
|
||||
// endregion
|
||||
|
||||
fun shouldProvideNodeLocation(nodeNum: Int?): Boolean
|
||||
|
||||
fun setShouldProvideNodeLocation(nodeNum: Int?, value: Boolean)
|
||||
@@ -62,10 +53,6 @@ class UiPrefsImpl(private val prefs: SharedPreferences) : UiPrefs {
|
||||
override var onlyDirect: Boolean by PrefDelegate(prefs, "only-direct", false)
|
||||
override var showIgnored: Boolean by PrefDelegate(prefs, "show-ignored", false)
|
||||
override var showQuickChat: Boolean by PrefDelegate(prefs, "show-quick-chat", false)
|
||||
override var showOnlyFavorites: Boolean by PrefDelegate(prefs, "only-favorites", false)
|
||||
override var showWaypointsOnMap: Boolean by PrefDelegate(prefs, "show-waypoints-on-map", true)
|
||||
override var showPrecisionCircleOnMap: Boolean by PrefDelegate(prefs, "show-precision-circle-on-map", true)
|
||||
override var mapStyle: Int by PrefDelegate(prefs, "map_style_id", 0)
|
||||
|
||||
override fun shouldProvideNodeLocation(nodeNum: Int?): Boolean =
|
||||
prefs.getBoolean(provideLocationKey(nodeNum), false)
|
||||
|
||||
@@ -37,7 +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.android.prefs.MapPrefs
|
||||
import com.geeksville.mesh.database.MeshLogRepository
|
||||
import com.geeksville.mesh.database.entity.FirmwareRelease
|
||||
import com.geeksville.mesh.database.entity.MeshLog
|
||||
@@ -203,7 +203,7 @@ constructor(
|
||||
private val radioConfigRepository: RadioConfigRepository,
|
||||
private val deviceHardwareRepository: DeviceHardwareRepository,
|
||||
private val firmwareReleaseRepository: FirmwareReleaseRepository,
|
||||
private val uiPrefs: UiPrefs,
|
||||
private val mapPrefs: MapPrefs,
|
||||
) : ViewModel(),
|
||||
Logging {
|
||||
private val destNum = savedStateHandle.toRoute<NodesRoutes.NodeDetailGraph>().destNum
|
||||
@@ -233,7 +233,7 @@ constructor(
|
||||
fun getUser(nodeNum: Int) = radioConfigRepository.getUser(nodeNum)
|
||||
|
||||
val tileSource
|
||||
get() = CustomTileSource.getTileSource(uiPrefs.mapStyle)
|
||||
get() = CustomTileSource.getTileSource(mapPrefs.mapStyle)
|
||||
|
||||
fun deleteLog(uuid: String) = viewModelScope.launch(dispatchers.io) { meshLogRepository.deleteLog(uuid) }
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.geeksville.mesh.ui.map
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.geeksville.mesh.android.prefs.UiPrefs
|
||||
import com.geeksville.mesh.android.prefs.MapPrefs
|
||||
import com.geeksville.mesh.database.NodeRepository
|
||||
import com.geeksville.mesh.database.PacketRepository
|
||||
import com.geeksville.mesh.database.entity.Packet
|
||||
@@ -34,7 +34,7 @@ import kotlinx.coroutines.flow.stateIn
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
abstract class BaseMapViewModel(
|
||||
protected val uiPrefs: UiPrefs,
|
||||
protected val mapPrefs: MapPrefs,
|
||||
nodeRepository: NodeRepository,
|
||||
packetRepository: PacketRepository,
|
||||
) : ViewModel() {
|
||||
@@ -61,27 +61,27 @@ abstract class BaseMapViewModel(
|
||||
}
|
||||
.stateIn(scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), initialValue = emptyMap())
|
||||
|
||||
private val showOnlyFavorites = MutableStateFlow(uiPrefs.showOnlyFavorites)
|
||||
private val showOnlyFavorites = MutableStateFlow(mapPrefs.showOnlyFavorites)
|
||||
|
||||
private val showWaypointsOnMap = MutableStateFlow(uiPrefs.showWaypointsOnMap)
|
||||
private val showWaypointsOnMap = MutableStateFlow(mapPrefs.showWaypointsOnMap)
|
||||
|
||||
private val showPrecisionCircleOnMap = MutableStateFlow(uiPrefs.showPrecisionCircleOnMap)
|
||||
private val showPrecisionCircleOnMap = MutableStateFlow(mapPrefs.showPrecisionCircleOnMap)
|
||||
|
||||
fun toggleOnlyFavorites() {
|
||||
val current = showOnlyFavorites.value
|
||||
uiPrefs.showOnlyFavorites = !current
|
||||
mapPrefs.showOnlyFavorites = !current
|
||||
showOnlyFavorites.value = !current
|
||||
}
|
||||
|
||||
fun toggleShowWaypointsOnMap() {
|
||||
val current = showWaypointsOnMap.value
|
||||
uiPrefs.showWaypointsOnMap = !current
|
||||
mapPrefs.showWaypointsOnMap = !current
|
||||
showWaypointsOnMap.value = !current
|
||||
}
|
||||
|
||||
fun toggleShowPrecisionCircleOnMap() {
|
||||
val current = showPrecisionCircleOnMap.value
|
||||
uiPrefs.showPrecisionCircleOnMap = !current
|
||||
mapPrefs.showPrecisionCircleOnMap = !current
|
||||
showPrecisionCircleOnMap.value = !current
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user