Skip to content

Commit

Permalink
Disable location settings when location permission isn't granted
Browse files Browse the repository at this point in the history
Currently the seekbar is still enabled, but an issue for KAU has been opened:
AllanWang/KAU#133
  • Loading branch information
Thames1990 committed Jan 26, 2018
1 parent 3452457 commit af330e4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
@@ -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
Expand All @@ -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<Int>.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)
Expand All @@ -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
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -161,6 +161,7 @@
<string name="replay_intro">Replay Introduction</string>

<string name="requires_custom_theme">Requires custom theme</string>
<string name="requires_location_permission">Requires location permission</string>

<string name="secure_app">Secure privacy</string>
<string name="secure_app_desc">Prohibit screenshots and interception of screen status and require fingerprint authentication</string>
Expand Down

0 comments on commit af330e4

Please sign in to comment.