mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-02-01 11:22:40 -05:00
store background location pref
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package com.geeksville.mesh.model
|
||||
|
||||
object MyPreferences {
|
||||
val provideLocationKey = "provide-location"
|
||||
}
|
||||
@@ -190,6 +190,15 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
|
||||
val bluetoothEnabled = object : MutableLiveData<Boolean>(false) {
|
||||
}
|
||||
|
||||
val provideLocation = object : MutableLiveData<Boolean>(getPreferences(context).getBoolean(MyPreferences.provideLocationKey, false)) {
|
||||
override fun setValue(value: Boolean) {
|
||||
super.setValue(value)
|
||||
|
||||
getPreferences(context).edit(commit = true) {
|
||||
this.putBoolean(MyPreferences.provideLocationKey, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If the app was launched because we received a new channel intent, the Url will be here
|
||||
var requestedChannelUrl: Uri? = null
|
||||
|
||||
@@ -651,6 +651,9 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||
}
|
||||
|
||||
binding.provideLocationCheckbox.setOnCheckedChangeListener { view, isChecked ->
|
||||
// No matter what set our desired state in prefs
|
||||
model.provideLocation.value = isChecked
|
||||
|
||||
if (view.isPressed && isChecked) { // We want to ignore changes caused by code (as opposed to the user)
|
||||
debug("User changed location tracking to $isChecked")
|
||||
view.isChecked =
|
||||
@@ -977,7 +980,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||
scanModel.startScan()
|
||||
|
||||
// system permissions might have changed while we were away
|
||||
binding.provideLocationCheckbox.isChecked = myActivity.hasBackgroundPermission()
|
||||
binding.provideLocationCheckbox.isChecked = myActivity.hasBackgroundPermission() && (model.provideLocation.value ?: false)
|
||||
|
||||
myActivity.registerReceiver(updateProgressReceiver, updateProgressFilter)
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="Provide location to mesh"
|
||||
android:text="@string/provide_location_to_mesh"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/deviceRadioGroup" />
|
||||
|
||||
|
||||
@@ -115,4 +115,5 @@
|
||||
<string name="location">location</string>
|
||||
<string name="cancel_no_radio">Cancel (no radio access)</string>
|
||||
<string name="allow_will_show">Allow (will show dialog)</string>
|
||||
<string name="provide_location_to_mesh">Provide location to mesh</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user