Bubble up sources with results in global search (closes #3598)
(cherry picked from commit 9376b223bb88c4923b4a8b9d2e00c50f2ce276d6) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt
This commit is contained in:
parent
b6f8db81ee
commit
c82d7db570
@ -106,16 +106,10 @@ open class GlobalSearchPresenter(
|
|||||||
val disabledSourceIds = preferences.disabledSources().get()
|
val disabledSourceIds = preferences.disabledSources().get()
|
||||||
val pinnedSourceIds = preferences.pinnedSources().get()
|
val pinnedSourceIds = preferences.pinnedSources().get()
|
||||||
|
|
||||||
val list = sourceManager.getVisibleCatalogueSources()
|
return sourceManager.getVisibleCatalogueSources()
|
||||||
.filter { it.lang in languages }
|
.filter { it.lang in languages }
|
||||||
.filterNot { it.id.toString() in disabledSourceIds }
|
.filterNot { it.id.toString() in disabledSourceIds }
|
||||||
.sortedBy { "(${it.lang}) ${it.name}" }
|
.sortedWith(compareBy({ it.id.toString() !in pinnedSourceIds }, { "${it.name} (${it.lang})" }))
|
||||||
|
|
||||||
return if (preferences.searchPinnedSourcesOnly()) {
|
|
||||||
list.filter { it.id.toString() in pinnedSourceIds }
|
|
||||||
} else {
|
|
||||||
list.sortedBy { it.id.toString() !in pinnedSourceIds }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSourcesToQuery(): List<CatalogueSource> {
|
private fun getSourcesToQuery(): List<CatalogueSource> {
|
||||||
@ -169,6 +163,8 @@ open class GlobalSearchPresenter(
|
|||||||
val initialItems = sources.map { createCatalogueSearchItem(it, null) }
|
val initialItems = sources.map { createCatalogueSearchItem(it, null) }
|
||||||
var items = initialItems
|
var items = initialItems
|
||||||
|
|
||||||
|
val pinnedSourceIds = preferences.pinnedSources().get()
|
||||||
|
|
||||||
fetchSourcesSubscription?.unsubscribe()
|
fetchSourcesSubscription?.unsubscribe()
|
||||||
fetchSourcesSubscription = Observable.from(sources)
|
fetchSourcesSubscription = Observable.from(sources)
|
||||||
.flatMap(
|
.flatMap(
|
||||||
@ -186,7 +182,15 @@ open class GlobalSearchPresenter(
|
|||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
// Update matching source with the obtained results
|
// Update matching source with the obtained results
|
||||||
.map { result ->
|
.map { result ->
|
||||||
items.map { item -> if (item.source == result.source) result else item }
|
items
|
||||||
|
.map { item -> if (item.source == result.source) result else item }
|
||||||
|
.sortedWith(compareBy(
|
||||||
|
// Bubble up sources that actually have results
|
||||||
|
{ it.results.isNullOrEmpty() },
|
||||||
|
// Same as initial sort, i.e. pinned first then alphabetically
|
||||||
|
{ it.source.id.toString() !in pinnedSourceIds },
|
||||||
|
{ "${it.source.name} (${it.source.lang})" }
|
||||||
|
))
|
||||||
}
|
}
|
||||||
// Update current state
|
// Update current state
|
||||||
.doOnNext { items = it }
|
.doOnNext { items = it }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user