mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	Rename some code from "catalogue" to "source"
This commit is contained in:
		| @@ -71,11 +71,11 @@ object PreferenceKeys { | ||||
|  | ||||
|     const val autoUpdateTrack = "pref_auto_update_manga_sync_key" | ||||
|  | ||||
|     const val lastUsedCatalogueSource = "last_catalogue_source" | ||||
|     const val lastUsedSource = "last_catalogue_source" | ||||
|  | ||||
|     const val lastUsedCategory = "last_used_category" | ||||
|  | ||||
|     const val catalogueDisplayMode = "pref_display_mode_catalogue" | ||||
|     const val sourceDisplayMode = "pref_display_mode_catalogue" | ||||
|  | ||||
|     const val enabledLanguages = "source_languages" | ||||
|  | ||||
|   | ||||
| @@ -135,13 +135,13 @@ class PreferencesHelper(val context: Context) { | ||||
|  | ||||
|     fun autoUpdateTrack() = prefs.getBoolean(Keys.autoUpdateTrack, true) | ||||
|  | ||||
|     fun lastUsedCatalogueSource() = flowPrefs.getLong(Keys.lastUsedCatalogueSource, -1) | ||||
|     fun lastUsedSource() = flowPrefs.getLong(Keys.lastUsedSource, -1) | ||||
|  | ||||
|     fun lastUsedCategory() = flowPrefs.getInt(Keys.lastUsedCategory, 0) | ||||
|  | ||||
|     fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0) | ||||
|  | ||||
|     fun catalogueDisplayMode() = flowPrefs.getEnum(Keys.catalogueDisplayMode, DisplayMode.COMPACT_GRID) | ||||
|     fun sourceDisplayMode() = flowPrefs.getEnum(Keys.sourceDisplayMode, DisplayMode.COMPACT_GRID) | ||||
|  | ||||
|     fun enabledLanguages() = flowPrefs.getStringSet(Keys.enabledLanguages, setOf("en", Locale.getDefault().language)) | ||||
|  | ||||
| @@ -215,9 +215,9 @@ class PreferencesHelper(val context: Context) { | ||||
|  | ||||
|     fun searchPinnedSourcesOnly() = prefs.getBoolean(Keys.searchPinnedSourcesOnly, false) | ||||
|  | ||||
|     fun hiddenCatalogues() = flowPrefs.getStringSet("hidden_catalogues", emptySet()) | ||||
|     fun disabledSources() = flowPrefs.getStringSet("hidden_catalogues", emptySet()) | ||||
|  | ||||
|     fun pinnedCatalogues() = flowPrefs.getStringSet("pinned_catalogues", emptySet()) | ||||
|     fun pinnedSources() = flowPrefs.getStringSet("pinned_catalogues", emptySet()) | ||||
|  | ||||
|     fun downloadNew() = flowPrefs.getBoolean(Keys.downloadNew, false) | ||||
|  | ||||
|   | ||||
| @@ -144,7 +144,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : | ||||
|                                     } | ||||
|  | ||||
|                                     // React to enable/disable all changes | ||||
|                                     preferences.hiddenCatalogues().asFlow() | ||||
|                                     preferences.disabledSources().asFlow() | ||||
|                                         .onEach { | ||||
|                                             val enabled = source.isEnabled() | ||||
|                                             isChecked = enabled | ||||
| @@ -212,9 +212,9 @@ class ExtensionDetailsController(bundle: Bundle? = null) : | ||||
|     } | ||||
|  | ||||
|     private fun toggleSource(source: Source, enable: Boolean) { | ||||
|         val current = preferences.hiddenCatalogues().get() | ||||
|         val current = preferences.disabledSources().get() | ||||
|  | ||||
|         preferences.hiddenCatalogues().set( | ||||
|         preferences.disabledSources().set( | ||||
|             if (enable) { | ||||
|                 current - source.id.toString() | ||||
|             } else { | ||||
| @@ -224,7 +224,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : | ||||
|     } | ||||
|  | ||||
|     private fun Source.isEnabled(): Boolean { | ||||
|         return id.toString() !in preferences.hiddenCatalogues().get() | ||||
|         return id.toString() !in preferences.disabledSources().get() | ||||
|     } | ||||
|  | ||||
|     private fun getPreferenceThemeContext(): Context { | ||||
|   | ||||
| @@ -120,7 +120,7 @@ class SourceController : | ||||
|     private fun onItemClick(position: Int) { | ||||
|         val item = adapter?.getItem(position) as? SourceItem ?: return | ||||
|         val source = item.source | ||||
|         openCatalogue(source, BrowseSourceController(source)) | ||||
|         openSource(source, BrowseSourceController(source)) | ||||
|     } | ||||
|  | ||||
|     override fun onItemLongClick(position: Int) { | ||||
| @@ -132,11 +132,11 @@ class SourceController : | ||||
|         val items = mutableListOf( | ||||
|             Pair( | ||||
|                 activity.getString(if (isPinned) R.string.action_unpin else R.string.action_pin), | ||||
|                 { pinCatalogue(item.source, isPinned) } | ||||
|                 { pinSource(item.source, isPinned) } | ||||
|             ) | ||||
|         ) | ||||
|         if (item.source !is LocalSource) { | ||||
|             items.add(Pair(activity.getString(R.string.action_hide), { hideCatalogue(item.source) })) | ||||
|             items.add(Pair(activity.getString(R.string.action_disable), { disableSource(item.source) })) | ||||
|         } | ||||
|  | ||||
|         MaterialDialog(activity) | ||||
| @@ -151,19 +151,19 @@ class SourceController : | ||||
|             .show() | ||||
|     } | ||||
|  | ||||
|     private fun hideCatalogue(source: Source) { | ||||
|         val current = preferences.hiddenCatalogues().get() | ||||
|         preferences.hiddenCatalogues().set(current + source.id.toString()) | ||||
|     private fun disableSource(source: Source) { | ||||
|         val current = preferences.disabledSources().get() | ||||
|         preferences.disabledSources().set(current + source.id.toString()) | ||||
|  | ||||
|         presenter.updateSources() | ||||
|     } | ||||
|  | ||||
|     private fun pinCatalogue(source: Source, isPinned: Boolean) { | ||||
|         val current = preferences.pinnedCatalogues().get() | ||||
|     private fun pinSource(source: Source, isPinned: Boolean) { | ||||
|         val current = preferences.pinnedSources().get() | ||||
|         if (isPinned) { | ||||
|             preferences.pinnedCatalogues().set(current - source.id.toString()) | ||||
|             preferences.pinnedSources().set(current - source.id.toString()) | ||||
|         } else { | ||||
|             preferences.pinnedCatalogues().set(current + source.id.toString()) | ||||
|             preferences.pinnedSources().set(current + source.id.toString()) | ||||
|         } | ||||
|  | ||||
|         presenter.updateSources() | ||||
| @@ -181,14 +181,14 @@ class SourceController : | ||||
|      */ | ||||
|     override fun onLatestClick(position: Int) { | ||||
|         val item = adapter?.getItem(position) as? SourceItem ?: return | ||||
|         openCatalogue(item.source, LatestUpdatesController(item.source)) | ||||
|         openSource(item.source, LatestUpdatesController(item.source)) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Opens a catalogue with the given controller. | ||||
|      */ | ||||
|     private fun openCatalogue(source: CatalogueSource, controller: BrowseSourceController) { | ||||
|         preferences.lastUsedCatalogueSource().set(source.id) | ||||
|     private fun openSource(source: CatalogueSource, controller: BrowseSourceController) { | ||||
|         preferences.lastUsedSource().set(source.id) | ||||
|         parentController!!.router.pushController(controller.withFadeTransaction()) | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -78,17 +78,17 @@ class SourceFilterController : SettingsController() { | ||||
|      * @param group the language category. | ||||
|      */ | ||||
|     private fun addLanguageSources(group: PreferenceGroup, sources: List<HttpSource>) { | ||||
|         val hiddenCatalogues = preferences.hiddenCatalogues().get() | ||||
|         val disabledSourceIds = preferences.disabledSources().get() | ||||
|  | ||||
|         sources | ||||
|             .sortedBy { it.id.toString() in hiddenCatalogues } | ||||
|             .sortedBy { it.id.toString() in disabledSourceIds } | ||||
|             .map { source -> | ||||
|                 CheckBoxPreference(group.context).apply { | ||||
|                     val id = source.id.toString() | ||||
|                     title = source.name | ||||
|                     key = source.getPreferenceKey() | ||||
|                     isPersistent = false | ||||
|                     isChecked = id !in hiddenCatalogues | ||||
|                     isChecked = id !in disabledSourceIds | ||||
|  | ||||
|                     val sourceIcon = source.icon() | ||||
|                     if (sourceIcon != null) { | ||||
| @@ -97,9 +97,9 @@ class SourceFilterController : SettingsController() { | ||||
|  | ||||
|                     onChange { newValue -> | ||||
|                         val checked = newValue as Boolean | ||||
|                         val current = preferences.hiddenCatalogues().get() | ||||
|                         val current = preferences.disabledSources().get() | ||||
|  | ||||
|                         preferences.hiddenCatalogues().set( | ||||
|                         preferences.disabledSources().set( | ||||
|                             if (checked) { | ||||
|                                 current - id | ||||
|                             } else { | ||||
|   | ||||
| @@ -58,7 +58,7 @@ class SourcePresenter( | ||||
|         sourceSubscription?.unsubscribe() | ||||
|  | ||||
|         val pinnedSources = mutableListOf<SourceItem>() | ||||
|         val pinnedCatalogues = preferences.pinnedCatalogues().get() | ||||
|         val pinnedSourceIds = preferences.pinnedSources().get() | ||||
|  | ||||
|         val map = TreeMap<String, MutableList<CatalogueSource>> { d1, d2 -> | ||||
|             // Catalogues without a lang defined will be placed at the end | ||||
| @@ -72,7 +72,7 @@ class SourcePresenter( | ||||
|         var sourceItems = byLang.flatMap { | ||||
|             val langItem = LangItem(it.key) | ||||
|             it.value.map { source -> | ||||
|                 if (source.id.toString() in pinnedCatalogues) { | ||||
|                 if (source.id.toString() in pinnedSourceIds) { | ||||
|                     pinnedSources.add(SourceItem(source, LangItem(PINNED_KEY))) | ||||
|                 } | ||||
|  | ||||
| @@ -90,10 +90,10 @@ class SourcePresenter( | ||||
|  | ||||
|     private fun loadLastUsedSource() { | ||||
|         // Immediate initial load | ||||
|         preferences.lastUsedCatalogueSource().get().let { updateLastUsedSource(it) } | ||||
|         preferences.lastUsedSource().get().let { updateLastUsedSource(it) } | ||||
|  | ||||
|         // Subsequent updates | ||||
|         preferences.lastUsedCatalogueSource().asFlow() | ||||
|         preferences.lastUsedSource().asFlow() | ||||
|             .drop(1) | ||||
|             .onStart { delay(500) } | ||||
|             .distinctUntilChanged() | ||||
| @@ -119,11 +119,11 @@ class SourcePresenter( | ||||
|      */ | ||||
|     private fun getEnabledSources(): List<CatalogueSource> { | ||||
|         val languages = preferences.enabledLanguages().get() | ||||
|         val hiddenCatalogues = preferences.hiddenCatalogues().get() | ||||
|         val disabledSourceIds = preferences.disabledSources().get() | ||||
|  | ||||
|         return sourceManager.getCatalogueSources() | ||||
|             .filter { it.lang in languages } | ||||
|             .filterNot { it.id.toString() in hiddenCatalogues } | ||||
|             .filterNot { it.id.toString() in disabledSourceIds } | ||||
|             .sortedBy { "(${it.lang}) ${it.name}" } + | ||||
|             sourceManager.get(LocalSource.ID) as LocalSource | ||||
|     } | ||||
|   | ||||
| @@ -192,7 +192,7 @@ open class BrowseSourceController(bundle: Bundle) : | ||||
|             binding.catalogueView.removeView(oldRecycler) | ||||
|         } | ||||
|  | ||||
|         val recycler = if (preferences.catalogueDisplayMode().get() == DisplayMode.LIST) { | ||||
|         val recycler = if (preferences.sourceDisplayMode().get() == DisplayMode.LIST) { | ||||
|             RecyclerView(view.context).apply { | ||||
|                 id = R.id.recycler | ||||
|                 layoutManager = LinearLayoutManager(context) | ||||
| @@ -271,7 +271,7 @@ open class BrowseSourceController(bundle: Bundle) : | ||||
|             } | ||||
|         ) | ||||
|  | ||||
|         val displayItem = when (preferences.catalogueDisplayMode().get()) { | ||||
|         val displayItem = when (preferences.sourceDisplayMode().get()) { | ||||
|             DisplayMode.COMPACT_GRID -> R.id.action_compact_grid | ||||
|             DisplayMode.COMFORTABLE_GRID -> R.id.action_comfortable_grid | ||||
|             DisplayMode.LIST -> R.id.action_list | ||||
| @@ -445,7 +445,7 @@ open class BrowseSourceController(bundle: Bundle) : | ||||
|         val view = view ?: return | ||||
|         val adapter = adapter ?: return | ||||
|  | ||||
|         preferences.catalogueDisplayMode().set(mode) | ||||
|         preferences.sourceDisplayMode().set(mode) | ||||
|         presenter.refreshDisplayMode() | ||||
|         activity?.invalidateOptionsMenu() | ||||
|         setupRecycler(view) | ||||
|   | ||||
| @@ -139,7 +139,7 @@ open class BrowseSourcePresenter( | ||||
|  | ||||
|         val sourceId = source.id | ||||
|  | ||||
|         val catalogueDisplayMode = prefs.catalogueDisplayMode() | ||||
|         val sourceDisplayMode = prefs.sourceDisplayMode() | ||||
|  | ||||
|         // Prepare the pager. | ||||
|         pagerSubscription?.let { remove(it) } | ||||
| @@ -147,7 +147,7 @@ open class BrowseSourcePresenter( | ||||
|             .observeOn(Schedulers.io()) | ||||
|             .map { pair -> pair.first to pair.second.map { networkToLocalManga(it, sourceId) } } | ||||
|             .doOnNext { initializeMangas(it.second) } | ||||
|             .map { pair -> pair.first to pair.second.map { SourceItem(it, catalogueDisplayMode) } } | ||||
|             .map { pair -> pair.first to pair.second.map { SourceItem(it, sourceDisplayMode) } } | ||||
|             .observeOn(AndroidSchedulers.mainThread()) | ||||
|             .subscribeReplay( | ||||
|                 { view, (page, mangas) -> | ||||
|   | ||||
| @@ -17,11 +17,11 @@ import eu.kanade.tachiyomi.widget.AutofitRecyclerView | ||||
| import kotlinx.android.synthetic.main.source_compact_grid_item.view.card | ||||
| import kotlinx.android.synthetic.main.source_compact_grid_item.view.gradient | ||||
|  | ||||
| class SourceItem(val manga: Manga, private val catalogueDisplayMode: Preference<DisplayMode>) : | ||||
| class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMode>) : | ||||
|     AbstractFlexibleItem<SourceHolder>() { | ||||
|  | ||||
|     override fun getLayoutRes(): Int { | ||||
|         return when (catalogueDisplayMode.get()) { | ||||
|         return when (displayMode.get()) { | ||||
|             DisplayMode.COMPACT_GRID -> R.layout.source_compact_grid_item | ||||
|             DisplayMode.COMFORTABLE_GRID -> R.layout.source_comfortable_grid_item | ||||
|             DisplayMode.LIST -> R.layout.source_list_item | ||||
| @@ -32,7 +32,7 @@ class SourceItem(val manga: Manga, private val catalogueDisplayMode: Preference< | ||||
|         view: View, | ||||
|         adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>> | ||||
|     ): SourceHolder { | ||||
|         return when (catalogueDisplayMode.get()) { | ||||
|         return when (displayMode.get()) { | ||||
|             DisplayMode.COMPACT_GRID -> { | ||||
|                 val parent = adapter.recyclerView as AutofitRecyclerView | ||||
|                 val coverHeight = parent.itemWidth / 3 * 4 | ||||
|   | ||||
| @@ -197,7 +197,7 @@ open class GlobalSearchController( | ||||
|      * Opens a catalogue with the given search. | ||||
|      */ | ||||
|     override fun onTitleClick(source: CatalogueSource) { | ||||
|         presenter.preferences.lastUsedCatalogueSource().set(source.id) | ||||
|         presenter.preferences.lastUsedSource().set(source.id) | ||||
|         router.pushController(BrowseSourceController(source, presenter.query).withFadeTransaction()) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -102,13 +102,13 @@ open class GlobalSearchPresenter( | ||||
|      */ | ||||
|     protected open fun getEnabledSources(): List<CatalogueSource> { | ||||
|         val languages = preferences.enabledLanguages().get() | ||||
|         val hiddenCatalogues = preferences.hiddenCatalogues().get() | ||||
|         val pinnedCatalogues = preferences.pinnedCatalogues().get() | ||||
|         val disabledSourceIds = preferences.disabledSources().get() | ||||
|         val pinnedSourceIds = preferences.pinnedSources().get() | ||||
|  | ||||
|         return sourceManager.getCatalogueSources() | ||||
|             .filter { it.lang in languages } | ||||
|             .filterNot { it.id.toString() in hiddenCatalogues } | ||||
|             .sortedWith(compareBy({ it.id.toString() !in pinnedCatalogues }, { "(${it.lang}) ${it.name}" })) | ||||
|             .filterNot { it.id.toString() in disabledSourceIds } | ||||
|             .sortedWith(compareBy({ it.id.toString() !in pinnedSourceIds }, { "(${it.lang}) ${it.name}" })) | ||||
|     } | ||||
|  | ||||
|     private fun getSourcesToQuery(): List<CatalogueSource> { | ||||
| @@ -129,10 +129,10 @@ open class GlobalSearchPresenter( | ||||
|         } | ||||
|  | ||||
|         val onlyPinnedSources = preferences.searchPinnedSourcesOnly() | ||||
|         val pinnedCatalogues = preferences.pinnedCatalogues().get() | ||||
|         val pinnedSourceIds = preferences.pinnedSources().get() | ||||
|  | ||||
|         return enabledSources | ||||
|             .filter { if (onlyPinnedSources) it.id.toString() in pinnedCatalogues else true } | ||||
|             .filter { if (onlyPinnedSources) it.id.toString() in pinnedSourceIds else true } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user