From c51a6ab2fc842713dd9f35fba45dc54fc7845945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Muller?= Date: Tue, 10 Dec 2024 17:05:52 +0100 Subject: [PATCH] Make TalkBack inform about the selected item --- .../main/java/ch/srgssr/pillarbox/demo/MainNavigation.kt | 2 ++ .../java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt | 6 +++++- .../ch/srgssr/pillarbox/demo/ui/settings/AppSettingsView.kt | 6 +++++- .../showcases/playlists/CustomPlaybackSettingsShowcase.kt | 6 +++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/MainNavigation.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/MainNavigation.kt index 0fcf41e9b..274b6cb75 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/MainNavigation.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/MainNavigation.kt @@ -35,6 +35,7 @@ import androidx.compose.ui.semantics.CollectionInfo import androidx.compose.ui.semantics.CollectionItemInfo import androidx.compose.ui.semantics.collectionInfo import androidx.compose.ui.semantics.collectionItemInfo +import androidx.compose.ui.semantics.selected import androidx.compose.ui.semantics.semantics import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.DpOffset @@ -239,6 +240,7 @@ private fun ListsMenu( isMenuVisible = false }, modifier = Modifier.semantics { + selected = isSelected collectionItemInfo = CollectionItemInfo( rowIndex = (index * servers.size) + envIndex, rowSpan = 1, diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt index e86348032..30be08894 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt @@ -62,6 +62,7 @@ import androidx.compose.ui.semantics.CollectionItemInfo import androidx.compose.ui.semantics.collectionInfo import androidx.compose.ui.semantics.collectionItemInfo import androidx.compose.ui.semantics.onClick +import androidx.compose.ui.semantics.selected import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString @@ -304,6 +305,8 @@ private fun SearchInput( ) ) { bus.forEachIndexed { index, bu -> + val isSelected = selectedBu == bu + DropdownMenuItem( text = { BuLabel(bu) }, onClick = { @@ -311,6 +314,7 @@ private fun SearchInput( showBuSelector = false }, modifier = Modifier.semantics { + selected = isSelected collectionItemInfo = CollectionItemInfo( rowIndex = index, rowSpan = 1, @@ -318,7 +322,7 @@ private fun SearchInput( columnSpan = 1, ) }, - trailingIcon = if (selectedBu == bu) { + trailingIcon = if (isSelected) { { Icon( imageVector = Icons.Default.Check, diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/settings/AppSettingsView.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/settings/AppSettingsView.kt index 81801f031..b605ce3d0 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/settings/AppSettingsView.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/settings/AppSettingsView.kt @@ -50,6 +50,7 @@ import androidx.compose.ui.semantics.collectionInfo import androidx.compose.ui.semantics.collectionItemInfo import androidx.compose.ui.semantics.onClick import androidx.compose.ui.semantics.role +import androidx.compose.ui.semantics.selected import androidx.compose.ui.semantics.semantics import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.DpOffset @@ -298,6 +299,8 @@ private fun DropdownSetting( offset = dropdownOffset, ) { entries.forEachIndexed { index, entry -> + val isSelected = entry == selectedEntry + DropdownMenuItem( text = { Text(text = entry.toString()) }, onClick = { @@ -305,6 +308,7 @@ private fun DropdownSetting( showDropdownMenu = false }, modifier = Modifier.semantics { + selected = isSelected collectionItemInfo = CollectionItemInfo( rowIndex = index, rowSpan = 1, @@ -313,7 +317,7 @@ private fun DropdownSetting( ) }, leadingIcon = { - AnimatedVisibility(entry == selectedEntry) { + AnimatedVisibility(isSelected) { Icon( imageVector = Icons.Default.Check, contentDescription = null, diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/showcases/playlists/CustomPlaybackSettingsShowcase.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/showcases/playlists/CustomPlaybackSettingsShowcase.kt index 8fc064970..e4c4df3c8 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/showcases/playlists/CustomPlaybackSettingsShowcase.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/showcases/playlists/CustomPlaybackSettingsShowcase.kt @@ -42,6 +42,7 @@ import androidx.compose.ui.semantics.CollectionInfo import androidx.compose.ui.semantics.CollectionItemInfo import androidx.compose.ui.semantics.collectionInfo import androidx.compose.ui.semantics.collectionItemInfo +import androidx.compose.ui.semantics.selected import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.DpOffset import androidx.lifecycle.compose.LifecycleResumeEffect @@ -142,6 +143,8 @@ fun CustomPlaybackSettingsShowcase( offset = menuOffset, ) { repeatModes.forEachIndexed { index, (repeatMode, repeatModeLabel) -> + val isSelected = index == selectedRepeatModeIndex + DropdownMenuItem( text = { Text(text = repeatModeLabel) }, onClick = { @@ -150,6 +153,7 @@ fun CustomPlaybackSettingsShowcase( showRepeatModeMenu = false }, modifier = Modifier.semantics { + selected = isSelected collectionItemInfo = CollectionItemInfo( rowIndex = index, rowSpan = 1, @@ -158,7 +162,7 @@ fun CustomPlaybackSettingsShowcase( ) }, leadingIcon = { - AnimatedVisibility(index == selectedRepeatModeIndex) { + AnimatedVisibility(isSelected) { Icon( imageVector = Icons.Default.Check, contentDescription = null,