Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class PermissionsHandler {
private val _state = MutableStateFlow(State())
val state: StateFlow<State> = _state
fun onEvent(event: Event) {
when (event) {
Event.PermissionDenied -> onPermissionDenied()
Event.PermissionDismissTapped -> onPermissionDismissTapped()
Event.PermissionNeverAskAgain -> onPermissionNeverShowAgain()
Event.PermissionRationaleOkTapped -> onPermissionRationaleOkTapped()
Event.PermissionRequired -> onPermissionRequired()
Event.PermissionSettingsTapped -> onPermissionSettingsTapped()
Event.PermissionsGranted -> onPermissionGranted()
is Event.PermissionsStateUpdated -> onPermissionsStateUpdated(event.permissionsState)
}
}
data class State(
val multiplePermissionsState: MultiplePermissionsState? = null,
val permissionAction: Action = Action.NO_ACTION
)
sealed class Event {
object PermissionDenied : Event()
object PermissionsGranted : Event()
object PermissionSettingsTapped : Event()
object PermissionNeverAskAgain : Event()
object PermissionDismissTapped : Event()
object PermissionRationaleOkTapped : Event()
object PermissionRequired : Event()
data class PermissionsStateUpdated(val permissionsState: MultiplePermissionsState) :
Event()
}
enum class Action {
REQUEST_PERMISSION, SHOW_RATIONALE, SHOW_NEVER_ASK_AGAIN, NO_ACTION
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment