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 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<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.
*/
protected open fun getEnabledSources(): List<CatalogueSource> {
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<CatalogueSource> {

View File

@ -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)