Tweak the SearchScreen with empty search results.

- Display the recent searches
- Tweak the styles to match the UI mock

Add missing useFilterNewsIds argument to search for the NewsResources.
fix_news_resource_query
Takeshi Hagikura 1 year ago
parent caf43361ec
commit 983831c890

@ -61,7 +61,7 @@ class DefaultSearchContentsRepository @Inject constructor(
.mapLatest { it.toSet() } .mapLatest { it.toSet() }
.distinctUntilChanged() .distinctUntilChanged()
.flatMapLatest { .flatMapLatest {
newsResourceDao.getNewsResources(filterNewsIds = it) newsResourceDao.getNewsResources(useFilterNewsIds = true, filterNewsIds = it)
} }
val topicsFlow = topicIds val topicsFlow = topicIds
.mapLatest { it.toSet() } .mapLatest { it.toSet() }

@ -102,6 +102,29 @@ class SearchScreenTest {
.assertIsDisplayed() .assertIsDisplayed()
} }
@Test
fun emptySearchResult_nonEmptyRecentSearches_emptySearchScreenAndRecentSearchesAreDisplayed() {
val recentSearches = listOf("kotlin")
composeTestRule.setContent {
SearchScreen(
searchResultUiState = SearchResultUiState.Success(),
recentSearchesUiState = RecentSearchQueriesUiState.Success(
recentQueries = recentSearches.map(::RecentSearchQuery),
),
)
}
composeTestRule
.onNodeWithText(tryAnotherSearchString)
.assertIsDisplayed()
composeTestRule
.onNodeWithContentDescription(clearRecentSearchesContentDesc)
.assertIsDisplayed()
composeTestRule
.onNodeWithText("kotlin")
.assertIsDisplayed()
}
@Test @Test
fun searchResultWithTopics_allTopicsAreVisible_followButtonsVisibleForTheNumOfFollowedTopics() { fun searchResultWithTopics_allTopicsAreVisible_followButtonsVisibleForTheNumOfFollowedTopics() {
composeTestRule.setContent { composeTestRule.setContent {

@ -63,10 +63,12 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withStyle import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
@ -147,6 +149,7 @@ internal fun SearchScreen(
SearchResultUiState.Loading, SearchResultUiState.Loading,
SearchResultUiState.LoadFailed, SearchResultUiState.LoadFailed,
-> Unit -> Unit
SearchResultUiState.EmptyQuery, SearchResultUiState.EmptyQuery,
-> { -> {
if (recentSearchesUiState is RecentSearchQueriesUiState.Success) { if (recentSearchesUiState is RecentSearchQueriesUiState.Success) {
@ -167,6 +170,16 @@ internal fun SearchScreen(
onInterestsClick = onInterestsClick, onInterestsClick = onInterestsClick,
searchQuery = searchQuery, searchQuery = searchQuery,
) )
if (recentSearchesUiState is RecentSearchQueriesUiState.Success) {
RecentSearchesBody(
onClearRecentSearches = onClearRecentSearches,
onRecentSearchClicked = {
onSearchQueryChanged(it)
onSearchTriggered(it)
},
recentSearchQueries = recentSearchesUiState.recentQueries.map { it.query },
)
}
} else { } else {
SearchResultBody( SearchResultBody(
topics = searchResultUiState.topics, topics = searchResultUiState.topics,
@ -189,7 +202,10 @@ fun EmptySearchResultBody(
onInterestsClick: () -> Unit, onInterestsClick: () -> Unit,
searchQuery: String, searchQuery: String,
) { ) {
Column(horizontalAlignment = Alignment.CenterHorizontally) { Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(horizontal = 48.dp),
) {
val message = stringResource(id = searchR.string.search_result_not_found, searchQuery) val message = stringResource(id = searchR.string.search_result_not_found, searchQuery)
val start = message.indexOf(searchQuery) val start = message.indexOf(searchQuery)
Text( Text(
@ -203,26 +219,34 @@ fun EmptySearchResultBody(
), ),
), ),
), ),
modifier = Modifier.padding(horizontal = 36.dp, vertical = 24.dp), fontSize = 18.sp,
textAlign = TextAlign.Center,
modifier = Modifier.padding(vertical = 24.dp),
) )
val interests = stringResource(id = searchR.string.interests) val interests = stringResource(id = searchR.string.interests)
val tryAnotherSearchString = buildAnnotatedString { val tryAnotherSearchString = buildAnnotatedString {
append(stringResource(id = searchR.string.try_another_search)) withStyle(style = SpanStyle(fontSize = 18.sp)) {
append(" ") append(stringResource(id = searchR.string.try_another_search))
withStyle( append(" ")
style = SpanStyle( withStyle(
textDecoration = TextDecoration.Underline, style = SpanStyle(
fontWeight = FontWeight.Bold, textDecoration = TextDecoration.Underline,
), fontWeight = FontWeight.Bold,
) { ),
pushStringAnnotation(tag = interests, annotation = interests) ) {
append(interests) pushStringAnnotation(tag = interests, annotation = interests)
append(interests)
}
append(" ")
append(stringResource(id = searchR.string.to_browse_topics))
} }
append(" ")
append(stringResource(id = searchR.string.to_browse_topics))
} }
ClickableText( ClickableText(
text = tryAnotherSearchString, text = tryAnotherSearchString,
style = TextStyle(
textAlign = TextAlign.Center,
lineHeight = 24.sp,
),
modifier = Modifier modifier = Modifier
.padding(start = 36.dp, end = 36.dp, bottom = 24.dp) .padding(start = 36.dp, end = 36.dp, bottom = 24.dp)
.clickable {}, .clickable {},
@ -454,7 +478,8 @@ private fun SearchTextField(
} else { } else {
false false
} }
}.testTag("searchTextField"), }
.testTag("searchTextField"),
shape = RoundedCornerShape(32.dp), shape = RoundedCornerShape(32.dp),
value = searchQuery, value = searchQuery,
keyboardOptions = KeyboardOptions( keyboardOptions = KeyboardOptions(

Loading…
Cancel
Save