Skip to content

Commit

Permalink
Merge pull request #153 from MohamedRejeb/0.5.x
Browse files Browse the repository at this point in the history
Add PermissionStatus.isNotGranted and PermissionStatus.isDenied helpers
  • Loading branch information
MohamedRejeb authored Aug 20, 2024
2 parents f73de15 + 1234173 commit 7286941
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 7286941

Please sign in to comment.