Skip to content

Instantly share code, notes, and snippets.

@hichamboushaba
Created November 16, 2021 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hichamboushaba/91169767c24105990e65c14e2acec2f3 to your computer and use it in GitHub Desktop.
Save hichamboushaba/91169767c24105990e65c14e2acec2f3 to your computer and use it in GitHub Desktop.
class LocationPermissionController(
private val permissionManager: PermissionManager,
private val activityProvider: ActivityProvider
) {
suspend fun requestLocationPermission(): Boolean {
if (permissionManager.hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) return true
val permissionStatus =
permissionManager.requestPermission(Manifest.permission.ACCESS_FINE_LOCATION)
return when (permissionStatus) {
is PermissionDenied -> {
if (permissionStatus.shouldShowRationale) {
if (showRationale()) requestLocationPermission() else false
} else {
showDenialSnackBar()
false
}
}
PermissionGranted -> true
}
}
private suspend fun showRationale(): Boolean {
// Show a dialog with to explain the need, and handle re-requesting the permission
}
private fun showDenialSnackBar() {
// Show a Snackbar to let the user know about the denial
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment