store background location pref

This commit is contained in:
Kevin Hester
2021-06-23 12:41:44 -07:00
parent 74f7281a60
commit 74a34cd9b6
5 changed files with 20 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
package com.geeksville.mesh.model
object MyPreferences {
val provideLocationKey = "provide-location"
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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" />

View File

@@ -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>