Skip to content

Commit

Permalink
store background location pref
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksville committed Jun 23, 2021
1 parent 74f7281 commit 74a34cd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/geeksville/mesh/model/MyPreferences.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.geeksville.mesh.model

object MyPreferences {
val provideLocationKey = "provide-location"
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/geeksville/mesh/model/UIState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/settings_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 74a34cd

Please sign in to comment.