diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/search/SearchVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/search/SearchVM.kt index 54da56cf..69c6fb95 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/search/SearchVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/search/SearchVM.kt @@ -262,7 +262,7 @@ class SearchVM : ViewModel(), KoinComponent { ) else flowOf(emptyList()) searchService.search( query, - filters = if (query.isEmpty()) filters.copy(apps = true) else filters, + filters = filters, previousResults, ) .combine(hiddenItemKeys) { results, hiddenKeys -> results to hiddenKeys } @@ -440,11 +440,13 @@ class SearchVM : ViewModel(), KoinComponent { add(item) } } + private suspend fun SnapshotStateList.mergeWith( newItems: List?, hiddenKeys: List, query: String - ) = this.mergeWith((newItems ?: emptyList()).filterNot { hiddenKeys.contains(it.key) }.applyRanking(query)) + ) = this.mergeWith((newItems ?: emptyList()).filterNot { hiddenKeys.contains(it.key) } + .applyRanking(query)) } diff --git a/services/search/src/main/java/de/mm20/launcher2/search/SearchService.kt b/services/search/src/main/java/de/mm20/launcher2/search/SearchService.kt index a55a43f6..640576ea 100644 --- a/services/search/src/main/java/de/mm20/launcher2/search/SearchService.kt +++ b/services/search/src/main/java/de/mm20/launcher2/search/SearchService.kt @@ -58,7 +58,21 @@ internal class SearchServiceImpl( initialResults: SearchResults?, ): Flow = flow { supervisorScope { - val results = MutableStateFlow(initialResults ?: SearchResults()) + val results = MutableStateFlow( + initialResults?.let { + it.copy( + apps = if (filters.apps) it.apps else null, + shortcuts = if (filters.shortcuts) it.shortcuts else null, + contacts = if (filters.contacts) it.contacts else null, + calendars = if (filters.events) it.calendars else null, + files = if (filters.files) it.files else null, + calculators = if (filters.tools) it.calculators else null, + unitConverters = if (filters.tools) it.unitConverters else null, + websites = if (filters.websites) it.websites else null, + wikipedia = if (filters.articles) it.wikipedia else null, + ) + } + ?: SearchResults()) val customAttrResults = customAttributesRepository.search(query) .map { items -> @@ -266,13 +280,25 @@ internal class SearchServiceImpl( val standardProfileApps = mutableListOf() val workProfileApps = mutableListOf() val privateSpaceApps = mutableListOf() - for (app in apps) { + for (app in apps) { when { - standardProfile != null && app.user == standardProfile.userHandle -> standardProfileApps.add(app) - workProfile != null && app.user == workProfile.userHandle -> workProfileApps.add(app) - privateSpace != null && app.user == privateSpace.userHandle -> privateSpaceApps.add(app) + standardProfile != null && app.user == standardProfile.userHandle -> standardProfileApps.add( + app + ) + + workProfile != null && app.user == workProfile.userHandle -> workProfileApps.add( + app + ) + + privateSpace != null && app.user == privateSpace.userHandle -> privateSpaceApps.add( + app + ) + else -> { - Log.w("MM20", "App ${app.label} does not belong to any known profile. Ignoring.") + Log.w( + "MM20", + "App ${app.label} does not belong to any known profile. Ignoring." + ) } } }