Skip to content

Commit d15a352

Browse files
committed
Improve accessibility of Poll answers.
1 parent 148b3d9 commit d15a352

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

features/poll/api/src/main/kotlin/io/element/android/features/poll/api/pollcontent/PollAnswerView.kt

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ import androidx.compose.ui.Alignment
2020
import androidx.compose.ui.Modifier
2121
import androidx.compose.ui.graphics.StrokeCap
2222
import androidx.compose.ui.res.pluralStringResource
23+
import androidx.compose.ui.res.stringResource
24+
import androidx.compose.ui.semantics.clearAndSetSemantics
25+
import androidx.compose.ui.semantics.contentDescription
2326
import androidx.compose.ui.unit.dp
2427
import io.element.android.compound.theme.ElementTheme
2528
import io.element.android.compound.tokens.generated.CompoundIcons
29+
import io.element.android.features.poll.api.R
2630
import io.element.android.libraries.designsystem.preview.ElementPreview
2731
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
2832
import io.element.android.libraries.designsystem.theme.components.Icon
@@ -32,14 +36,40 @@ import io.element.android.libraries.designsystem.theme.progressIndicatorTrackCol
3236
import io.element.android.libraries.designsystem.toEnabledColor
3337
import io.element.android.libraries.designsystem.utils.CommonDrawables
3438
import io.element.android.libraries.ui.strings.CommonPlurals
39+
import io.element.android.libraries.ui.strings.CommonStrings
3540

3641
@Composable
3742
internal fun PollAnswerView(
3843
answerItem: PollAnswerItem,
3944
modifier: Modifier = Modifier,
4045
) {
46+
val nbVotesText = pluralStringResource(
47+
id = CommonPlurals.common_poll_votes_count,
48+
count = answerItem.votesCount,
49+
answerItem.votesCount,
50+
)
51+
val a11yText = buildString {
52+
val sentenceDelimiter = stringResource(CommonStrings.common_sentence_delimiter)
53+
append(answerItem.answer.text.removeSuffix("."))
54+
if (answerItem.showVotes) {
55+
append(sentenceDelimiter)
56+
append(nbVotesText)
57+
if (answerItem.votesCount != 0) {
58+
append(sentenceDelimiter)
59+
append(stringResource(R.string.a11y_polls_percent_of_total, (answerItem.percentage * 100).toInt()))
60+
}
61+
if (answerItem.isWinner) {
62+
append(sentenceDelimiter)
63+
append(stringResource(R.string.a11y_polls_winning_answer))
64+
}
65+
}
66+
}
4167
Row(
42-
modifier = modifier.fillMaxWidth(),
68+
modifier = modifier
69+
.fillMaxWidth()
70+
.clearAndSetSemantics {
71+
contentDescription = a11yText
72+
},
4373
) {
4474
Icon(
4575
imageVector = if (answerItem.isSelected) {
@@ -70,11 +100,6 @@ internal fun PollAnswerView(
70100
style = if (answerItem.isWinner) ElementTheme.typography.fontBodyLgMedium else ElementTheme.typography.fontBodyLgRegular,
71101
)
72102
if (answerItem.showVotes) {
73-
val text = pluralStringResource(
74-
id = CommonPlurals.common_poll_votes_count,
75-
count = answerItem.votesCount,
76-
answerItem.votesCount
77-
)
78103
Row(
79104
modifier = Modifier.align(Alignment.Bottom),
80105
verticalAlignment = Alignment.CenterVertically,
@@ -87,13 +112,13 @@ internal fun PollAnswerView(
87112
)
88113
Spacer(modifier = Modifier.width(2.dp))
89114
Text(
90-
text = text,
115+
text = nbVotesText,
91116
style = ElementTheme.typography.fontBodySmMedium,
92117
color = ElementTheme.colors.textPrimary,
93118
)
94119
} else {
95120
Text(
96-
text = text,
121+
text = nbVotesText,
97122
style = ElementTheme.typography.fontBodySmRegular,
98123
color = ElementTheme.colors.textSecondary,
99124
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
3+
<string name="a11y_polls_percent_of_total">"%1$d percent of total votes"</string>
4+
<string name="a11y_polls_winning_answer">"This is the winning answer"</string>
5+
</resources>

libraries/ui-strings/src/main/res/values/localazy.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ Reason: %1$s."</string>
259259
<string name="common_sending">"Sending…"</string>
260260
<string name="common_sending_failed">"Sending failed"</string>
261261
<string name="common_sent">"Sent"</string>
262+
<string name="common_sentence_delimiter">". "</string>
262263
<string name="common_server_not_supported">"Server not supported"</string>
263264
<string name="common_server_url">"Server URL"</string>
264265
<string name="common_settings">"Settings"</string>

tools/localazy/config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@
242242
"screen_polls_history_.*"
243243
]
244244
},
245+
{
246+
"name" : ":features:poll:api",
247+
"includeRegex" : [
248+
"a11y\\.polls\\..*"
249+
]
250+
},
245251
{
246252
"name" : ":features:securebackup:impl",
247253
"includeRegex" : [

0 commit comments

Comments
 (0)