Add strings for permission dialogs in Localazy

This commit is contained in:
Benoit Marty
2023-09-21 11:49:53 +02:00
parent 378d3ff9ab
commit 6d41542bd0
5 changed files with 44 additions and 50 deletions

View File

@@ -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)
}
}

View File

@@ -22,16 +22,18 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
open class PermissionsViewStateProvider : PreviewParameterProvider<PermissionsState> {
override val values: Sequence<PermissionsState>
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,

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="dialog_permission_camera">"In order to let the application use the camera, please grant the permission to the system settings."</string>
<string name="dialog_permission_generic">"Please grant the permission to the system settings."</string>
<string name="dialog_permission_microphone">"In order to let the application use the microphone, please grant the permission to the system settings."</string>
<string name="dialog_permission_notification">"In order to let the application display notification, please grant the permission to the system settings."</string>
</resources>

View File

@@ -44,6 +44,7 @@
<string name="action_no">"No"</string>
<string name="action_not_now">"Not now"</string>
<string name="action_ok">"OK"</string>
<string name="action_open_settings">"Open settings"</string>
<string name="action_open_with">"Open with"</string>
<string name="action_quick_reply">"Quick reply"</string>
<string name="action_quote">"Quote"</string>
@@ -105,6 +106,7 @@
<string name="common_password">"Password"</string>
<string name="common_people">"People"</string>
<string name="common_permalink">"Permalink"</string>
<string name="common_permission">"Permission"</string>
<string name="common_poll_total_votes">"Total votes: %1$s"</string>
<string name="common_poll_undisclosed_text">"Results will show after the poll has ended"</string>
<string name="common_privacy_policy">"Privacy policy"</string>

View File

@@ -50,6 +50,12 @@
"rich_text_editor.*"
]
},
{
"name": ":libraries:permissions:api",
"includeRegex": [
"dialog\\.permission_.*"
]
},
{
"name": ":libraries:androidutils",
"includeRegex": [