Fix format issues

Change-Id: I5b87f89d824961cb9aec039281e784d6dec0716b
search_screen
Takeshi Hagikura 2 years ago
parent 13e6cc4f2b
commit 83b640a7f0

@ -18,13 +18,11 @@ package com.google.samples.apps.nowinandroid.navigation
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.bookmarksScreen import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.bookmarksScreen
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouNavigationRoute import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouNavigationRoute
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouScreen import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouScreen
import com.google.samples.apps.nowinandroid.feature.interests.navigation.interestsGraph import com.google.samples.apps.nowinandroid.feature.interests.navigation.interestsGraph
import com.google.samples.apps.nowinandroid.feature.interests.navigation.navigateToInterestsGraph
import com.google.samples.apps.nowinandroid.feature.search.navigation.searchScreen import com.google.samples.apps.nowinandroid.feature.search.navigation.searchScreen
import com.google.samples.apps.nowinandroid.feature.topic.navigation.navigateToTopic import com.google.samples.apps.nowinandroid.feature.topic.navigation.navigateToTopic
import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicScreen import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicScreen
@ -56,7 +54,7 @@ fun NiaNavHost(
searchScreen( searchScreen(
onBackClick = navController::popBackStack, onBackClick = navController::popBackStack,
onInterestsClick = { appState.navigateToTopLevelDestination(INTERESTS) }, onInterestsClick = { appState.navigateToTopLevelDestination(INTERESTS) },
onTopicClick = {} onTopicClick = {},
) )
interestsGraph( interestsGraph(
onTopicClick = { topicId -> onTopicClick = { topicId ->

@ -35,7 +35,7 @@ fun TopicsTabContent(
onTopicClick: (String) -> Unit, onTopicClick: (String) -> Unit,
onFollowButtonClick: (String, Boolean) -> Unit, onFollowButtonClick: (String, Boolean) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
withBottomSpacer: Boolean = true withBottomSpacer: Boolean = true,
) { ) {
LazyColumn( LazyColumn(
modifier = modifier modifier = modifier

@ -93,7 +93,7 @@ class SearchScreenTest {
fun emptySearchResult_emptyScreenIsDisplayed() { fun emptySearchResult_emptyScreenIsDisplayed() {
composeTestRule.setContent { composeTestRule.setContent {
SearchScreen( SearchScreen(
uiState = SearchResultUiState.Success() uiState = SearchResultUiState.Success(),
) )
} }
@ -135,11 +135,14 @@ class SearchScreenTest {
fun searchResultWithNewsResources_firstNewsResourcesIsVisible() { fun searchResultWithNewsResources_firstNewsResourcesIsVisible() {
composeTestRule.setContent { composeTestRule.setContent {
SearchScreen( SearchScreen(
uiState = SearchResultUiState.Success(newsResources = newsResourcesTestData.map { uiState = SearchResultUiState.Success(
UserNewsResource( newsResources = newsResourcesTestData.map {
newsResource = it, UserNewsResource(
userData = userData) newsResource = it,
}), userData = userData,
)
},
),
) )
} }

@ -1,17 +1,17 @@
/* /*
* Copyright 2023 The Android Open Source Project * Copyright 2023 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.samples.apps.nowinandroid.feature.search package com.google.samples.apps.nowinandroid.feature.search

@ -95,7 +95,7 @@ internal fun SearchRoute(
onInterestsClick = onInterestsClick, onInterestsClick = onInterestsClick,
onSearchQueryChanged = searchViewModel::onSearchQueryChanged, onSearchQueryChanged = searchViewModel::onSearchQueryChanged,
onTopicClick = onTopicClick, onTopicClick = onTopicClick,
onNewsResourcesCheckedChanged = forYouViewModel::updateNewsResourceSaved onNewsResourcesCheckedChanged = forYouViewModel::updateNewsResourceSaved,
) )
} }
@ -103,9 +103,9 @@ internal fun SearchRoute(
internal fun SearchScreen( internal fun SearchScreen(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onBackClick: () -> Unit = {}, onBackClick: () -> Unit = {},
onFollowButtonClick: (String, Boolean) -> Unit = {_, _ -> }, onFollowButtonClick: (String, Boolean) -> Unit = { _, _ -> },
onInterestsClick: () -> Unit = {}, onInterestsClick: () -> Unit = {},
onNewsResourcesCheckedChanged: (String, Boolean) -> Unit = {_, _ -> }, onNewsResourcesCheckedChanged: (String, Boolean) -> Unit = { _, _ -> },
onSearchQueryChanged: (String) -> Unit = {}, onSearchQueryChanged: (String) -> Unit = {},
onTopicClick: (String) -> Unit = {}, onTopicClick: (String) -> Unit = {},
uiState: SearchResultUiState = SearchResultUiState.Loading, uiState: SearchResultUiState = SearchResultUiState.Loading,
@ -192,7 +192,6 @@ fun EmptySearchResultBody(
onInterestsClick() onInterestsClick()
} }
} }
} }
} }
@ -201,8 +200,8 @@ private fun SearchResultBody(
topics: List<FollowableTopic>, topics: List<FollowableTopic>,
newsResources: List<UserNewsResource>, newsResources: List<UserNewsResource>,
onFollowButtonClick: (String, Boolean) -> Unit, onFollowButtonClick: (String, Boolean) -> Unit,
onNewsResourcesCheckedChanged: (String, Boolean) -> Unit = {_, _ -> }, onNewsResourcesCheckedChanged: (String, Boolean) -> Unit = { _, _ -> },
onTopicClick: (String) -> Unit = {} onTopicClick: (String) -> Unit = {},
) { ) {
if (topics.isNotEmpty()) { if (topics.isNotEmpty()) {
Text( Text(
@ -217,7 +216,7 @@ private fun SearchResultBody(
topics = topics, topics = topics,
onTopicClick = onTopicClick, onTopicClick = onTopicClick,
onFollowButtonClick = onFollowButtonClick, onFollowButtonClick = onFollowButtonClick,
withBottomSpacer = false withBottomSpacer = false,
) )
} }
@ -246,7 +245,7 @@ private fun SearchResultBody(
newsFeed( newsFeed(
feedState = NewsFeedUiState.Success(feed = newsResources), feedState = NewsFeedUiState.Success(feed = newsResources),
onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged, onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged,
onTopicClick = onTopicClick onTopicClick = onTopicClick,
) )
} }
} }
@ -347,7 +346,7 @@ private fun EmptySearchResultColumnPreview() {
@DevicePreviews @DevicePreviews
@Composable @Composable
private fun SearchScreenPreview( private fun SearchScreenPreview(
@PreviewParameter(SearchResultUiStatePreviewParameterProvider::class) @PreviewParameter(SearchUiStatePreviewParameterProvider::class)
searchResultUiState: SearchResultUiState, searchResultUiState: SearchResultUiState,
) { ) {
NiaTheme { NiaTheme {

@ -26,11 +26,13 @@ import com.google.samples.apps.nowinandroid.core.ui.PreviewParameterData.topics
* This [PreviewParameterProvider](https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/preview/PreviewParameterProvider) * This [PreviewParameterProvider](https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/preview/PreviewParameterProvider)
* provides list of [SearchResultUiState] for Composable previews. * provides list of [SearchResultUiState] for Composable previews.
*/ */
class SearchResultUiStatePreviewParameterProvider : PreviewParameterProvider<SearchResultUiState> { class SearchUiStatePreviewParameterProvider : PreviewParameterProvider<SearchResultUiState> {
override val values: Sequence<SearchResultUiState> = sequenceOf(SearchResultUiState.Success( override val values: Sequence<SearchResultUiState> = sequenceOf(
topics = topics.mapIndexed { i, topic -> SearchResultUiState.Success(
FollowableTopic(topic = topic, isFollowed = i % 2 == 0) topics = topics.mapIndexed { i, topic ->
}, FollowableTopic(topic = topic, isFollowed = i % 2 == 0)
newsResources = newsResources, },
)) newsResources = newsResources,
),
)
} }

@ -31,7 +31,7 @@ fun NavController.navigateToSearch(navOptions: NavOptions? = null) {
fun NavGraphBuilder.searchScreen( fun NavGraphBuilder.searchScreen(
onBackClick: () -> Unit, onBackClick: () -> Unit,
onInterestsClick: () -> Unit, onInterestsClick: () -> Unit,
onTopicClick: (String) -> Unit = {} onTopicClick: (String) -> Unit = {},
) { ) {
// TODO: Handle back stack for each top-level destination. At the moment each top-level // TODO: Handle back stack for each top-level destination. At the moment each top-level
// destination may have own search screen's back stack. // destination may have own search screen's back stack.
@ -39,7 +39,7 @@ fun NavGraphBuilder.searchScreen(
SearchRoute( SearchRoute(
onBackClick = onBackClick, onBackClick = onBackClick,
onInterestsClick = onInterestsClick, onInterestsClick = onInterestsClick,
onTopicClick = onTopicClick onTopicClick = onTopicClick,
) )
} }
} }

Loading…
Cancel
Save