From c0fb62af9d937e8f1e269a109a402e466d9bffde Mon Sep 17 00:00:00 2001 From: Florent Maitre Date: Mon, 7 Aug 2023 16:20:26 +0200 Subject: [PATCH] [#506] The number of search results is now vocalized --- .../orange/ods/app/ui/search/SearchScreen.kt | 27 +++++++++++++++++++ app/src/main/res/values/strings.xml | 5 ++++ changelog.md | 7 ++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/orange/ods/app/ui/search/SearchScreen.kt b/app/src/main/java/com/orange/ods/app/ui/search/SearchScreen.kt index 0f89e9829..33d157b8b 100644 --- a/app/src/main/java/com/orange/ods/app/ui/search/SearchScreen.kt +++ b/app/src/main/java/com/orange/ods/app/ui/search/SearchScreen.kt @@ -12,19 +12,27 @@ package com.orange.ods.app.ui.search import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.painter.ColorPainter import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.LiveRegionMode +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.liveRegion +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.unit.dp import com.orange.ods.app.R import com.orange.ods.app.ui.LocalOdsGuideline import com.orange.ods.app.ui.MainDestinations @@ -132,6 +140,25 @@ fun SearchScreen( modifier = Modifier .fillMaxWidth() ) { + item { + // The aim of this item is to vocalize the number of search results + // This should be done on LazyColumn with liveRegion and contentDescription, but doing so vocalizes the entire content of the column + // Thus we add the text below in order to vocalize the number of search results only + // The text is not empty with a 1dp height otherwise it is not vocalized, and alpha is set to 0 to make it invisible when navigating with TalkBack + Text(" ", modifier = Modifier + .height(1.dp) + .alpha(0f) + .semantics { + liveRegion = LiveRegionMode.Polite + contentDescription = with(context.resources) { + if (searchResults.isNotEmpty()) { + getQuantityString(R.plurals.search_result_count_content_description, searchResults.count(), searchResults.count()) + } else { + getString(R.string.search_no_result_content_description) + } + } + }) + } items(searchResults) { item -> val openDialog = remember { mutableStateOf(false) } val guidelineColor = filteredGuidelineColors.firstOrNull { guidelineColor -> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 844b9f14d..9762f0262 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -392,5 +392,10 @@ Search Search icon + + There is %1$d result + There are %1$d results + + There are no results \ No newline at end of file diff --git a/changelog.md b/changelog.md index 40537e8d5..0388c45ac 100644 --- a/changelog.md +++ b/changelog.md @@ -9,15 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- [\All\] Use Compose BOM and update Kotlin and Gradle versions ([#578](https://github.com/Orange-OpenSource/ods-android/issues/578)) +- \[All\] Use Compose BOM and update Kotlin and Gradle versions ([#578](https://github.com/Orange-OpenSource/ods-android/issues/578)) - \[Lib\] Replace composable parameter of `OdsDropdownMenu` with a list of `OdsDropdownMenuItem` ([#572](https://github.com/Orange-OpenSource/ods-android/issues/572)) - \[Lib\] Update `OdsTopAppBar` and `OdsLargeTopAppBar` APIs ([#572](https://github.com/Orange-OpenSource/ods-android/issues/572)) - \[Lib\] Update `OdsBottomNavigation` API ([#588](https://github.com/Orange-OpenSource/ods-android/issues/588)) ### Fixed -- [\App\] Screen displayed on filter chip variant click was not the good one ([#580](https://github.com/Orange-OpenSource/ods-android/issues/580)) -- [\App\] Fix a bug where `OdsListItem` text color did not update when switching between light and dark modes in text field demo ([#578](https://github.com/Orange-OpenSource/ods-android/issues/578)) +- \[App\] Screen displayed on filter chip variant click was not the good one ([#580](https://github.com/Orange-OpenSource/ods-android/issues/580)) +- \[App\] Fix a bug where `OdsListItem` text color did not update when switching between light and dark modes in text field demo ([#578](https://github.com/Orange-OpenSource/ods-android/issues/578)) +- \[App\] The number of search results is now vocalized ([#506](https://github.com/Orange-OpenSource/ods-android/issues/506)) ## [0.14.0](https://github.com/Orange-OpenSource/ods-android/compare/0.13.0...0.14.0) - 2023-07-12