From 8ce4f97e5183d0d119feef3ff7c7f8a002464204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20St=C3=A4hli?= Date: Wed, 29 Nov 2023 15:06:07 +0100 Subject: [PATCH] Remove some duplicate code --- .../demo/tv/ui/integrationLayer/SearchView.kt | 40 ++++++++++--------- .../demo/ui/integrationLayer/SearchView.kt | 27 +++++-------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/integrationLayer/SearchView.kt b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/integrationLayer/SearchView.kt index 43155734b..46fd608cf 100644 --- a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/integrationLayer/SearchView.kt +++ b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/integrationLayer/SearchView.kt @@ -29,6 +29,7 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction @@ -188,32 +189,33 @@ private fun SearchInput( } @Composable -@OptIn(ExperimentalTvMaterial3Api::class) private fun NoResults( modifier: Modifier = Modifier ) { - Column( + StateMessage( modifier = modifier, - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Icon( - imageVector = Icons.Default.Block, - contentDescription = null, - modifier = Modifier.size(56.dp) - ) - - Text( - text = stringResource(R.string.no_results), - modifier = Modifier.padding(top = 8.dp) - ) - } + message = stringResource(R.string.no_results), + image = Icons.Default.Block + ) } @Composable -@OptIn(ExperimentalTvMaterial3Api::class) private fun NoContent( modifier: Modifier = Modifier +) { + StateMessage( + modifier = modifier, + message = stringResource(R.string.empty_search_query), + image = Icons.Default.Search + ) +} + +@Composable +@OptIn(ExperimentalTvMaterial3Api::class) +private fun StateMessage( + modifier: Modifier, + message: String, + image: ImageVector ) { Column( modifier = modifier, @@ -221,13 +223,13 @@ private fun NoContent( horizontalAlignment = Alignment.CenterHorizontally ) { Icon( - imageVector = Icons.Default.Search, + imageVector = image, contentDescription = null, modifier = Modifier.size(56.dp) ) Text( - text = stringResource(R.string.empty_search_query), + text = image, modifier = Modifier.padding(top = 8.dp) ) } diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchView.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchView.kt index a0aa17ec5..4280d8139 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchView.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchView.kt @@ -53,6 +53,7 @@ import androidx.compose.ui.draw.rotate import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.DpOffset @@ -280,39 +281,29 @@ private fun SearchInput( @Composable private fun NoContent(modifier: Modifier = Modifier) { - Column( - modifier = modifier, - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Icon( - imageVector = Icons.Default.Search, - contentDescription = null, - modifier = Modifier.size(56.dp) - ) - - Text( - text = stringResource(sharedR.string.empty_search_query), - modifier = Modifier.padding(top = MaterialTheme.paddings.small) - ) - } + StateMessage(modifier = modifier, message = stringResource(sharedR.string.empty_search_query), image = Icons.Default.Search) } @Composable private fun NoResult(modifier: Modifier = Modifier) { + StateMessage(modifier = modifier, message = stringResource(sharedR.string.no_results), image = Icons.Default.Block) +} + +@Composable +private fun StateMessage(modifier: Modifier, message: String, image: ImageVector) { Column( modifier = modifier, verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { Icon( - imageVector = Icons.Default.Block, + imageVector = image, contentDescription = null, modifier = Modifier.size(56.dp) ) Text( - text = stringResource(sharedR.string.no_results), + text = message, modifier = Modifier.padding(top = MaterialTheme.paddings.small) ) }