Skip to content

Instantly share code, notes, and snippets.

@mayowa-egbewunmi
Last active August 1, 2022 02:02
Show Gist options
  • Save mayowa-egbewunmi/8a067ceb97d3be62c67c9b3208cf3996 to your computer and use it in GitHub Desktop.
Save mayowa-egbewunmi/8a067ceb97d3be62c67c9b3208cf3996 to your computer and use it in GitHub Desktop.
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