refactor: improve record list accessibility
This commit is contained in:
@@ -11,23 +11,42 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.clearAndSetSemantics
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import bzh.ajaury.chombev.core.model.Phrase
|
||||
import bzh.ajaury.chombev.core.model.Record
|
||||
import bzh.ajaury.chombev.resources.generated.resources.Res
|
||||
import bzh.ajaury.chombev.resources.generated.resources.records_chapter_action_description
|
||||
import bzh.ajaury.chombev.resources.generated.resources.records_chapter_number
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@Composable
|
||||
fun RecordView(
|
||||
record: Record,
|
||||
onClick: () -> Unit = {},
|
||||
) {
|
||||
val chapterNumber = stringResource(Res.string.records_chapter_number, record.index)
|
||||
val rowDescription =
|
||||
listOfNotNull(chapterNumber, record.title.transcription, record.title.translation)
|
||||
.joinToString(separator = ", ")
|
||||
|
||||
Row(
|
||||
modifier =
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { onClick() }
|
||||
.padding(16.dp),
|
||||
.clickable(
|
||||
role = Role.Button,
|
||||
onClickLabel = stringResource(Res.string.records_chapter_action_description),
|
||||
) {
|
||||
onClick()
|
||||
}.padding(16.dp)
|
||||
.clearAndSetSemantics {
|
||||
contentDescription = rowDescription
|
||||
},
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
@@ -70,3 +89,23 @@ private fun RecordViewPreview() {
|
||||
onClick = {},
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun RecordViewWithoutTranslationPreview() {
|
||||
RecordView(
|
||||
record =
|
||||
Record(
|
||||
id = 1,
|
||||
index = 1,
|
||||
emoji = "🙏",
|
||||
title = Phrase(
|
||||
transcription = "Sample Record",
|
||||
translation = null,
|
||||
),
|
||||
audioResourcePath = "files/Chom_bev_01.ogg",
|
||||
subtitleResourcePath = "files/Chom_bev_01_st_bzh.lrc",
|
||||
),
|
||||
onClick = {},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user