From 1234173a983dedd8d3e01323b1eab6cf7acd0bde Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Tue, 20 Aug 2024 14:46:47 +0100 Subject: [PATCH] Add PermissionStatus.isNotGranted and PermissionStatus.isDenied helpers --- .../permissions/PermissionsUtil.kt | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/calf-permissions/src/commonMain/kotlin/com.mohamedrejeb.calf/permissions/PermissionsUtil.kt b/calf-permissions/src/commonMain/kotlin/com.mohamedrejeb.calf/permissions/PermissionsUtil.kt index 1e46053..325e4ba 100644 --- a/calf-permissions/src/commonMain/kotlin/com.mohamedrejeb.calf/permissions/PermissionsUtil.kt +++ b/calf-permissions/src/commonMain/kotlin/com.mohamedrejeb.calf/permissions/PermissionsUtil.kt @@ -15,7 +15,7 @@ annotation class ExperimentalPermissionsApi sealed interface PermissionStatus { data object Granted : PermissionStatus data class Denied( - val shouldShowRationale: Boolean + val shouldShowRationale: Boolean, ) : PermissionStatus } @@ -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 } \ No newline at end of file