Fix sources suggestion

This commit is contained in:
Koitharu
2024-10-07 14:40:29 +03:00
parent b46c00f2d0
commit 4faef85086

View File

@@ -25,6 +25,7 @@ import org.koitharu.kotatsu.core.util.ext.sizeOrZero
import org.koitharu.kotatsu.explore.data.MangaSourcesRepository import org.koitharu.kotatsu.explore.data.MangaSourcesRepository
import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.model.MangaSource
import org.koitharu.kotatsu.parsers.model.MangaTag import org.koitharu.kotatsu.parsers.model.MangaTag
import org.koitharu.kotatsu.parsers.util.mapToSet
import org.koitharu.kotatsu.search.domain.MangaSearchRepository import org.koitharu.kotatsu.search.domain.MangaSearchRepository
import org.koitharu.kotatsu.search.ui.suggestion.model.SearchSuggestionItem import org.koitharu.kotatsu.search.ui.suggestion.model.SearchSuggestionItem
import javax.inject.Inject import javax.inject.Inject
@@ -103,7 +104,7 @@ class SearchSuggestionViewModel @Inject constructor(
suggestionJob?.cancel() suggestionJob?.cancel()
suggestionJob = combine( suggestionJob = combine(
query.debounce(DEBOUNCE_TIMEOUT), query.debounce(DEBOUNCE_TIMEOUT),
sourcesRepository.observeEnabledSources().map { it.toSet() }, sourcesRepository.observeEnabledSources().map { it.mapToSet { x -> x.name } },
settings.observeAsFlow(AppSettings.KEY_SEARCH_SUGGESTION_TYPES) { searchSuggestionTypes }, settings.observeAsFlow(AppSettings.KEY_SEARCH_SUGGESTION_TYPES) { searchSuggestionTypes },
::Triple, ::Triple,
).mapLatest { (searchQuery, enabledSources, types) -> ).mapLatest { (searchQuery, enabledSources, types) ->
@@ -116,7 +117,7 @@ class SearchSuggestionViewModel @Inject constructor(
private suspend fun buildSearchSuggestion( private suspend fun buildSearchSuggestion(
searchQuery: String, searchQuery: String,
enabledSources: Set<MangaSource>, enabledSources: Set<String>,
types: Set<SearchSuggestionType>, types: Set<SearchSuggestionType>,
): List<SearchSuggestionItem> = coroutineScope { ): List<SearchSuggestionItem> = coroutineScope {
val queriesDeferred = if (SearchSuggestionType.QUERIES_RECENT in types) { val queriesDeferred = if (SearchSuggestionType.QUERIES_RECENT in types) {
@@ -169,7 +170,7 @@ class SearchSuggestionViewModel @Inject constructor(
if (!mangaList.isNullOrEmpty()) { if (!mangaList.isNullOrEmpty()) {
add(SearchSuggestionItem.MangaList(mangaList)) add(SearchSuggestionItem.MangaList(mangaList))
} }
sources?.mapTo(this) { SearchSuggestionItem.Source(it, it in enabledSources) } sources?.mapTo(this) { SearchSuggestionItem.Source(it, it.name in enabledSources) }
queries?.mapTo(this) { SearchSuggestionItem.RecentQuery(it) } queries?.mapTo(this) { SearchSuggestionItem.RecentQuery(it) }
authors?.mapTo(this) { SearchSuggestionItem.Author(it) } authors?.mapTo(this) { SearchSuggestionItem.Author(it) }
hints?.mapTo(this) { SearchSuggestionItem.Hint(it) } hints?.mapTo(this) { SearchSuggestionItem.Hint(it) }