-
-
Save hichamboushaba/91169767c24105990e65c14e2acec2f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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