From 9376b223bb88c4923b4a8b9d2e00c50f2ce276d6 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 9 Aug 2020 11:58:50 -0400 Subject: [PATCH] Bubble up sources with results in global search (closes #3598) --- .../source/globalsearch/GlobalSearchPresenter.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt index 12c2ae54ef..4807e28a79 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt @@ -108,7 +108,7 @@ open class GlobalSearchPresenter( return sourceManager.getCatalogueSources() .filter { it.lang in languages } .filterNot { it.id.toString() in disabledSourceIds } - .sortedWith(compareBy({ it.id.toString() !in pinnedSourceIds }, { "(${it.lang}) ${it.name}" })) + .sortedWith(compareBy({ it.id.toString() !in pinnedSourceIds }, { "${it.name} (${it.lang})" })) } private fun getSourcesToQuery(): List { @@ -161,6 +161,8 @@ open class GlobalSearchPresenter( val initialItems = sources.map { createCatalogueSearchItem(it, null) } var items = initialItems + val pinnedSourceIds = preferences.pinnedSources().get() + fetchSourcesSubscription?.unsubscribe() fetchSourcesSubscription = Observable.from(sources) .flatMap( @@ -178,7 +180,15 @@ open class GlobalSearchPresenter( .observeOn(AndroidSchedulers.mainThread()) // Update matching source with the obtained results .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 .doOnNext { items = it }