|
|
|
@ -100,10 +100,10 @@ import com.google.samples.apps.nowinandroid.feature.search.R as searchR
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
internal fun SearchRoute(
|
|
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
|
onBackClick: () -> Unit,
|
|
|
|
|
onInterestsClick: () -> Unit,
|
|
|
|
|
onTopicClick: (String) -> Unit,
|
|
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
|
bookmarksViewModel: BookmarksViewModel = hiltViewModel(),
|
|
|
|
|
interestsViewModel: InterestsViewModel = hiltViewModel(),
|
|
|
|
|
searchViewModel: SearchViewModel = hiltViewModel(),
|
|
|
|
@ -114,36 +114,36 @@ internal fun SearchRoute(
|
|
|
|
|
val searchQuery by searchViewModel.searchQuery.collectAsStateWithLifecycle()
|
|
|
|
|
SearchScreen(
|
|
|
|
|
modifier = modifier,
|
|
|
|
|
onBackClick = onBackClick,
|
|
|
|
|
onClearRecentSearches = searchViewModel::clearRecentSearches,
|
|
|
|
|
onFollowButtonClick = interestsViewModel::followTopic,
|
|
|
|
|
onInterestsClick = onInterestsClick,
|
|
|
|
|
searchQuery = searchQuery,
|
|
|
|
|
recentSearchesUiState = recentSearchQueriesUiState,
|
|
|
|
|
searchResultUiState = searchResultUiState,
|
|
|
|
|
onSearchQueryChanged = searchViewModel::onSearchQueryChanged,
|
|
|
|
|
onSearchTriggered = searchViewModel::onSearchTriggered,
|
|
|
|
|
onTopicClick = onTopicClick,
|
|
|
|
|
onClearRecentSearches = searchViewModel::clearRecentSearches,
|
|
|
|
|
onNewsResourcesCheckedChanged = forYouViewModel::updateNewsResourceSaved,
|
|
|
|
|
onNewsResourceViewed = { bookmarksViewModel.setNewsResourceViewed(it, true) },
|
|
|
|
|
recentSearchesUiState = recentSearchQueriesUiState,
|
|
|
|
|
searchQuery = searchQuery,
|
|
|
|
|
searchResultUiState = searchResultUiState,
|
|
|
|
|
onFollowButtonClick = interestsViewModel::followTopic,
|
|
|
|
|
onBackClick = onBackClick,
|
|
|
|
|
onInterestsClick = onInterestsClick,
|
|
|
|
|
onTopicClick = onTopicClick,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
internal fun SearchScreen(
|
|
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
|
onBackClick: () -> Unit = {},
|
|
|
|
|
searchQuery: String = "",
|
|
|
|
|
recentSearchesUiState: RecentSearchQueriesUiState = RecentSearchQueriesUiState.Loading,
|
|
|
|
|
searchResultUiState: SearchResultUiState = SearchResultUiState.Loading,
|
|
|
|
|
onSearchQueryChanged: (String) -> Unit = {},
|
|
|
|
|
onSearchTriggered: (String) -> Unit = {},
|
|
|
|
|
onClearRecentSearches: () -> Unit = {},
|
|
|
|
|
onFollowButtonClick: (String, Boolean) -> Unit = { _, _ -> },
|
|
|
|
|
onInterestsClick: () -> Unit = {},
|
|
|
|
|
onNewsResourcesCheckedChanged: (String, Boolean) -> Unit = { _, _ -> },
|
|
|
|
|
onNewsResourceViewed: (String) -> Unit = {},
|
|
|
|
|
onSearchQueryChanged: (String) -> Unit = {},
|
|
|
|
|
onSearchTriggered: (String) -> Unit = {},
|
|
|
|
|
onFollowButtonClick: (String, Boolean) -> Unit = { _, _ -> },
|
|
|
|
|
onBackClick: () -> Unit = {},
|
|
|
|
|
onInterestsClick: () -> Unit = {},
|
|
|
|
|
onTopicClick: (String) -> Unit = {},
|
|
|
|
|
searchQuery: String = "",
|
|
|
|
|
recentSearchesUiState: RecentSearchQueriesUiState = RecentSearchQueriesUiState.Loading,
|
|
|
|
|
searchResultUiState: SearchResultUiState = SearchResultUiState.Loading,
|
|
|
|
|
) {
|
|
|
|
|
TrackScreenViewEvent(screenName = "Search")
|
|
|
|
|
Column(modifier = modifier) {
|
|
|
|
@ -177,8 +177,8 @@ internal fun SearchScreen(
|
|
|
|
|
is SearchResultUiState.Success -> {
|
|
|
|
|
if (searchResultUiState.isEmpty()) {
|
|
|
|
|
EmptySearchResultBody(
|
|
|
|
|
onInterestsClick = onInterestsClick,
|
|
|
|
|
searchQuery = searchQuery,
|
|
|
|
|
onInterestsClick = onInterestsClick,
|
|
|
|
|
)
|
|
|
|
|
if (recentSearchesUiState is RecentSearchQueriesUiState.Success) {
|
|
|
|
|
RecentSearchesBody(
|
|
|
|
@ -192,14 +192,14 @@ internal fun SearchScreen(
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
SearchResultBody(
|
|
|
|
|
searchQuery = searchQuery,
|
|
|
|
|
topics = searchResultUiState.topics,
|
|
|
|
|
onFollowButtonClick = onFollowButtonClick,
|
|
|
|
|
onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged,
|
|
|
|
|
onNewsResourceViewed = onNewsResourceViewed,
|
|
|
|
|
newsResources = searchResultUiState.newsResources,
|
|
|
|
|
onSearchTriggered = onSearchTriggered,
|
|
|
|
|
onTopicClick = onTopicClick,
|
|
|
|
|
newsResources = searchResultUiState.newsResources,
|
|
|
|
|
searchQuery = searchQuery,
|
|
|
|
|
onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged,
|
|
|
|
|
onNewsResourceViewed = onNewsResourceViewed,
|
|
|
|
|
onFollowButtonClick = onFollowButtonClick,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -210,8 +210,8 @@ internal fun SearchScreen(
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun EmptySearchResultBody(
|
|
|
|
|
onInterestsClick: () -> Unit,
|
|
|
|
|
searchQuery: String,
|
|
|
|
|
onInterestsClick: () -> Unit,
|
|
|
|
|
) {
|
|
|
|
|
Column(
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
|
@ -286,14 +286,14 @@ private fun SearchNotReadyBody() {
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
private fun SearchResultBody(
|
|
|
|
|
searchQuery: String,
|
|
|
|
|
topics: List<FollowableTopic>,
|
|
|
|
|
newsResources: List<UserNewsResource>,
|
|
|
|
|
onFollowButtonClick: (String, Boolean) -> Unit,
|
|
|
|
|
onNewsResourcesCheckedChanged: (String, Boolean) -> Unit,
|
|
|
|
|
onNewsResourceViewed: (String) -> Unit,
|
|
|
|
|
onSearchTriggered: (String) -> Unit,
|
|
|
|
|
onTopicClick: (String) -> Unit,
|
|
|
|
|
searchQuery: String = "",
|
|
|
|
|
onNewsResourcesCheckedChanged: (String, Boolean) -> Unit,
|
|
|
|
|
onNewsResourceViewed: (String) -> Unit,
|
|
|
|
|
onFollowButtonClick: (String, Boolean) -> Unit,
|
|
|
|
|
) {
|
|
|
|
|
val state = rememberLazyStaggeredGridState()
|
|
|
|
|
Box(
|
|
|
|
@ -392,9 +392,9 @@ private fun SearchResultBody(
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
private fun RecentSearchesBody(
|
|
|
|
|
recentSearchQueries: List<String>,
|
|
|
|
|
onClearRecentSearches: () -> Unit,
|
|
|
|
|
onRecentSearchClicked: (String) -> Unit,
|
|
|
|
|
recentSearchQueries: List<String>,
|
|
|
|
|
) {
|
|
|
|
|
Column {
|
|
|
|
|
Row(
|
|
|
|
@ -444,11 +444,11 @@ private fun RecentSearchesBody(
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
private fun SearchToolbar(
|
|
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
|
onBackClick: () -> Unit,
|
|
|
|
|
searchQuery: String,
|
|
|
|
|
onSearchQueryChanged: (String) -> Unit,
|
|
|
|
|
searchQuery: String = "",
|
|
|
|
|
onSearchTriggered: (String) -> Unit,
|
|
|
|
|
onBackClick: () -> Unit,
|
|
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
|
) {
|
|
|
|
|
Row(
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
@ -473,8 +473,8 @@ private fun SearchToolbar(
|
|
|
|
|
@OptIn(ExperimentalComposeUiApi::class)
|
|
|
|
|
@Composable
|
|
|
|
|
private fun SearchTextField(
|
|
|
|
|
onSearchQueryChanged: (String) -> Unit,
|
|
|
|
|
searchQuery: String,
|
|
|
|
|
onSearchQueryChanged: (String) -> Unit,
|
|
|
|
|
onSearchTriggered: (String) -> Unit,
|
|
|
|
|
) {
|
|
|
|
|
val focusRequester = remember { FocusRequester() }
|
|
|
|
@ -556,6 +556,7 @@ private fun SearchTextField(
|
|
|
|
|
private fun SearchToolbarPreview() {
|
|
|
|
|
NiaTheme {
|
|
|
|
|
SearchToolbar(
|
|
|
|
|
searchQuery = "",
|
|
|
|
|
onBackClick = {},
|
|
|
|
|
onSearchQueryChanged = {},
|
|
|
|
|
onSearchTriggered = {},
|
|
|
|
|