Skip to content

Commit

Permalink
Add PermissionStatus.isNotGranted and PermissionStatus.isDenied helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb committed Aug 20, 2024
1 parent 68bc77f commit 1234173
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ annotation class ExperimentalPermissionsApi
sealed interface PermissionStatus {
data object Granted : PermissionStatus
data class Denied(
val shouldShowRationale: Boolean
val shouldShowRationale: Boolean,
) : PermissionStatus
}

Expand All @@ -26,12 +26,29 @@ sealed interface PermissionStatus {
val PermissionStatus.isGranted: Boolean
get() = this == PermissionStatus.Granted

/**
* `true` if the permission is not granted.
*/
@ExperimentalPermissionsApi
val PermissionStatus.isNotGranted: Boolean
get() = !isGranted

/**
* `true` if the permission is denied.
*/
@ExperimentalPermissionsApi
val PermissionStatus.isDenied: Boolean
get() = this is PermissionStatus.Denied

/**
* `true` if a rationale should be presented to the user.
*/
@ExperimentalPermissionsApi
val PermissionStatus.shouldShowRationale: Boolean
get() = when (this) {
PermissionStatus.Granted -> false
is PermissionStatus.Denied -> shouldShowRationale
is PermissionStatus.Granted ->
false

is PermissionStatus.Denied ->
shouldShowRationale
}

0 comments on commit 1234173

Please sign in to comment.