Skip to content

Commit

Permalink
Hook Search Action to existing logic
Browse files Browse the repository at this point in the history
* Show/hide if search is supported
* Open Reader search screen
  • Loading branch information
Thomas Horta committed Jan 11, 2024
1 parent bb8988f commit 300b246
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ class ReaderViewModel @Inject constructor(
menuItems = menuItems,
selectedItem = selectedItem,
filterUiState = filterUiState,
isSearchActionVisible = isSearchSupported(),
)
)
}
Expand Down Expand Up @@ -515,6 +516,7 @@ class ReaderViewModel @Inject constructor(
val menuItems: List<MenuElementData>,
val selectedItem: MenuElementData.Item.Single,
val filterUiState: FilterUiState? = null,
val isSearchActionVisible: Boolean = false,
) {
data class FilterUiState(
val blogsFilterCount: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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,
)
}
}
}
}
Expand Down Expand Up @@ -225,6 +228,7 @@ fun ReaderTopAppBarPreview() {
},
onFilterClick = {},
onClearFilterClick = {},
isSearchVisible = true,
onSearchClick = {},
)
}
Expand Down

0 comments on commit 300b246

Please sign in to comment.