@@ -20,9 +20,13 @@ import androidx.compose.ui.Alignment
2020import androidx.compose.ui.Modifier
2121import androidx.compose.ui.graphics.StrokeCap
2222import 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
2326import androidx.compose.ui.unit.dp
2427import io.element.android.compound.theme.ElementTheme
2528import io.element.android.compound.tokens.generated.CompoundIcons
29+ import io.element.android.features.poll.api.R
2630import io.element.android.libraries.designsystem.preview.ElementPreview
2731import io.element.android.libraries.designsystem.preview.PreviewsDayNight
2832import io.element.android.libraries.designsystem.theme.components.Icon
@@ -32,14 +36,40 @@ import io.element.android.libraries.designsystem.theme.progressIndicatorTrackCol
3236import io.element.android.libraries.designsystem.toEnabledColor
3337import io.element.android.libraries.designsystem.utils.CommonDrawables
3438import io.element.android.libraries.ui.strings.CommonPlurals
39+ import io.element.android.libraries.ui.strings.CommonStrings
3540
3641@Composable
3742internal 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 )
0 commit comments