From 0375c0b2c53d4579d3231049194f091d2005c56f Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 11 Apr 2020 11:46:05 -0400 Subject: [PATCH] Prioritize pinned sources in global search (closes #1739) --- .../global_search/CatalogueSearchPresenter.kt | 14 ++++++++------ .../tachiyomi/ui/migration/SearchPresenter.kt | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt index 29087ec248..b8f110e9dc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt @@ -30,14 +30,14 @@ import uy.kohesive.injekt.injectLazy * * @param sourceManager manages the different sources. * @param db manages the database calls. - * @param preferencesHelper manages the preference calls. + * @param preferences manages the preference calls. */ open class CatalogueSearchPresenter( val initialQuery: String? = "", val initialExtensionFilter: String? = null, val sourceManager: SourceManager = Injekt.get(), val db: DatabaseHelper = Injekt.get(), - val preferencesHelper: PreferencesHelper = Injekt.get() + val preferences: PreferencesHelper = Injekt.get() ) : BasePresenter() { /** @@ -94,18 +94,20 @@ open class CatalogueSearchPresenter( } /** - * Returns a list of enabled sources ordered by language and name. + * Returns a list of enabled sources ordered by language and name, with pinned catalogues + * prioritized. * * @return list containing enabled sources. */ protected open fun getEnabledSources(): List { - val languages = preferencesHelper.enabledLanguages().getOrDefault() - val hiddenCatalogues = preferencesHelper.hiddenCatalogues().getOrDefault() + val languages = preferences.enabledLanguages().getOrDefault() + val hiddenCatalogues = preferences.hiddenCatalogues().getOrDefault() + val pinnedCatalogues = preferences.pinnedCatalogues().getOrDefault() return sourceManager.getCatalogueSources() .filter { it.lang in languages } .filterNot { it.id.toString() in hiddenCatalogues } - .sortedBy { "(${it.lang}) ${it.name}" } + .sortedWith(compareBy({ it.id.toString() !in pinnedCatalogues }, { "(${it.lang}) ${it.name}" })) } private fun getSourcesToQuery(): List { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt index 460f67d0b4..8147828adf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt @@ -70,7 +70,7 @@ class SearchPresenter( manga: Manga, replace: Boolean ) { - val flags = preferencesHelper.migrateFlags().getOrDefault() + val flags = preferences.migrateFlags().getOrDefault() val migrateChapters = MigrationFlags.hasChapters(flags) val migrateCategories = MigrationFlags.hasCategories(flags) val migrateTracks = MigrationFlags.hasTracks(flags)