mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat(map): Persist Google Maps camera position (#3605)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
78a10118a0
commit
6e06d27701
10 changed files with 184 additions and 37 deletions
|
|
@ -19,6 +19,8 @@ package org.meshtastic.core.prefs.map
|
|||
|
||||
import android.content.SharedPreferences
|
||||
import com.google.maps.android.compose.MapType
|
||||
import org.meshtastic.core.prefs.DoublePrefDelegate
|
||||
import org.meshtastic.core.prefs.FloatPrefDelegate
|
||||
import org.meshtastic.core.prefs.NullableStringPrefDelegate
|
||||
import org.meshtastic.core.prefs.StringSetPrefDelegate
|
||||
import org.meshtastic.core.prefs.di.GoogleMapsSharedPreferences
|
||||
|
|
@ -30,6 +32,11 @@ interface GoogleMapsPrefs {
|
|||
var selectedGoogleMapType: String?
|
||||
var selectedCustomTileUrl: String?
|
||||
var hiddenLayerUrls: Set<String>
|
||||
var cameraTargetLat: Double
|
||||
var cameraTargetLng: Double
|
||||
var cameraZoom: Float
|
||||
var cameraTilt: Float
|
||||
var cameraBearing: Float
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
|
@ -38,4 +45,9 @@ class GoogleMapsPrefsImpl @Inject constructor(@GoogleMapsSharedPreferences prefs
|
|||
NullableStringPrefDelegate(prefs, "selected_google_map_type", MapType.NORMAL.name)
|
||||
override var selectedCustomTileUrl: String? by NullableStringPrefDelegate(prefs, "selected_custom_tile_url", null)
|
||||
override var hiddenLayerUrls: Set<String> by StringSetPrefDelegate(prefs, "hidden_layer_urls", emptySet())
|
||||
override var cameraTargetLat: Double by DoublePrefDelegate(prefs, "camera_target_lat", 0.0)
|
||||
override var cameraTargetLng: Double by DoublePrefDelegate(prefs, "camera_target_lng", 0.0)
|
||||
override var cameraZoom: Float by FloatPrefDelegate(prefs, "camera_zoom", 7f)
|
||||
override var cameraTilt: Float by FloatPrefDelegate(prefs, "camera_tilt", 0f)
|
||||
override var cameraBearing: Float by FloatPrefDelegate(prefs, "camera_bearing", 0f)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 org.meshtastic.core.prefs
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class DoublePrefDelegate(
|
||||
private val preferences: SharedPreferences,
|
||||
private val key: String,
|
||||
private val defaultValue: Double,
|
||||
) : ReadWriteProperty<Any?, Double> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Double = preferences
|
||||
.getFloat(key, defaultValue.toFloat())
|
||||
.toDouble() // SharedPreferences doesn't have putDouble, so convert to float
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Double) {
|
||||
preferences
|
||||
.edit()
|
||||
.putFloat(key, value.toFloat())
|
||||
.apply() // SharedPreferences doesn't have putDouble, so convert to float
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 org.meshtastic.core.prefs
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class FloatPrefDelegate(
|
||||
private val preferences: SharedPreferences,
|
||||
private val key: String,
|
||||
private val defaultValue: Float,
|
||||
) : ReadWriteProperty<Any?, Float> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Float = preferences.getFloat(key, defaultValue)
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Float) {
|
||||
preferences.edit().putFloat(key, value).apply()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue