-
-
Save mayowa-egbewunmi/8a067ceb97d3be62c67c9b3208cf3996 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 PermissionsHandler { | |
private fun onPermissionsStateUpdated(permissionState: MultiplePermissionsState) { | |
_state.update { it.copy(multiplePermissionsState = permissionState) } | |
} | |
private fun onPermissionGranted() { | |
_state.update { it.copy(permissionAction = Action.NO_ACTION) } | |
} | |
private fun onPermissionDenied() { | |
_state.update { it.copy(permissionAction = Action.NO_ACTION) } | |
} | |
private fun onPermissionNeverShowAgain() { | |
_state.update { | |
it.copy(permissionAction = Action.SHOW_NEVER_ASK_AGAIN) | |
} | |
} | |
private fun onPermissionRequired() { | |
_state.value.multiplePermissionsState?.let { | |
val permissionAction = | |
if (!it.allPermissionsGranted && !it.shouldShowRationale && !it.permissionRequested) { | |
Action.REQUEST_PERMISSION | |
} else if (!it.allPermissionsGranted && it.shouldShowRationale) { | |
Action.SHOW_RATIONALE | |
} else { | |
Action.SHOW_NEVER_ASK_AGAIN | |
} | |
_state.update { it.copy(permissionAction = permissionAction) } | |
} | |
} | |
private fun onPermissionRationaleOkTapped() { | |
_state.update { it.copy(permissionAction = Action.REQUEST_PERMISSION) } | |
} | |
private fun onPermissionDismissTapped() { | |
_state.update { it.copy(permissionAction = Action.NO_ACTION) } | |
} | |
private fun onPermissionSettingsTapped() { | |
_state.update { it.copy(permissionAction = Action.NO_ACTION) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment