From b52e2e70f43d63b4163762501ffb8fb48309b941 Mon Sep 17 00:00:00 2001 From: David Carr Date: Mon, 23 Dec 2024 09:47:55 +0000 Subject: [PATCH] GOVUKAPP-1037: User removes all topics (#159) * Display empty selected topics message * Add onclick to feedback prompt widget semantics to ensure correct talkback announcement --- .../app/settings/ui/FeedbackPromptWidget.kt | 2 + .../app/topics/ui/widget/TopicsWidget.kt | 42 +++++++++++++++---- .../topics/src/main/res/values/strings.xml | 1 + 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/feature/settings/src/main/kotlin/uk/govuk/app/settings/ui/FeedbackPromptWidget.kt b/feature/settings/src/main/kotlin/uk/govuk/app/settings/ui/FeedbackPromptWidget.kt index b4d338ab..6f386307 100644 --- a/feature/settings/src/main/kotlin/uk/govuk/app/settings/ui/FeedbackPromptWidget.kt +++ b/feature/settings/src/main/kotlin/uk/govuk/app/settings/ui/FeedbackPromptWidget.kt @@ -6,6 +6,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.onClick import androidx.compose.ui.tooling.preview.Preview import uk.govuk.app.design.ui.component.HomeNavigationCard import uk.govuk.app.design.ui.theme.GovUkTheme @@ -26,6 +27,7 @@ fun FeedbackPromptWidget( .focusable() .clearAndSetSemantics { contentDescription = altText + onClick(label = null, action = null) }, isSelected = true ) diff --git a/feature/topics/src/main/kotlin/uk/govuk/app/topics/ui/widget/TopicsWidget.kt b/feature/topics/src/main/kotlin/uk/govuk/app/topics/ui/widget/TopicsWidget.kt index 4371afb8..2d0e22bb 100644 --- a/feature/topics/src/main/kotlin/uk/govuk/app/topics/ui/widget/TopicsWidget.kt +++ b/feature/topics/src/main/kotlin/uk/govuk/app/topics/ui/widget/TopicsWidget.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState @@ -16,6 +17,7 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.tooling.preview.Preview import androidx.hilt.navigation.compose.hiltViewModel import uk.govuk.app.design.ui.component.BodyBoldLabel +import uk.govuk.app.design.ui.component.BodyRegularLabel import uk.govuk.app.design.ui.component.CompactButton import uk.govuk.app.design.ui.component.Title3BoldLabel import uk.govuk.app.design.ui.theme.GovUkTheme @@ -89,15 +91,24 @@ private fun TopicsWidgetContent( } } - TopicsGrid( - topics = topics, - ) { modifier, topic -> - TopicVerticalCard( - icon = topic.icon, - title = topic.title, - onClick = { onTopicClick(topic.ref, topic.title) }, - modifier = modifier + if (topics.isEmpty()) { + BodyRegularLabel( + text = stringResource(R.string.empty_topics), + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding(vertical = GovUkTheme.spacing.small) ) + } else { + TopicsGrid( + topics = topics, + ) { modifier, topic -> + TopicVerticalCard( + icon = topic.icon, + title = topic.title, + onClick = { onTopicClick(topic.ref, topic.title) }, + modifier = modifier + ) + } } if (displayShowAll) { @@ -160,4 +171,19 @@ private fun TopicsWidgetPreview() { onAllClick = { } ) } +} + +@Preview(showBackground = true) +@Composable +private fun TopicsWidgetEmptyTopicsPreview() { + GovUkTheme { + TopicsWidgetContent( + topics = emptyList(), + isCustomised = true, + displayShowAll = true, + onTopicClick = { _, _ -> }, + onEditClick = { }, + onAllClick = { } + ) + } } \ No newline at end of file diff --git a/feature/topics/src/main/res/values/strings.xml b/feature/topics/src/main/res/values/strings.xml index 8e904a5c..ccb19c1b 100644 --- a/feature/topics/src/main/res/values/strings.xml +++ b/feature/topics/src/main/res/values/strings.xml @@ -21,6 +21,7 @@ Skip Removed Selected + No topics selected Benefits