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