-
-
Save mayowa-egbewunmi/33cd7cdef4a869eab2acd971bf9c8ccf 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
@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