Fix format issues

recent_search
Takeshi Hagikura 1 year ago
parent 6f9d2fe3ba
commit 477838f9da

@ -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.core.data.repository package com.google.samples.apps.nowinandroid.core.data.repository
@ -41,17 +41,17 @@ class DefaultSearchContentsRepository @Inject constructor(
override fun searchContents(searchQuery: String): Flow<SearchResult> { override fun searchContents(searchQuery: String): Flow<SearchResult> {
// Surround the query by asterisks to match the query when it's in the middle of // Surround the query by asterisks to match the query when it's in the middle of
// a word // a word
val newsResourceIds = newsResourceFtsDao.searchAllNewsResources("*${searchQuery}*") val newsResourceIds = newsResourceFtsDao.searchAllNewsResources("*$searchQuery*")
val topicIds = topicFtsDao.searchAllTopics("*${searchQuery}*") val topicIds = topicFtsDao.searchAllTopics("*$searchQuery*")
return combine( return combine(
newsResourceDao.getNewsResources(filterNewsIds = newsResourceIds.toSet()), newsResourceDao.getNewsResources(filterNewsIds = newsResourceIds.toSet()),
topicDao.getTopicEntities(topicIds.toSet()) topicDao.getTopicEntities(topicIds.toSet()),
) { newsResources, topics -> ) { newsResources, topics ->
SearchResult( SearchResult(
topics = topics.map { it.asExternalModel() }, topics = topics.map { it.asExternalModel() },
newsResources = newsResources.map { it.asExternalModel() } newsResources = newsResources.map { it.asExternalModel() },
) )
} }
} }
} }

@ -24,8 +24,7 @@ import javax.inject.Inject
/** /**
* Fake implementation of the [SearchContentsRepository] * Fake implementation of the [SearchContentsRepository]
*/ */
class FakeSearchContentsRepository @Inject constructor( class FakeSearchContentsRepository @Inject constructor() : SearchContentsRepository {
) : SearchContentsRepository {
override fun populateFtsData() {} override fun populateFtsData() {}
override fun searchContents(searchQuery: String): Flow<SearchResult> { override fun searchContents(searchQuery: String): Flow<SearchResult> {

@ -29,6 +29,7 @@ import com.google.samples.apps.nowinandroid.core.database.model.TopicFtsEntity
interface TopicFtsDao { interface TopicFtsDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(topics: List<TopicFtsEntity>) fun insertAll(topics: List<TopicFtsEntity>)
@Query("SELECT topicId FROM topicsFts WHERE topicsFts MATCH :query") @Query("SELECT topicId FROM topicsFts WHERE topicsFts MATCH :query")
fun searchAllTopics(query: String): List<String> fun searchAllTopics(query: String): List<String>

@ -44,5 +44,5 @@ fun TopicEntity.asFtsEntity() = TopicFtsEntity(
topicId = id, topicId = id,
name = name, name = name,
shortDescription = shortDescription, shortDescription = shortDescription,
longDescription = longDescription longDescription = longDescription,
) )

@ -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.core.domain package com.google.samples.apps.nowinandroid.core.domain
@ -24,8 +24,6 @@ import com.google.samples.apps.nowinandroid.core.domain.model.UserNewsResource
import com.google.samples.apps.nowinandroid.core.model.data.UserData import com.google.samples.apps.nowinandroid.core.model.data.UserData
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filterNot
import kotlinx.coroutines.flow.flow
import javax.inject.Inject import javax.inject.Inject
class GetSearchContentsUseCase @Inject constructor( class GetSearchContentsUseCase @Inject constructor(
@ -61,4 +59,4 @@ fun Flow<SearchResult>.mapToUserSearchResult(userDataStream: Flow<UserData>): Fl
data class UserSearchResult( data class UserSearchResult(
val topics: List<FollowableTopic> = emptyList(), val topics: List<FollowableTopic> = emptyList(),
val newsResources: List<UserNewsResource> = emptyList(), val newsResources: List<UserNewsResource> = emptyList(),
) )

@ -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.core.testing.repository package com.google.samples.apps.nowinandroid.core.testing.repository
@ -59,4 +59,4 @@ class TestSearchContentsRepository : SearchContentsRepository {
fun addNewsResources(newsResources: List<NewsResource>) { fun addNewsResources(newsResources: List<NewsResource>) {
cachedNewsResources.addAll(newsResources) cachedNewsResources.addAll(newsResources)
} }
} }

@ -44,7 +44,6 @@ import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
@ -100,7 +99,7 @@ internal fun SearchRoute(
onSearchQueryChanged = searchViewModel::onSearchQueryChanged, onSearchQueryChanged = searchViewModel::onSearchQueryChanged,
onTopicClick = onTopicClick, onTopicClick = onTopicClick,
onNewsResourcesCheckedChanged = forYouViewModel::updateNewsResourceSaved, onNewsResourcesCheckedChanged = forYouViewModel::updateNewsResourceSaved,
uiState = uiState uiState = uiState,
) )
} }

@ -58,4 +58,4 @@ class SearchViewModel @Inject constructor(
fun onSearchQueryChanged(query: String) { fun onSearchQueryChanged(query: String) {
searchQuery.value = query searchQuery.value = query
} }
} }

@ -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
@ -86,4 +86,4 @@ class SearchViewModelTest {
collectJob.cancel() collectJob.cancel()
} }
} }

Loading…
Cancel
Save