From af330e4047e4ea6b0b22f3b3bb1e1fdf0bdf6efe Mon Sep 17 00:00:00 2001 From: Thames1990 Date: Fri, 26 Jan 2018 23:32:40 +0100 Subject: [PATCH] Disable location settings when location permission isn't granted Currently the seekbar is still enabled, but an issue for KAU has been opened: https://github.com/AllanWang/KAU/issues/133 --- .../mathematik/ds/serval/settings/Location.kt | 28 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/uni_marburg/mathematik/ds/serval/settings/Location.kt b/app/src/main/java/de/uni_marburg/mathematik/ds/serval/settings/Location.kt index 2eabc98d..555cc8dd 100644 --- a/app/src/main/java/de/uni_marburg/mathematik/ds/serval/settings/Location.kt +++ b/app/src/main/java/de/uni_marburg/mathematik/ds/serval/settings/Location.kt @@ -1,6 +1,11 @@ package de.uni_marburg.mathematik.ds.serval.settings +import android.Manifest import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder +import ca.allanwang.kau.kpref.activity.items.KPrefSeekbar +import ca.allanwang.kau.kpref.activity.items.KPrefText +import ca.allanwang.kau.utils.hasPermission +import ca.allanwang.kau.utils.snackbar import ca.allanwang.kau.utils.string import de.uni_marburg.mathematik.ds.serval.R import de.uni_marburg.mathematik.ds.serval.activities.SettingsActivity @@ -9,12 +14,25 @@ import de.uni_marburg.mathematik.ds.serval.utils.Prefs import de.uni_marburg.mathematik.ds.serval.utils.materialDialogThemed fun SettingsActivity.getLocationPrefs(): KPrefAdapterBuilder.() -> Unit = { + fun KPrefText.KPrefTextContract.dependsOnLocationPermission() { + enabler = { hasPermission(Manifest.permission.ACCESS_FINE_LOCATION) } + onDisabledClick = { snackbar(R.string.requires_location_permission) } + } + + // TODO Currently the seekbar isn't disabled, when the contract enabler is false + // See: https://github.com/AllanWang/KAU/issues/133 + fun KPrefSeekbar.KPrefSeekbarContract.dependsOnLocationPermission() { + enabler = { hasPermission(Manifest.permission.ACCESS_FINE_LOCATION) } + onDisabledClick = { snackbar(R.string.requires_location_permission) } + } + // Location request priority text( title = R.string.location_request_priority, getter = Prefs::locationRequestPriorityType, setter = { Prefs.locationRequestPriorityType = it } ) { + dependsOnLocationPermission() onClick = { materialDialogThemed { title(R.string.location_request_priority) @@ -39,12 +57,18 @@ fun SettingsActivity.getLocationPrefs(): KPrefAdapterBuilder.() -> Unit = { title = R.string.location_request_interval, getter = Prefs::locationRequestInterval, setter = { Prefs.locationRequestInterval = it } - ) { descRes = R.string.location_request_interval_description } + ) { + dependsOnLocationPermission() + descRes = R.string.location_request_interval_description + } // Location request priority fastest interval seekbar( title = R.string.location_request_fastest_interval, getter = Prefs::locationRequestFastestInterval, setter = { Prefs.locationRequestFastestInterval = it } - ) { descRes = R.string.location_request_fastest_interval_description } + ) { + dependsOnLocationPermission() + descRes = R.string.location_request_fastest_interval_description + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2c771fb1..d60ec140 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -161,6 +161,7 @@ Replay Introduction Requires custom theme + Requires location permission Secure privacy Prohibit screenshots and interception of screen status and require fingerprint authentication