better dialog for background location

1.2-legacy
Kevin Hester 2021-06-23 12:17:06 -07:00
rodzic c5fc6bc319
commit 74f7281a60
2 zmienionych plików z 9 dodań i 6 usunięć

Wyświetl plik

@ -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<String> = getMinimumPermissions()): Boolean =
private fun requestPermission(missingPerms: List<String> = 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()

Wyświetl plik

@ -110,7 +110,9 @@
<string name="choose_theme_title">Choose theme</string>
<string name="background_required">Background location access required</string>
<string name="show_system_settings">Show system settings</string>
<string name="why_background_required">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.</string>
<string name="why_background_required">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.</string>
<string name="required_permissions">Required permissions</string>
<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>
</resources>