Rename some code from "catalogue" to "source"

This commit is contained in:
arkon 2020-06-17 22:18:33 -04:00
parent f176a5179a
commit eee0bd6cf4
12 changed files with 50 additions and 50 deletions

View File

@ -71,11 +71,11 @@ object PreferenceKeys {
const val autoUpdateTrack = "pref_auto_update_manga_sync_key" 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 lastUsedCategory = "last_used_category"
const val catalogueDisplayMode = "pref_display_mode_catalogue" const val sourceDisplayMode = "pref_display_mode_catalogue"
const val enabledLanguages = "source_languages" const val enabledLanguages = "source_languages"

View File

@ -135,13 +135,13 @@ class PreferencesHelper(val context: Context) {
fun autoUpdateTrack() = prefs.getBoolean(Keys.autoUpdateTrack, true) 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 lastUsedCategory() = flowPrefs.getInt(Keys.lastUsedCategory, 0)
fun lastVersionCode() = flowPrefs.getInt("last_version_code", 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)) 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 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) fun downloadNew() = flowPrefs.getBoolean(Keys.downloadNew, false)

View File

@ -144,7 +144,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
} }
// React to enable/disable all changes // React to enable/disable all changes
preferences.hiddenCatalogues().asFlow() preferences.disabledSources().asFlow()
.onEach { .onEach {
val enabled = source.isEnabled() val enabled = source.isEnabled()
isChecked = enabled isChecked = enabled
@ -212,9 +212,9 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
} }
private fun toggleSource(source: Source, enable: Boolean) { 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) { if (enable) {
current - source.id.toString() current - source.id.toString()
} else { } else {
@ -224,7 +224,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
} }
private fun Source.isEnabled(): Boolean { private fun Source.isEnabled(): Boolean {
return id.toString() !in preferences.hiddenCatalogues().get() return id.toString() !in preferences.disabledSources().get()
} }
private fun getPreferenceThemeContext(): Context { private fun getPreferenceThemeContext(): Context {

View File

@ -120,7 +120,7 @@ class SourceController :
private fun onItemClick(position: Int) { private fun onItemClick(position: Int) {
val item = adapter?.getItem(position) as? SourceItem ?: return val item = adapter?.getItem(position) as? SourceItem ?: return
val source = item.source val source = item.source
openCatalogue(source, BrowseSourceController(source)) openSource(source, BrowseSourceController(source))
} }
override fun onItemLongClick(position: Int) { override fun onItemLongClick(position: Int) {
@ -132,11 +132,11 @@ class SourceController :
val items = mutableListOf( val items = mutableListOf(
Pair( Pair(
activity.getString(if (isPinned) R.string.action_unpin else R.string.action_pin), 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) { 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) MaterialDialog(activity)
@ -151,19 +151,19 @@ class SourceController :
.show() .show()
} }
private fun hideCatalogue(source: Source) { private fun disableSource(source: Source) {
val current = preferences.hiddenCatalogues().get() val current = preferences.disabledSources().get()
preferences.hiddenCatalogues().set(current + source.id.toString()) preferences.disabledSources().set(current + source.id.toString())
presenter.updateSources() presenter.updateSources()
} }
private fun pinCatalogue(source: Source, isPinned: Boolean) { private fun pinSource(source: Source, isPinned: Boolean) {
val current = preferences.pinnedCatalogues().get() val current = preferences.pinnedSources().get()
if (isPinned) { if (isPinned) {
preferences.pinnedCatalogues().set(current - source.id.toString()) preferences.pinnedSources().set(current - source.id.toString())
} else { } else {
preferences.pinnedCatalogues().set(current + source.id.toString()) preferences.pinnedSources().set(current + source.id.toString())
} }
presenter.updateSources() presenter.updateSources()
@ -181,14 +181,14 @@ class SourceController :
*/ */
override fun onLatestClick(position: Int) { override fun onLatestClick(position: Int) {
val item = adapter?.getItem(position) as? SourceItem ?: return 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. * Opens a catalogue with the given controller.
*/ */
private fun openCatalogue(source: CatalogueSource, controller: BrowseSourceController) { private fun openSource(source: CatalogueSource, controller: BrowseSourceController) {
preferences.lastUsedCatalogueSource().set(source.id) preferences.lastUsedSource().set(source.id)
parentController!!.router.pushController(controller.withFadeTransaction()) parentController!!.router.pushController(controller.withFadeTransaction())
} }

View File

@ -78,17 +78,17 @@ class SourceFilterController : SettingsController() {
* @param group the language category. * @param group the language category.
*/ */
private fun addLanguageSources(group: PreferenceGroup, sources: List<HttpSource>) { private fun addLanguageSources(group: PreferenceGroup, sources: List<HttpSource>) {
val hiddenCatalogues = preferences.hiddenCatalogues().get() val disabledSourceIds = preferences.disabledSources().get()
sources sources
.sortedBy { it.id.toString() in hiddenCatalogues } .sortedBy { it.id.toString() in disabledSourceIds }
.map { source -> .map { source ->
CheckBoxPreference(group.context).apply { CheckBoxPreference(group.context).apply {
val id = source.id.toString() val id = source.id.toString()
title = source.name title = source.name
key = source.getPreferenceKey() key = source.getPreferenceKey()
isPersistent = false isPersistent = false
isChecked = id !in hiddenCatalogues isChecked = id !in disabledSourceIds
val sourceIcon = source.icon() val sourceIcon = source.icon()
if (sourceIcon != null) { if (sourceIcon != null) {
@ -97,9 +97,9 @@ class SourceFilterController : SettingsController() {
onChange { newValue -> onChange { newValue ->
val checked = newValue as Boolean val checked = newValue as Boolean
val current = preferences.hiddenCatalogues().get() val current = preferences.disabledSources().get()
preferences.hiddenCatalogues().set( preferences.disabledSources().set(
if (checked) { if (checked) {
current - id current - id
} else { } else {

View File

@ -58,7 +58,7 @@ class SourcePresenter(
sourceSubscription?.unsubscribe() sourceSubscription?.unsubscribe()
val pinnedSources = mutableListOf<SourceItem>() val pinnedSources = mutableListOf<SourceItem>()
val pinnedCatalogues = preferences.pinnedCatalogues().get() val pinnedSourceIds = preferences.pinnedSources().get()
val map = TreeMap<String, MutableList<CatalogueSource>> { d1, d2 -> val map = TreeMap<String, MutableList<CatalogueSource>> { d1, d2 ->
// Catalogues without a lang defined will be placed at the end // Catalogues without a lang defined will be placed at the end
@ -72,7 +72,7 @@ class SourcePresenter(
var sourceItems = byLang.flatMap { var sourceItems = byLang.flatMap {
val langItem = LangItem(it.key) val langItem = LangItem(it.key)
it.value.map { source -> it.value.map { source ->
if (source.id.toString() in pinnedCatalogues) { if (source.id.toString() in pinnedSourceIds) {
pinnedSources.add(SourceItem(source, LangItem(PINNED_KEY))) pinnedSources.add(SourceItem(source, LangItem(PINNED_KEY)))
} }
@ -90,10 +90,10 @@ class SourcePresenter(
private fun loadLastUsedSource() { private fun loadLastUsedSource() {
// Immediate initial load // Immediate initial load
preferences.lastUsedCatalogueSource().get().let { updateLastUsedSource(it) } preferences.lastUsedSource().get().let { updateLastUsedSource(it) }
// Subsequent updates // Subsequent updates
preferences.lastUsedCatalogueSource().asFlow() preferences.lastUsedSource().asFlow()
.drop(1) .drop(1)
.onStart { delay(500) } .onStart { delay(500) }
.distinctUntilChanged() .distinctUntilChanged()
@ -119,11 +119,11 @@ class SourcePresenter(
*/ */
private fun getEnabledSources(): List<CatalogueSource> { private fun getEnabledSources(): List<CatalogueSource> {
val languages = preferences.enabledLanguages().get() val languages = preferences.enabledLanguages().get()
val hiddenCatalogues = preferences.hiddenCatalogues().get() val disabledSourceIds = preferences.disabledSources().get()
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 disabledSourceIds }
.sortedBy { "(${it.lang}) ${it.name}" } + .sortedBy { "(${it.lang}) ${it.name}" } +
sourceManager.get(LocalSource.ID) as LocalSource sourceManager.get(LocalSource.ID) as LocalSource
} }

View File

@ -192,7 +192,7 @@ open class BrowseSourceController(bundle: Bundle) :
binding.catalogueView.removeView(oldRecycler) binding.catalogueView.removeView(oldRecycler)
} }
val recycler = if (preferences.catalogueDisplayMode().get() == DisplayMode.LIST) { val recycler = if (preferences.sourceDisplayMode().get() == DisplayMode.LIST) {
RecyclerView(view.context).apply { RecyclerView(view.context).apply {
id = R.id.recycler id = R.id.recycler
layoutManager = LinearLayoutManager(context) 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.COMPACT_GRID -> R.id.action_compact_grid
DisplayMode.COMFORTABLE_GRID -> R.id.action_comfortable_grid DisplayMode.COMFORTABLE_GRID -> R.id.action_comfortable_grid
DisplayMode.LIST -> R.id.action_list DisplayMode.LIST -> R.id.action_list
@ -445,7 +445,7 @@ open class BrowseSourceController(bundle: Bundle) :
val view = view ?: return val view = view ?: return
val adapter = adapter ?: return val adapter = adapter ?: return
preferences.catalogueDisplayMode().set(mode) preferences.sourceDisplayMode().set(mode)
presenter.refreshDisplayMode() presenter.refreshDisplayMode()
activity?.invalidateOptionsMenu() activity?.invalidateOptionsMenu()
setupRecycler(view) setupRecycler(view)

View File

@ -139,7 +139,7 @@ open class BrowseSourcePresenter(
val sourceId = source.id val sourceId = source.id
val catalogueDisplayMode = prefs.catalogueDisplayMode() val sourceDisplayMode = prefs.sourceDisplayMode()
// Prepare the pager. // Prepare the pager.
pagerSubscription?.let { remove(it) } pagerSubscription?.let { remove(it) }
@ -147,7 +147,7 @@ open class BrowseSourcePresenter(
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
.map { pair -> pair.first to pair.second.map { networkToLocalManga(it, sourceId) } } .map { pair -> pair.first to pair.second.map { networkToLocalManga(it, sourceId) } }
.doOnNext { initializeMangas(it.second) } .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()) .observeOn(AndroidSchedulers.mainThread())
.subscribeReplay( .subscribeReplay(
{ view, (page, mangas) -> { view, (page, mangas) ->

View File

@ -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.card
import kotlinx.android.synthetic.main.source_compact_grid_item.view.gradient 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>() { AbstractFlexibleItem<SourceHolder>() {
override fun getLayoutRes(): Int { override fun getLayoutRes(): Int {
return when (catalogueDisplayMode.get()) { return when (displayMode.get()) {
DisplayMode.COMPACT_GRID -> R.layout.source_compact_grid_item DisplayMode.COMPACT_GRID -> R.layout.source_compact_grid_item
DisplayMode.COMFORTABLE_GRID -> R.layout.source_comfortable_grid_item DisplayMode.COMFORTABLE_GRID -> R.layout.source_comfortable_grid_item
DisplayMode.LIST -> R.layout.source_list_item DisplayMode.LIST -> R.layout.source_list_item
@ -32,7 +32,7 @@ class SourceItem(val manga: Manga, private val catalogueDisplayMode: Preference<
view: View, view: View,
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>> adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
): SourceHolder { ): SourceHolder {
return when (catalogueDisplayMode.get()) { return when (displayMode.get()) {
DisplayMode.COMPACT_GRID -> { DisplayMode.COMPACT_GRID -> {
val parent = adapter.recyclerView as AutofitRecyclerView val parent = adapter.recyclerView as AutofitRecyclerView
val coverHeight = parent.itemWidth / 3 * 4 val coverHeight = parent.itemWidth / 3 * 4

View File

@ -197,7 +197,7 @@ open class GlobalSearchController(
* Opens a catalogue with the given search. * Opens a catalogue with the given search.
*/ */
override fun onTitleClick(source: CatalogueSource) { override fun onTitleClick(source: CatalogueSource) {
presenter.preferences.lastUsedCatalogueSource().set(source.id) presenter.preferences.lastUsedSource().set(source.id)
router.pushController(BrowseSourceController(source, presenter.query).withFadeTransaction()) router.pushController(BrowseSourceController(source, presenter.query).withFadeTransaction())
} }
} }

View File

@ -102,13 +102,13 @@ open class GlobalSearchPresenter(
*/ */
protected open fun getEnabledSources(): List<CatalogueSource> { protected open fun getEnabledSources(): List<CatalogueSource> {
val languages = preferences.enabledLanguages().get() val languages = preferences.enabledLanguages().get()
val hiddenCatalogues = preferences.hiddenCatalogues().get() val disabledSourceIds = preferences.disabledSources().get()
val pinnedCatalogues = preferences.pinnedCatalogues().get() val pinnedSourceIds = preferences.pinnedSources().get()
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 disabledSourceIds }
.sortedWith(compareBy({ it.id.toString() !in pinnedCatalogues }, { "(${it.lang}) ${it.name}" })) .sortedWith(compareBy({ it.id.toString() !in pinnedSourceIds }, { "(${it.lang}) ${it.name}" }))
} }
private fun getSourcesToQuery(): List<CatalogueSource> { private fun getSourcesToQuery(): List<CatalogueSource> {
@ -129,10 +129,10 @@ open class GlobalSearchPresenter(
} }
val onlyPinnedSources = preferences.searchPinnedSourcesOnly() val onlyPinnedSources = preferences.searchPinnedSourcesOnly()
val pinnedCatalogues = preferences.pinnedCatalogues().get() val pinnedSourceIds = preferences.pinnedSources().get()
return enabledSources return enabledSources
.filter { if (onlyPinnedSources) it.id.toString() in pinnedCatalogues else true } .filter { if (onlyPinnedSources) it.id.toString() in pinnedSourceIds else true }
} }
/** /**

View File

@ -90,7 +90,7 @@
<string name="action_display_download_badge">Download badges</string> <string name="action_display_download_badge">Download badges</string>
<string name="action_display_unread_badge">Unread badges</string> <string name="action_display_unread_badge">Unread badges</string>
<string name="action_display_show_tabs">Show category tabs</string> <string name="action_display_show_tabs">Show category tabs</string>
<string name="action_hide">Hide</string> <string name="action_disable">Disable</string>
<string name="action_pin">Pin</string> <string name="action_pin">Pin</string>
<string name="action_unpin">Unpin</string> <string name="action_unpin">Unpin</string>
<string name="action_cancel">Cancel</string> <string name="action_cancel">Cancel</string>