if -> when

This commit is contained in:
Benoit Marty 2023-04-07 15:30:09 +02:00 committed by Benoit Marty
parent 40660ca317
commit 68fb2bd2eb

View file

@ -32,48 +32,52 @@ fun PermissionsView(
) { ) {
if (state.showDialog.not()) return if (state.showDialog.not()) return
if (state.permissionGranted) { when {
// Notification Granted, nothing to do state.permissionGranted -> {
} else if (state.permissionAlreadyDenied) { // Notification Granted, nothing to do
// In this case, tell the user to go to the settings }
ConfirmationDialog( state.permissionAlreadyDenied -> {
modifier = modifier, // In this case, tell the user to go to the settings
title = "System", ConfirmationDialog(
content = "In order to let the application display notification, please grant the permission to the system settings", modifier = modifier,
submitText = "Open settings", title = "System",
onSubmitClicked = { content = "In order to let the application display notification, please grant the permission to the system settings",
state.eventSink.invoke(PermissionsEvents.CloseDialog) submitText = "Open settings",
openSystemSettings() onSubmitClicked = {
}, state.eventSink.invoke(PermissionsEvents.CloseDialog)
onDismiss = { state.eventSink.invoke(PermissionsEvents.CloseDialog) }, openSystemSettings()
) },
} else { onDismiss = { state.eventSink.invoke(PermissionsEvents.CloseDialog) },
val textToShow = if (state.shouldShowRationale) { )
// TODO Move to state }
// If the user has denied the permission but the rationale can be shown, else -> {
// then gently explain why the app requires this permission val textToShow = if (state.shouldShowRationale) {
// permissions_rationale_msg_notification // TODO Move to state
"To be able to receive notifications, please grant the permission. Else you will not be able to be alerted if you've got new messages." // If the user has denied the permission but the rationale can be shown,
} else { // then gently explain why the app requires this permission
// TODO Move to state // permissions_rationale_msg_notification
// If it's the first time the user lands on this feature, or the user "To be able to receive notifications, please grant the permission. Else you will not be able to be alerted if you've got new messages."
// doesn't want to be asked again for this permission, explain that the } else {
// permission is required // TODO Move to state
"To be able to receive notifications, please grant the permission." // If it's the first time the user lands on this feature, or the user
// doesn't want to be asked again for this permission, explain that the
// permission is required
"To be able to receive notifications, please grant the permission."
}
ConfirmationDialog(
modifier = modifier,
title = "Notifications",
content = textToShow,
submitText = "Request permission",
onSubmitClicked = {
state.eventSink.invoke(PermissionsEvents.OpenSystemDialog)
},
onCancelClicked = {
state.eventSink.invoke(PermissionsEvents.CloseDialog)
},
onDismiss = {}
)
} }
ConfirmationDialog(
modifier = modifier,
title = "Notifications",
content = textToShow,
submitText = "Request permission",
onSubmitClicked = {
state.eventSink.invoke(PermissionsEvents.OpenSystemDialog)
},
onCancelClicked = {
state.eventSink.invoke(PermissionsEvents.CloseDialog)
},
onDismiss = {}
)
} }
} }