diff --git a/libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsView.kt b/libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsView.kt index a85f0b62a7..46758fc636 100644 --- a/libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsView.kt +++ b/libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsView.kt @@ -16,12 +16,15 @@ package io.element.android.libraries.permissions.api +import android.Manifest import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.PreviewParameter import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog import io.element.android.libraries.designsystem.preview.DayNightPreviews import io.element.android.libraries.designsystem.preview.ElementPreview +import io.element.android.libraries.ui.strings.CommonStrings @Composable fun PermissionsView( @@ -31,52 +34,26 @@ fun PermissionsView( ) { if (state.showDialog.not()) return - when { - state.permissionGranted -> { - // Notification Granted, nothing to do - } - state.permissionAlreadyDenied -> { - // In this case, tell the user to go to the settings - ConfirmationDialog( - modifier = modifier, - title = "System", - content = "In order to let the application display notification, please grant the permission to the system settings", - submitText = "Open settings", - onSubmitClicked = { - state.eventSink.invoke(PermissionsEvents.CloseDialog) - onOpenSystemSettings() - }, - onDismiss = { state.eventSink.invoke(PermissionsEvents.CloseDialog) }, - ) - } - else -> { - val textToShow = if (state.shouldShowRationale) { - // TODO Move to state - // If the user has denied the permission but the rationale can be shown, - // then gently explain why the app requires this permission - // permissions_rationale_msg_notification - "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." - } else { - // TODO Move to state - // 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.AskPermissionToUser) - }, - onCancelClicked = { - state.eventSink.invoke(PermissionsEvents.CloseDialog) - }, - onDismiss = {} - ) - } + ConfirmationDialog( + modifier = modifier, + title = stringResource(id = CommonStrings.common_permission), + content = state.permission.toDialogContent(), + submitText = stringResource(id = CommonStrings.action_open_settings), + onSubmitClicked = { + state.eventSink.invoke(PermissionsEvents.CloseDialog) + onOpenSystemSettings() + }, + onDismiss = { state.eventSink.invoke(PermissionsEvents.CloseDialog) }, + ) +} + +@Composable +private fun String.toDialogContent(): String { + return when (this) { + Manifest.permission.POST_NOTIFICATIONS -> stringResource(id = R.string.dialog_permission_notification) + Manifest.permission.CAMERA -> stringResource(id = R.string.dialog_permission_camera) + Manifest.permission.RECORD_AUDIO -> stringResource(id = R.string.dialog_permission_microphone) + else -> stringResource(id = R.string.dialog_permission_generic) } } diff --git a/libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsViewStateProvider.kt b/libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsViewStateProvider.kt index faa35f3c7f..2009ad0e85 100644 --- a/libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsViewStateProvider.kt +++ b/libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsViewStateProvider.kt @@ -22,16 +22,18 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider open class PermissionsViewStateProvider : PreviewParameterProvider { override val values: Sequence get() = sequenceOf( - aPermissionsState(showDialog = true), - aPermissionsState(showDialog = true).copy(shouldShowRationale = true), - aPermissionsState(showDialog = true).copy(permissionAlreadyDenied = true), + aPermissionsState(showDialog = true, permission = Manifest.permission.POST_NOTIFICATIONS), + aPermissionsState(showDialog = true, permission = Manifest.permission.CAMERA), + aPermissionsState(showDialog = true, permission = Manifest.permission.RECORD_AUDIO), + aPermissionsState(showDialog = true, permission = Manifest.permission.INTERNET), ) } fun aPermissionsState( showDialog: Boolean, + permission: String = Manifest.permission.POST_NOTIFICATIONS ) = PermissionsState( - permission = Manifest.permission.INTERNET, + permission = permission, permissionGranted = false, shouldShowRationale = false, showDialog = showDialog, diff --git a/libraries/permissions/api/src/main/res/values/localazy.xml b/libraries/permissions/api/src/main/res/values/localazy.xml new file mode 100644 index 0000000000..4397e7d343 --- /dev/null +++ b/libraries/permissions/api/src/main/res/values/localazy.xml @@ -0,0 +1,7 @@ + + + "In order to let the application use the camera, please grant the permission to the system settings." + "Please grant the permission to the system settings." + "In order to let the application use the microphone, please grant the permission to the system settings." + "In order to let the application display notification, please grant the permission to the system settings." + diff --git a/libraries/ui-strings/src/main/res/values/localazy.xml b/libraries/ui-strings/src/main/res/values/localazy.xml index 72a31d46b0..ce9f867ba1 100644 --- a/libraries/ui-strings/src/main/res/values/localazy.xml +++ b/libraries/ui-strings/src/main/res/values/localazy.xml @@ -44,6 +44,7 @@ "No" "Not now" "OK" + "Open settings" "Open with" "Quick reply" "Quote" @@ -105,6 +106,7 @@ "Password" "People" "Permalink" + "Permission" "Total votes: %1$s" "Results will show after the poll has ended" "Privacy policy" diff --git a/tools/localazy/config.json b/tools/localazy/config.json index c51e0f1eed..0d410fc9c4 100644 --- a/tools/localazy/config.json +++ b/tools/localazy/config.json @@ -50,6 +50,12 @@ "rich_text_editor.*" ] }, + { + "name": ":libraries:permissions:api", + "includeRegex": [ + "dialog\\.permission_.*" + ] + }, { "name": ":libraries:androidutils", "includeRegex": [