Aperture: Ask for GPS permission only on the first launch
Change-Id: I6492771a22f3523aa9fcb4de0fc14f68bccef447
diff --git a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
index 6b583fc..1dfef5b 100644
--- a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
@@ -270,7 +270,7 @@
// Reset cached location
location = null
- if (allLocationPermissionsGranted() && sharedPreferences.saveLocation) {
+ if (allLocationPermissionsGranted() && sharedPreferences.saveLocation == true) {
// Request location updates
locationManager.allProviders.forEach {
locationManager.requestLocationUpdates(it, 1000, 1f, this)
@@ -617,7 +617,7 @@
super.onResume()
// Request camera permissions
- if (!allPermissionsGranted() || !allLocationPermissionsGranted()) {
+ if (!allPermissionsGranted() || sharedPreferences.saveLocation == null) {
requestMultiplePermissions.launch(
REQUIRED_PERMISSIONS + REQUIRED_PERMISSIONS_LOCATION
)
diff --git a/app/src/main/java/org/lineageos/aperture/SharedPreferencesExt.kt b/app/src/main/java/org/lineageos/aperture/SharedPreferencesExt.kt
index 6b26772..accf276 100644
--- a/app/src/main/java/org/lineageos/aperture/SharedPreferencesExt.kt
+++ b/app/src/main/java/org/lineageos/aperture/SharedPreferencesExt.kt
@@ -20,6 +20,23 @@
import org.lineageos.aperture.utils.StabilizationMode
import org.lineageos.aperture.utils.TimerMode
+// Helpers
+internal fun SharedPreferences.getBoolean(key: String): Boolean? {
+ return if (contains(key)) {
+ getBoolean(key, false)
+ } else {
+ null
+ }
+}
+
+internal fun SharedPreferences.Editor.putBoolean(key: String, value: Boolean?) {
+ if (value == null) {
+ remove(key)
+ } else {
+ putBoolean(key, value)
+ }
+}
+
// Generic prefs
private const val LAST_CAMERA_FACING_KEY = "last_camera_facing"
private const val LAST_CAMERA_FACING_DEFAULT = "back"
@@ -273,9 +290,8 @@
// Save location
private const val SAVE_LOCATION = "save_location"
-private const val SAVE_LOCATION_DEFAULT = false
-internal var SharedPreferences.saveLocation: Boolean
- get() = getBoolean(SAVE_LOCATION, SAVE_LOCATION_DEFAULT)
+internal var SharedPreferences.saveLocation: Boolean?
+ get() = getBoolean(SAVE_LOCATION)
set(value) = edit {
putBoolean(SAVE_LOCATION, value)
}