From 74f7281a60420a696a86eecc93ec343b6a2a8130 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 23 Jun 2021 12:17:06 -0700 Subject: [PATCH] better dialog for background location --- app/src/main/java/com/geeksville/mesh/MainActivity.kt | 11 ++++++----- app/src/main/res/values/strings.xml | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index 8765c24e..524a3cef 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -249,7 +249,7 @@ class MainActivity : AppCompatActivity(), Logging, /** Ask the user to grant background location permission */ - fun requestBackgroundPermission() = requestPermission(getBackgroundPermissions()) + fun requestBackgroundPermission() = requestPermission(getBackgroundPermissions(), false) /** * @return a localized string warning user about missing permissions. Or null if everything is find @@ -280,10 +280,11 @@ class MainActivity : AppCompatActivity(), Logging, } /** Possibly prompt user to grant permissions + * @param shouldShowDialog usually true, but in cases where we've already shown a dialog elsewhere we skip it. * * @return true if we already have the needed permissions */ - private fun requestPermission(missingPerms: List = getMinimumPermissions()): Boolean = + private fun requestPermission(missingPerms: List = getMinimumPermissions(), shouldShowDialog: Boolean = true): Boolean = if (missingPerms.isNotEmpty()) { val shouldShow = missingPerms.filter { ActivityCompat.shouldShowRequestPermissionRationale(this, it) @@ -299,7 +300,7 @@ class MainActivity : AppCompatActivity(), Logging, ) } - if (shouldShow.isNotEmpty()) { + if (shouldShow.isNotEmpty() && shouldShowDialog) { // DID_REQUEST_PERM is an // app-defined int constant. The callback method gets the // result of the request. @@ -308,10 +309,10 @@ class MainActivity : AppCompatActivity(), Logging, MaterialAlertDialogBuilder(this) .setTitle(getString(R.string.required_permissions)) .setMessage(getMissingMessage()) - .setNeutralButton("Cancel (no radio access)") { _, _ -> + .setNeutralButton(R.string.cancel_no_radio) { _, _ -> error("User bailed due to permissions") } - .setPositiveButton("Allow (will show dialog)") { _, _ -> + .setPositiveButton(R.string.allow_will_show) { _, _ -> doRequest() } .show() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index debdce91..7e7f9e20 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -110,7 +110,9 @@ Choose theme Background location access required Show system settings - In order to enable this feature, you must grant this application "allow location access all the time" permission. This allows meshtastic to read your location while the application is in the background, so that it can send your location to other members of your mesh. + In order to enable this feature, you must grant "allow location access all the time" permission.\n\nThis allows meshtastic to read your location while the application is in the background, so that it can send your location to other members of your mesh. Required permissions location + Cancel (no radio access) + Allow (will show dialog)