Add strings for permission dialogs in Localazy
This commit is contained in:
parent
378d3ff9ab
commit
6d41542bd0
5 changed files with 44 additions and 50 deletions
|
|
@ -16,12 +16,15 @@
|
||||||
|
|
||||||
package io.element.android.libraries.permissions.api
|
package io.element.android.libraries.permissions.api
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||||
import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog
|
import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog
|
||||||
import io.element.android.libraries.designsystem.preview.DayNightPreviews
|
import io.element.android.libraries.designsystem.preview.DayNightPreviews
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PermissionsView(
|
fun PermissionsView(
|
||||||
|
|
@ -31,52 +34,26 @@ fun PermissionsView(
|
||||||
) {
|
) {
|
||||||
if (state.showDialog.not()) return
|
if (state.showDialog.not()) return
|
||||||
|
|
||||||
when {
|
ConfirmationDialog(
|
||||||
state.permissionGranted -> {
|
modifier = modifier,
|
||||||
// Notification Granted, nothing to do
|
title = stringResource(id = CommonStrings.common_permission),
|
||||||
}
|
content = state.permission.toDialogContent(),
|
||||||
state.permissionAlreadyDenied -> {
|
submitText = stringResource(id = CommonStrings.action_open_settings),
|
||||||
// In this case, tell the user to go to the settings
|
onSubmitClicked = {
|
||||||
ConfirmationDialog(
|
state.eventSink.invoke(PermissionsEvents.CloseDialog)
|
||||||
modifier = modifier,
|
onOpenSystemSettings()
|
||||||
title = "System",
|
},
|
||||||
content = "In order to let the application display notification, please grant the permission to the system settings",
|
onDismiss = { state.eventSink.invoke(PermissionsEvents.CloseDialog) },
|
||||||
submitText = "Open settings",
|
)
|
||||||
onSubmitClicked = {
|
}
|
||||||
state.eventSink.invoke(PermissionsEvents.CloseDialog)
|
|
||||||
onOpenSystemSettings()
|
@Composable
|
||||||
},
|
private fun String.toDialogContent(): String {
|
||||||
onDismiss = { state.eventSink.invoke(PermissionsEvents.CloseDialog) },
|
return when (this) {
|
||||||
)
|
Manifest.permission.POST_NOTIFICATIONS -> stringResource(id = R.string.dialog_permission_notification)
|
||||||
}
|
Manifest.permission.CAMERA -> stringResource(id = R.string.dialog_permission_camera)
|
||||||
else -> {
|
Manifest.permission.RECORD_AUDIO -> stringResource(id = R.string.dialog_permission_microphone)
|
||||||
val textToShow = if (state.shouldShowRationale) {
|
else -> stringResource(id = R.string.dialog_permission_generic)
|
||||||
// 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 = {}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,16 +22,18 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||||
open class PermissionsViewStateProvider : PreviewParameterProvider<PermissionsState> {
|
open class PermissionsViewStateProvider : PreviewParameterProvider<PermissionsState> {
|
||||||
override val values: Sequence<PermissionsState>
|
override val values: Sequence<PermissionsState>
|
||||||
get() = sequenceOf(
|
get() = sequenceOf(
|
||||||
aPermissionsState(showDialog = true),
|
aPermissionsState(showDialog = true, permission = Manifest.permission.POST_NOTIFICATIONS),
|
||||||
aPermissionsState(showDialog = true).copy(shouldShowRationale = true),
|
aPermissionsState(showDialog = true, permission = Manifest.permission.CAMERA),
|
||||||
aPermissionsState(showDialog = true).copy(permissionAlreadyDenied = true),
|
aPermissionsState(showDialog = true, permission = Manifest.permission.RECORD_AUDIO),
|
||||||
|
aPermissionsState(showDialog = true, permission = Manifest.permission.INTERNET),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun aPermissionsState(
|
fun aPermissionsState(
|
||||||
showDialog: Boolean,
|
showDialog: Boolean,
|
||||||
|
permission: String = Manifest.permission.POST_NOTIFICATIONS
|
||||||
) = PermissionsState(
|
) = PermissionsState(
|
||||||
permission = Manifest.permission.INTERNET,
|
permission = permission,
|
||||||
permissionGranted = false,
|
permissionGranted = false,
|
||||||
shouldShowRationale = false,
|
shouldShowRationale = false,
|
||||||
showDialog = showDialog,
|
showDialog = showDialog,
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
<string name="action_no">"No"</string>
|
<string name="action_no">"No"</string>
|
||||||
<string name="action_not_now">"Not now"</string>
|
<string name="action_not_now">"Not now"</string>
|
||||||
<string name="action_ok">"OK"</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_open_with">"Open with"</string>
|
||||||
<string name="action_quick_reply">"Quick reply"</string>
|
<string name="action_quick_reply">"Quick reply"</string>
|
||||||
<string name="action_quote">"Quote"</string>
|
<string name="action_quote">"Quote"</string>
|
||||||
|
|
@ -105,6 +106,7 @@
|
||||||
<string name="common_password">"Password"</string>
|
<string name="common_password">"Password"</string>
|
||||||
<string name="common_people">"People"</string>
|
<string name="common_people">"People"</string>
|
||||||
<string name="common_permalink">"Permalink"</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_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_poll_undisclosed_text">"Results will show after the poll has ended"</string>
|
||||||
<string name="common_privacy_policy">"Privacy policy"</string>
|
<string name="common_privacy_policy">"Privacy policy"</string>
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,12 @@
|
||||||
"rich_text_editor.*"
|
"rich_text_editor.*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": ":libraries:permissions:api",
|
||||||
|
"includeRegex": [
|
||||||
|
"dialog\\.permission_.*"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": ":libraries:androidutils",
|
"name": ":libraries:androidutils",
|
||||||
"includeRegex": [
|
"includeRegex": [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue