Use correct sources when triggering new global search
Actually fixes #9724 (cherry picked from commit 3f868c0435009f6c36fe4e91f93c5480e8486685) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/MigrateSearchScreenModel.kt # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/SearchScreenModel.kt
This commit is contained in:
parent
18b2d575c5
commit
c061aabfc6
@ -6,12 +6,20 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SearchScreenModel
|
|||||||
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SourceFilter
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SourceFilter
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import tachiyomi.domain.manga.interactor.GetManga
|
||||||
|
import tachiyomi.domain.source.service.SourceManager
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
class MigrateSearchScreenModel(
|
class MigrateSearchScreenModel(
|
||||||
val mangaId: Long,
|
val mangaId: Long,
|
||||||
// SY -->
|
// SY -->
|
||||||
val validSources: List<Long>,
|
val validSources: List<Long>,
|
||||||
// SY <--
|
// SY <--
|
||||||
|
getManga: GetManga = Injekt.get(),
|
||||||
|
// SY -->
|
||||||
|
private val sourceManager: SourceManager = Injekt.get(),
|
||||||
|
// SY <--
|
||||||
) : SearchScreenModel() {
|
) : SearchScreenModel() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -28,11 +36,17 @@ class MigrateSearchScreenModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getEnabledSources(): List<CatalogueSource> {
|
override fun getEnabledSources(): List<CatalogueSource> {
|
||||||
val pinnedSources = sourcePreferences.pinnedSources().get()
|
|
||||||
// SY -->
|
// SY -->
|
||||||
return validSources.mapNotNull { sourceManager.get(it) }
|
return validSources.mapNotNull { sourceManager.get(it) }
|
||||||
.filterIsInstance<CatalogueSource>()
|
.filterIsInstance<CatalogueSource>()
|
||||||
.filter { mutableState.value.sourceFilter != SourceFilter.PinnedOnly || "${it.id}" in pinnedSources }
|
.filter { state.value.sourceFilter != SourceFilter.PinnedOnly || "${it.id}" in pinnedSources }
|
||||||
|
.sortedWith(
|
||||||
|
compareBy(
|
||||||
|
{ it.id != state.value.fromSourceId },
|
||||||
|
{ "${it.id}" !in pinnedSources },
|
||||||
|
{ "${it.name.lowercase()} (${it.lang})" },
|
||||||
|
),
|
||||||
|
)
|
||||||
// SY <--
|
// SY <--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,6 @@ class GlobalSearchScreenModel(
|
|||||||
|
|
||||||
override fun getEnabledSources(): List<CatalogueSource> {
|
override fun getEnabledSources(): List<CatalogueSource> {
|
||||||
return super.getEnabledSources()
|
return super.getEnabledSources()
|
||||||
.filter { mutableState.value.sourceFilter != SourceFilter.PinnedOnly || "${it.id}" in pinnedSources }
|
.filter { state.value.sourceFilter != SourceFilter.PinnedOnly || "${it.id}" in pinnedSources }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,22 +29,24 @@ import java.util.concurrent.Executors
|
|||||||
|
|
||||||
abstract class SearchScreenModel(
|
abstract class SearchScreenModel(
|
||||||
initialState: State = State(),
|
initialState: State = State(),
|
||||||
protected val sourcePreferences: SourcePreferences = Injekt.get(),
|
sourcePreferences: SourcePreferences = Injekt.get(),
|
||||||
protected val sourceManager: SourceManager = Injekt.get(),
|
private val sourceManager: SourceManager = Injekt.get(),
|
||||||
private val extensionManager: ExtensionManager = Injekt.get(),
|
private val extensionManager: ExtensionManager = Injekt.get(),
|
||||||
private val networkToLocalManga: NetworkToLocalManga = Injekt.get(),
|
private val networkToLocalManga: NetworkToLocalManga = Injekt.get(),
|
||||||
protected val getManga: GetManga = Injekt.get(),
|
private val getManga: GetManga = Injekt.get(),
|
||||||
) : StateScreenModel<SearchScreenModel.State>(initialState) {
|
) : StateScreenModel<SearchScreenModel.State>(initialState) {
|
||||||
|
|
||||||
private val coroutineDispatcher = Executors.newFixedThreadPool(5).asCoroutineDispatcher()
|
private val coroutineDispatcher = Executors.newFixedThreadPool(5).asCoroutineDispatcher()
|
||||||
private var searchJob: Job? = null
|
private var searchJob: Job? = null
|
||||||
|
|
||||||
private val sources by lazy { getSelectedSources() }
|
private val enabledLanguages = sourcePreferences.enabledLanguages().get()
|
||||||
|
private val disabledSources = sourcePreferences.disabledSources().get()
|
||||||
|
protected val pinnedSources = sourcePreferences.pinnedSources().get()
|
||||||
|
|
||||||
private var lastQuery: String? = null
|
private var lastQuery: String? = null
|
||||||
private var lastSourceFilter: SourceFilter? = null
|
private var lastSourceFilter: SourceFilter? = null
|
||||||
|
|
||||||
protected var extensionFilter: String? = null
|
protected var extensionFilter: String? = null
|
||||||
protected val pinnedSources = sourcePreferences.pinnedSources().get()
|
|
||||||
|
|
||||||
private val sortComparator = { map: Map<CatalogueSource, SearchItemResult> ->
|
private val sortComparator = { map: Map<CatalogueSource, SearchItemResult> ->
|
||||||
compareBy<CatalogueSource>(
|
compareBy<CatalogueSource>(
|
||||||
@ -66,10 +68,6 @@ abstract class SearchScreenModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
open fun getEnabledSources(): List<CatalogueSource> {
|
open fun getEnabledSources(): List<CatalogueSource> {
|
||||||
val enabledLanguages = sourcePreferences.enabledLanguages().get()
|
|
||||||
val disabledSources = sourcePreferences.disabledSources().get()
|
|
||||||
val pinnedSources = sourcePreferences.pinnedSources().get()
|
|
||||||
|
|
||||||
return sourceManager.getVisibleCatalogueSources()
|
return sourceManager.getVisibleCatalogueSources()
|
||||||
.filter { it.lang in enabledLanguages && "${it.id}" !in disabledSources }
|
.filter { it.lang in enabledLanguages && "${it.id}" !in disabledSources }
|
||||||
.sortedWith(
|
.sortedWith(
|
||||||
@ -125,7 +123,7 @@ abstract class SearchScreenModel(
|
|||||||
val initialItems = getSelectedSources().associateWith { SearchItemResult.Loading }
|
val initialItems = getSelectedSources().associateWith { SearchItemResult.Loading }
|
||||||
updateItems(initialItems)
|
updateItems(initialItems)
|
||||||
searchJob = ioCoroutineScope.launch {
|
searchJob = ioCoroutineScope.launch {
|
||||||
sources.map { source ->
|
getSelectedSources().map { source ->
|
||||||
async {
|
async {
|
||||||
try {
|
try {
|
||||||
val page = withContext(coroutineDispatcher) {
|
val page = withContext(coroutineDispatcher) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user