Prioritize pinned sources in global search (closes #1739)

This commit is contained in:
arkon 2020-04-11 11:46:05 -04:00
parent 135e55fe27
commit 0375c0b2c5
2 changed files with 9 additions and 7 deletions

View File

@ -30,14 +30,14 @@ import uy.kohesive.injekt.injectLazy
* *
* @param sourceManager manages the different sources. * @param sourceManager manages the different sources.
* @param db manages the database calls. * @param db manages the database calls.
* @param preferencesHelper manages the preference calls. * @param preferences manages the preference calls.
*/ */
open class CatalogueSearchPresenter( open class CatalogueSearchPresenter(
val initialQuery: String? = "", val initialQuery: String? = "",
val initialExtensionFilter: String? = null, val initialExtensionFilter: String? = null,
val sourceManager: SourceManager = Injekt.get(), val sourceManager: SourceManager = Injekt.get(),
val db: DatabaseHelper = Injekt.get(), val db: DatabaseHelper = Injekt.get(),
val preferencesHelper: PreferencesHelper = Injekt.get() val preferences: PreferencesHelper = Injekt.get()
) : BasePresenter<CatalogueSearchController>() { ) : BasePresenter<CatalogueSearchController>() {
/** /**
@ -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. * @return list containing enabled sources.
*/ */
protected open fun getEnabledSources(): List<CatalogueSource> { protected open fun getEnabledSources(): List<CatalogueSource> {
val languages = preferencesHelper.enabledLanguages().getOrDefault() val languages = preferences.enabledLanguages().getOrDefault()
val hiddenCatalogues = preferencesHelper.hiddenCatalogues().getOrDefault() val hiddenCatalogues = preferences.hiddenCatalogues().getOrDefault()
val pinnedCatalogues = preferences.pinnedCatalogues().getOrDefault()
return sourceManager.getCatalogueSources() return sourceManager.getCatalogueSources()
.filter { it.lang in languages } .filter { it.lang in languages }
.filterNot { it.id.toString() in hiddenCatalogues } .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<CatalogueSource> { private fun getSourcesToQuery(): List<CatalogueSource> {

View File

@ -70,7 +70,7 @@ class SearchPresenter(
manga: Manga, manga: Manga,
replace: Boolean replace: Boolean
) { ) {
val flags = preferencesHelper.migrateFlags().getOrDefault() val flags = preferences.migrateFlags().getOrDefault()
val migrateChapters = MigrationFlags.hasChapters(flags) val migrateChapters = MigrationFlags.hasChapters(flags)
val migrateCategories = MigrationFlags.hasCategories(flags) val migrateCategories = MigrationFlags.hasCategories(flags)
val migrateTracks = MigrationFlags.hasTracks(flags) val migrateTracks = MigrationFlags.hasTracks(flags)