From 300b246f011850b958af67d51f44617c553d639f Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Thu, 11 Jan 2024 17:20:57 -0300 Subject: [PATCH] Hook Search Action to existing logic * Show/hide if search is supported * Open Reader search screen --- .../android/ui/reader/ReaderFragment.kt | 3 +- .../ui/reader/viewmodels/ReaderViewModel.kt | 2 ++ .../reader/views/compose/ReaderTopAppBar.kt | 28 +++++++++++-------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt index 1ee55879d14b..c26aeae912f3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt @@ -145,7 +145,8 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider, onMenuItemClick = viewModel::onTopBarMenuItemClick, onFilterClick = ::tryOpenFilterList, onClearFilterClick = ::clearFilter, - onSearchClick = {} + isSearchVisible = state.isSearchActionVisible, + onSearchClick = viewModel::onSearchActionClicked, ) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt index 145b4171aaaa..bcbdd5ceb700 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt @@ -389,6 +389,7 @@ class ReaderViewModel @Inject constructor( menuItems = menuItems, selectedItem = selectedItem, filterUiState = filterUiState, + isSearchActionVisible = isSearchSupported(), ) ) } @@ -515,6 +516,7 @@ class ReaderViewModel @Inject constructor( val menuItems: List, val selectedItem: MenuElementData.Item.Single, val filterUiState: FilterUiState? = null, + val isSearchActionVisible: Boolean = false, ) { data class FilterUiState( val blogsFilterCount: Int, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt index 843fec5814c5..c1228c929565 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt @@ -54,7 +54,8 @@ fun ReaderTopAppBar( onMenuItemClick: (MenuElementData.Item.Single) -> Unit, onFilterClick: (ReaderFilterType) -> Unit, onClearFilterClick: () -> Unit, - onSearchClick: () -> Unit, + isSearchVisible: Boolean, + onSearchClick: () -> Unit = {}, ) { var selectedItem by remember { mutableStateOf(topBarUiState.selectedItem) } var isFilterShown by remember { mutableStateOf(topBarUiState.filterUiState != null) } @@ -124,17 +125,19 @@ fun ReaderTopAppBar( } } Spacer(Modifier.width(Margin.ExtraSmall.value)) - IconButton( - modifier = Modifier.align(Alignment.CenterVertically), - onClick = { onSearchClick() } - ) { - Icon( - painter = painterResource(R.drawable.ic_magnifying_glass_16dp), - contentDescription = stringResource( - R.string.reader_search_content_description - ), - tint = MaterialTheme.colors.onSurface, - ) + if (isSearchVisible) { + IconButton( + modifier = Modifier.align(Alignment.CenterVertically), + onClick = { onSearchClick() } + ) { + Icon( + painter = painterResource(R.drawable.ic_magnifying_glass_16dp), + contentDescription = stringResource( + R.string.reader_search_content_description + ), + tint = MaterialTheme.colors.onSurface, + ) + } } } } @@ -225,6 +228,7 @@ fun ReaderTopAppBarPreview() { }, onFilterClick = {}, onClearFilterClick = {}, + isSearchVisible = true, onSearchClick = {}, ) }