Skip to content

Instantly share code, notes, and snippets.

@oussama-dz
Created May 23, 2023 17:40
Show Gist options
  • Save oussama-dz/c4a80b2005a54aa3ff2c886f81489cd2 to your computer and use it in GitHub Desktop.
Save oussama-dz/c4a80b2005a54aa3ff2c886f81489cd2 to your computer and use it in GitHub Desktop.
An alert dialog composable to be shown when the user refuses to grant a permission.
@Composable
fun PermissionAlertDialog(
neededPermission: NeededPermission,
isPermissionDeclined: Boolean,
onDismiss: () -> Unit,
onOkClick: () -> Unit,
onGoToAppSettingsClick: () -> Unit,
) {
AlertDialog(
onDismissRequest = onDismiss,
buttons = {
Column(
modifier = Modifier
.fillMaxWidth()
) {
Divider(color = Color.LightGray)
Text(
text = if (isPermissionDeclined) "Go to app setting" else "OK",
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.clickable {
if (isPermissionDeclined)
onGoToAppSettingsClick()
else
onOkClick()
}
.padding(16.dp)
)
}
},
title = {
Text(
text = neededPermission.title,
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
)
},
text = {
Text(
text = neededPermission.permissionTextProvider(isPermissionDeclined),
)
},
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment