From 45f1f9929224b5d21cd2fae0717cd757c80f559d Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 20 May 2020 20:29:00 -0400 Subject: [PATCH] Added Sources (Browse) settings + Global Pinned Search Also moved all migration options to the sources settings Migration sources converted to flowpref New settings: Only globally search pinned sources Match migration sources with pinned Match migration sources with enabled sources --- .../data/preference/PreferenceKeys.kt | 2 + .../data/preference/PreferencesHelper.kt | 5 +- .../ui/extension/ExtensionBottomSheet.kt | 69 ----------- .../manga/design/PreMigrationController.kt | 6 +- .../manga/process/MigrationListController.kt | 2 +- .../ui/setting/SettingsBrowseController.kt | 110 ++++++++++++++++++ .../ui/setting/SettingsLibraryController.kt | 14 --- .../ui/setting/SettingsMainController.kt | 7 +- .../global_search/GlobalSearchPresenter.kt | 9 +- .../res/drawable/ic_info_outline_24dp.xml | 9 ++ app/src/main/res/layout/auto_ext_checkbox.xml | 9 -- app/src/main/res/menu/extension_main.xml | 8 -- app/src/main/res/values/strings.xml | 19 ++- 13 files changed, 155 insertions(+), 114 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt create mode 100644 app/src/main/res/drawable/ic_info_outline_24dp.xml delete mode 100644 app/src/main/res/layout/auto_ext_checkbox.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 18e99d7ae7..7c2379c084 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -109,6 +109,8 @@ object PreferenceKeys { const val automaticExtUpdates = "automatic_ext_updates" + const val onlySearchPinned = "only_search_pinned" + const val downloadNew = "download_new" const val downloadNewCategories = "download_new_categories" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 65df83504b..7603039831 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -233,7 +233,8 @@ class PreferencesHelper(val context: Context) { fun trustedSignatures() = rxPrefs.getStringSet("trusted_signatures", emptySet()) - fun migrationSources() = rxPrefs.getString("migrate_sources", "") + // using string instead of set so it is ordered + fun migrationSources() = flowPrefs.getString("migrate_sources", "") fun useSourceWithMost() = rxPrefs.getBoolean("use_source_with_most", false) @@ -275,6 +276,8 @@ class PreferencesHelper(val context: Context) { fun showCategoryInTitle() = flowPrefs.getBoolean("category_in_title", false) + fun onlySearchPinned() = flowPrefs.getBoolean(Keys.onlySearchPinned, true) + // Tutorial preferences fun shownFilterTutorial() = flowPrefs.getBoolean("shown_filter_tutorial", false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt index c6129fdd7e..9be1903d09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt @@ -3,17 +3,11 @@ package eu.kanade.tachiyomi.ui.extension import android.content.Context import android.util.AttributeSet import android.view.View -import android.widget.CheckBox -import android.widget.CompoundButton import android.widget.LinearLayout -import com.f2prateek.rx.preferences.Preference import com.google.android.material.bottomsheet.BottomSheetBehavior import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.flexibleadapter.items.AbstractHeaderItem import eu.davidea.flexibleadapter.items.IFlexible -import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.ui.source.SourceController import eu.kanade.tachiyomi.util.system.getResourceColor @@ -34,7 +28,6 @@ ExtensionAdapter.OnButtonClickListener, ExtensionTrustDialog.Listener { var sheetBehavior: BottomSheetBehavior<*>? = null - private lateinit var autoCheckItem: AutoCheckItem var shouldCallApi = false @@ -51,7 +44,6 @@ ExtensionAdapter.OnButtonClickListener, fun onCreate(controller: SourceController) { // Initialize adapter, scroll listener and recycler views - autoCheckItem = AutoCheckItem(presenter.getAutoCheckPref()) adapter = ExtensionAdapter(this) sheetBehavior = BottomSheetBehavior.from(this) // Create recycler and set adapter. @@ -166,15 +158,6 @@ ExtensionAdapter.OnButtonClickListener, adapter?.updateDataSet(extensions) } updateExtTitle() - setLastUsedSource() - } - - /** - * Called to set the last used catalogue at the top of the view. - */ - private fun setLastUsedSource() { - adapter?.removeAllScrollableHeaders() - adapter?.addScrollableHeader(autoCheckItem) } fun downloadUpdate(item: ExtensionItem) { @@ -189,55 +172,3 @@ ExtensionAdapter.OnButtonClickListener, presenter.uninstallExtension(pkgName) } } - -class AutoCheckItem(private val autoCheck: Preference) : AbstractHeaderItem() { - - override fun getLayoutRes(): Int { - return R.layout.auto_ext_checkbox - } - - override fun createViewHolder( - view: View, - adapter: FlexibleAdapter> - ): AutoCheckHolder { - return AutoCheckHolder(view, adapter, autoCheck) - } - - override fun bindViewHolder( - adapter: FlexibleAdapter>, - holder: AutoCheckHolder, - position: Int, - payloads: MutableList? - ) { - // holder.bind(autoCheck.getOrDefault()) - } - - override fun equals(other: Any?): Boolean { - return (this === other) - } - - override fun hashCode(): Int { - return -1 - } - - class AutoCheckHolder( - val view: View, - private val adapter: FlexibleAdapter>, - autoCheck: Preference - ) : - FlexibleViewHolder(view, adapter, true) { - private val autoCheckbox: CheckBox = view.findViewById(R.id.auto_checkbox) - - init { - autoCheckbox.bindToPreference(autoCheck) - } - - /** - * Binds a checkbox or switch view with a boolean preference. - */ - private fun CompoundButton.bindToPreference(pref: Preference) { - isChecked = pref.getOrDefault() - setOnCheckedChangeListener { _, isChecked -> pref.set(isChecked) } - } - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt index 6df5ec5cfb..2cdd26713a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt @@ -92,7 +92,7 @@ class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), F override fun startMigration(extraParam: String?) { val listOfSources = adapter?.items?.filter { it.sourceEnabled - }?.joinToString("/") { it.source.id.toString() } + }?.joinToString("/") { it.source.id.toString() } ?: "" prefs.migrationSources().set(listOfSources) router.replaceTopController( @@ -130,7 +130,7 @@ class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), F */ private fun getEnabledSources(): List { val languages = prefs.enabledLanguages().getOrDefault() - val sourcesSaved = prefs.migrationSources().getOrDefault().split("/") + val sourcesSaved = prefs.migrationSources().get().split("/") var sources = sourceManager.getCatalogueSources() .filterIsInstance() .filter { it.lang in languages } @@ -145,7 +145,7 @@ class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), F } fun isEnabled(id: String): Boolean { - val sourcesSaved = prefs.migrationSources().getOrDefault() + val sourcesSaved = prefs.migrationSources().get() val hiddenCatalogues = prefs.hiddenSources().getOrDefault() return if (sourcesSaved.isEmpty()) id !in hiddenCatalogues else sourcesSaved.split("/").contains(id) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt index 4d67fbc984..382e83269b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt @@ -126,7 +126,7 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), private suspend fun runMigrations(mangas: List) { val useSourceWithMost = preferences.useSourceWithMost().getOrDefault() - val sources = preferences.migrationSources().getOrDefault().split("/").mapNotNull { + val sources = preferences.migrationSources().get().split("/").mapNotNull { val value = it.toLongOrNull() ?: return sourceManager.get(value) as? CatalogueSource } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt new file mode 100644 index 0000000000..d93f28b640 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt @@ -0,0 +1,110 @@ +package eu.kanade.tachiyomi.ui.setting + +import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferenceKeys +import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.extension.ExtensionUpdateJob +import eu.kanade.tachiyomi.source.SourceManager +import eu.kanade.tachiyomi.ui.main.MainActivity +import eu.kanade.tachiyomi.ui.migration.MigrationController +import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.util.view.snack +import eu.kanade.tachiyomi.util.view.withFadeTransaction +import uy.kohesive.injekt.injectLazy + +class SettingsBrowseController : SettingsController() { + + val sourceManager: SourceManager by injectLazy() + + override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + titleRes = R.string.sources + + preferenceCategory { + titleRes = R.string.extensions + switchPreference { + key = PreferenceKeys.automaticExtUpdates + titleRes = R.string.check_for_extension_updates + defaultValue = true + + onChange { + it as Boolean + ExtensionUpdateJob.setupTask(it) + true + } + } + } + + preferenceCategory { + titleRes = R.string.pref_global_search + switchPreference { + key = PreferenceKeys.onlySearchPinned + titleRes = R.string.only_search_pinned_when + } + } + + preferenceCategory { + titleRes = R.string.migration + // Only show this if someone has mass migrated manga once + + preference { + titleRes = R.string.source_migration + onClick { router.pushController(MigrationController().withFadeTransaction()) } + } + if (preferences.skipPreMigration().getOrDefault() || preferences.migrationSources() + .isSet() + ) { + switchPreference { + key = PreferenceKeys.skipPreMigration + titleRes = R.string.skip_pre_migration + summaryRes = R.string.use_last_saved_migration_preferences + defaultValue = false + } + } + preference { + titleRes = R.string.match_pinned_sources + summaryRes = R.string.only_enable_pinned_for_migration + onClick { + val ogSources = preferences.migrationSources().get() + val pinnedSources = + (preferences.pinnedCatalogues().get() ?: emptySet()).joinToString("/") + preferences.migrationSources().set(pinnedSources) + (activity as? MainActivity)?.setUndoSnackBar(view?.snack( + R.string.migration_sources_set + ) { + setAction(R.string.undo) { + preferences.migrationSources().set(ogSources) + } + }) + } + } + + preference { + titleRes = R.string.match_enabled_sources + summaryRes = R.string.only_enable_enabled_for_migration + onClick { + val ogSources = preferences.migrationSources().get() + val languages = preferences.enabledLanguages().getOrDefault() + val hiddenCatalogues = preferences.hiddenSources().getOrDefault() + val enabledSources = + sourceManager.getCatalogueSources().filter { it.lang in languages } + .filterNot { it.id.toString() in hiddenCatalogues } + .sortedBy { "(${it.lang}) ${it.name}" } + .joinToString("/") { it.id.toString() } + preferences.migrationSources().set(enabledSources) + (activity as? MainActivity)?.setUndoSnackBar(view?.snack(R.string.migration_sources_set) { + setAction(R.string.undo) { + preferences.migrationSources().set(ogSources) + } + }) + } + } + } + preference { + iconRes = R.drawable.ic_info_outline_24dp + iconTint = activity?.getResourceColor(android.R.attr.textColorSecondary) ?: 0 + summaryRes = R.string.you_can_migrate_in_library + isEnabled = false + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 1c62574bf1..dff4bcc44a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -6,7 +6,6 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.library.LibraryUpdateJob -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.category.CategoryController import eu.kanade.tachiyomi.util.view.withFadeTransaction import uy.kohesive.injekt.Injekt @@ -161,18 +160,5 @@ class SettingsLibraryController : SettingsController() { defaultValue = true } } - if (preferences.skipPreMigration().getOrDefault() || preferences.migrationSources().getOrDefault().isNotEmpty()) { - preferenceCategory { - titleRes = R.string.migration - // Only show this if someone has mass migrated manga once - - switchPreference { - key = Keys.skipPreMigration - titleRes = R.string.skip_pre_migration - summaryRes = R.string.use_last_saved_migration_preferences - defaultValue = false - } - } - } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt index 61d62f1f98..51b29e63b4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt @@ -7,7 +7,6 @@ import androidx.preference.PreferenceScreen import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.migration.MigrationController import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.view.withFadeTransaction @@ -48,10 +47,10 @@ class SettingsMainController : SettingsController() { onClick { navigateTo(SettingsDownloadController()) } } preference { - iconRes = R.drawable.ic_swap_calls_white_24dp + iconRes = R.drawable.ic_browse_24dp iconTint = tintColor - titleRes = R.string.source_migration - onClick { navigateTo(MigrationController()) } + titleRes = R.string.sources + onClick { navigateTo(SettingsBrowseController()) } } preference { iconRes = R.drawable.ic_sync_black_24dp diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt index e255f81084..1fa01ef3ae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt @@ -104,11 +104,16 @@ open class GlobalSearchPresenter( val hiddenCatalogues = preferencesHelper.hiddenSources().getOrDefault() val pinnedCatalogues = preferencesHelper.pinnedCatalogues().getOrDefault() - return sourceManager.getCatalogueSources() + val list = sourceManager.getCatalogueSources() .filter { it.lang in languages } .filterNot { it.id.toString() in hiddenCatalogues } .sortedBy { "(${it.lang}) ${it.name}" } - .sortedBy { it.id.toString() !in pinnedCatalogues } + + return if (preferencesHelper.onlySearchPinned().get()) { + list.filter { it.id.toString() in pinnedCatalogues } + } else { + list.sortedBy { it.id.toString() !in pinnedCatalogues } + } } private fun getSourcesToQuery(): List { diff --git a/app/src/main/res/drawable/ic_info_outline_24dp.xml b/app/src/main/res/drawable/ic_info_outline_24dp.xml new file mode 100644 index 0000000000..9c51a4ffb9 --- /dev/null +++ b/app/src/main/res/drawable/ic_info_outline_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/auto_ext_checkbox.xml b/app/src/main/res/layout/auto_ext_checkbox.xml deleted file mode 100644 index 876882efcd..0000000000 --- a/app/src/main/res/layout/auto_ext_checkbox.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/extension_main.xml b/app/src/main/res/menu/extension_main.xml index e15943375e..ee4296071a 100644 --- a/app/src/main/res/menu/extension_main.xml +++ b/app/src/main/res/menu/extension_main.xml @@ -12,12 +12,4 @@ android:title="@string/search" app:actionViewClass="androidx.appcompat.widget.SearchView" app:showAsAction="collapseActionView|ifRoom" /> - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8868bf6ca..4570a3e112 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -181,8 +181,6 @@ Sort by ignoring articles When sorting alphabetically, sort ignoring articles (a, an, the) at the start of manga titles - Use last saved pre-migration preferences - and sources to mass migrate Categories to include in global update Include in global update Automatically refresh covers @@ -241,7 +239,6 @@ Extensions Extension Updates - Notify when extension updates are available Extension info Details Obsolete @@ -547,6 +544,22 @@ Delete old and unused cached covers of manga in your library that has been updated.\nCurrently using: %1$s + + Global search + Check for extension updates + Only search pinned sources + Match pinned sources + Match enabled sources + Only enable your pinned sources for + migration + Only enable your currently enabled sources for + migration + Use last saved pre-migration preferences + and sources to mass migrate + Migration sources set + You can also migrate by selecting manga in your + library + Version Build time