Skip to content

Instantly share code, notes, and snippets.

@mayowa-egbewunmi
Last active August 1, 2022 02:02
Show Gist options
  • Save mayowa-egbewunmi/33cd7cdef4a869eab2acd971bf9c8ccf to your computer and use it in GitHub Desktop.
Save mayowa-egbewunmi/33cd7cdef4a869eab2acd971bf9c8ccf to your computer and use it in GitHub Desktop.
@Composable
fun HandlePermissionAction(
action: PermissionsHandler.Action,
permissionStates: MultiplePermissionsState?,
@StringRes rationaleText: Int,
@StringRes neverAskAgainText: Int,
onOkTapped: () -> Unit,
onSettingsTapped: () -> Unit,
) {
val context = LocalContext.current
when (action) {
PermissionsHandler.Action.REQUEST_PERMISSION -> {
LaunchedEffect(true) {
permissionStates?.launchMultiplePermissionRequest()
}
}
PermissionsHandler.Action.SHOW_RATIONALE -> {
PermissionRationaleDialog(
message = stringResource(rationaleText),
onOkTapped = onOkTapped
)
}
PermissionsHandler.Action.SHOW_NEVER_ASK_AGAIN -> {
ShowGotoSettingsDialog(
title = stringResource(R.string.allow_permission),
message = stringResource(neverAskAgainText),
onSettingsTapped = {
onSettingsTapped()
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.parse("package:" + context.packageName)
context.startActivity(this)
}
},
)
}
PermissionsHandler.Action.NO_ACTION -> Unit
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment