From b92c6cfdab5292d323b3d445c0d9e4ee738cf81d Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 2 Feb 2020 18:04:50 -0500 Subject: [PATCH] Categorize library settings --- .../data/library/LibraryUpdateService.kt | 1 - .../ui/setting/SettingsLibraryController.kt | 283 ++++++++++-------- app/src/main/res/values/strings.xml | 14 +- 3 files changed, 161 insertions(+), 137 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index cf10ec39b3..1309117dc0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.library -import android.app.ActivityManager import android.app.Notification import android.app.PendingIntent import android.app.Service 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 7de68a9c43..e5129bbee0 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 @@ -26,150 +26,167 @@ class SettingsLibraryController : SettingsController() { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { titleRes = R.string.pref_category_library - - preference { - titleRes = R.string.pref_library_columns - onClick { - LibraryColumnsDialog().showDialog(router) - } - - fun getColumnValue(value: Int): String { - return if (value == 0) - context.getString(R.string.default_columns) - else - value.toString() - } - - Observable.combineLatest( - preferences.portraitColumns().asObservable(), - preferences.landscapeColumns().asObservable(), - { portraitCols, landscapeCols -> Pair(portraitCols, landscapeCols) }) - .subscribeUntilDestroy { (portraitCols, landscapeCols) -> - val portrait = getColumnValue(portraitCols) - val landscape = getColumnValue(landscapeCols) - summary = "${context.getString(R.string.portrait)}: $portrait, " + - "${context.getString(R.string.landscape)}: $landscape" + preferenceCategory { + titleRes = R.string.pref_category_library_display + preference { + titleRes = R.string.pref_library_columns + onClick { + LibraryColumnsDialog().showDialog(router) } - } - intListPreference(activity) { - key = Keys.libraryUpdateInterval - titleRes = R.string.pref_library_update_interval - entriesRes = arrayOf(R.string.update_never, R.string.update_1hour, - R.string.update_2hour, R.string.update_3hour, R.string.update_6hour, - R.string.update_12hour, R.string.update_24hour, R.string.update_48hour) - entryValues = listOf(0, 1, 2, 3, 6, 12, 24, 48) - defaultValue = 0 - onChange { newValue -> - // Always cancel the previous task, it seems that sometimes they are not updated. - LibraryUpdateJob.cancelTask() - - val interval = newValue as Int - if (interval > 0) { - LibraryUpdateJob.setupTask(interval) + fun getColumnValue(value: Int): String { + return if (value == 0) context.getString(R.string.default_columns) + else value.toString() } - true + + Observable.combineLatest(preferences.portraitColumns().asObservable(), + preferences.landscapeColumns().asObservable(), + { portraitCols, landscapeCols -> Pair(portraitCols, landscapeCols) }) + .subscribeUntilDestroy { (portraitCols, landscapeCols) -> + val portrait = getColumnValue(portraitCols) + val landscape = getColumnValue(landscapeCols) + summary = + "${context.getString(R.string.portrait)}: $portrait, " + "${context.getString( + R.string.landscape + )}: $landscape" + } } - } - multiSelectListPreferenceMat(activity) { - key = Keys.libraryUpdateRestriction - titleRes = R.string.pref_library_update_restriction - entriesRes = arrayOf(R.string.wifi, R.string.charging) - entryValues = listOf("wifi", "ac") - customSummaryRes = R.string.pref_library_update_restriction_summary - preferences.libraryUpdateInterval().asObservable() - .subscribeUntilDestroy { isVisible = it > 0 } - - onChange { - // Post to event looper to allow the preference to be updated. - Handler().post { LibraryUpdateJob.setupTask() } - true - } - } - switchPreference { - key = Keys.updateOnlyNonCompleted - titleRes = R.string.pref_update_only_non_completed - defaultValue = false - } - - val dbCategories = db.getCategories().executeAsBlocking() - - multiSelectListPreferenceMat(activity) { - key = Keys.libraryUpdateCategories - titleRes = R.string.pref_library_update_categories - entries = dbCategories.map { it.name } - entryValues = dbCategories.map { it.id.toString() } - allSelectionRes = R.string.all - - preferences.libraryUpdateCategories().asObservable() - .subscribeUntilDestroy { - val selectedCategories = it - .mapNotNull { id -> dbCategories.find { it.id == id.toInt() } } - .sortedBy { it.order } - - customSummary = if (selectedCategories.isEmpty()) - context.getString(R.string.all) - else - selectedCategories.joinToString { it.name } - } - } - intListPreference(activity) { - key = Keys.libraryUpdatePrioritization - titleRes = R.string.pref_library_update_prioritization - - // The following array lines up with the list rankingScheme in: - // ../../data/library/LibraryUpdateRanker.kt - entriesRes = arrayOf( - R.string.action_sort_alpha, - R.string.action_sort_last_updated - ) - entryRange = 0..1 - defaultValue = 0 - summaryRes = R.string.pref_library_update_prioritization_summary - } - intListPreference(activity) { - key = Keys.defaultCategory - titleRes = R.string.default_category - - val categories = listOf(Category.createDefault(context)) + dbCategories - entries = listOf(context.getString(R.string.default_category_summary)) + - categories.map { it.name }.toTypedArray() - entryValues = listOf(-1) + categories.mapNotNull { it.id }.toList() - defaultValue = "-1" - - val selectedCategory = categories.find { it.id == preferences.defaultCategory() } - summary = selectedCategory?.name ?: context.getString(R.string.default_category_summary) - onChange { newValue -> - summary = categories.find { - it.id == newValue as Int - }?.name ?: context.getString(R.string.default_category_summary) - true - } - } - - // Only show this if someone has mass migrated manga once - if (preferences.skipPreMigration().getOrDefault() || preferences.migrationSources() - .getOrDefault().isNotEmpty()) { switchPreference { - key = Keys.skipPreMigration - titleRes = R.string.pref_skip_pre_migration - summaryRes = R.string.pref_skip_pre_migration_summary + key = Keys.removeArticles + titleRes = R.string.pref_remove_articles + summaryRes = R.string.pref_remove_articles_summary defaultValue = false } } - switchPreference { - key = Keys.removeArticles - titleRes = R.string.pref_remove_articles - summaryRes = R.string.pref_remove_articles_summary - defaultValue = false + val dbCategories = db.getCategories().executeAsBlocking() + + preferenceCategory { + titleRes = R.string.pref_category_library_update + intListPreference(activity) { + key = Keys.libraryUpdateInterval + titleRes = R.string.pref_library_update_interval + entriesRes = arrayOf( + R.string.update_never, + R.string.update_1hour, + R.string.update_2hour, + R.string.update_3hour, + R.string.update_6hour, + R.string.update_12hour, + R.string.update_24hour, + R.string.update_48hour + ) + entryValues = listOf(0, 1, 2, 3, 6, 12, 24, 48) + defaultValue = 0 + + onChange { newValue -> + // Always cancel the previous task, it seems that sometimes they are not updated. + LibraryUpdateJob.cancelTask() + + val interval = newValue as Int + if (interval > 0) { + LibraryUpdateJob.setupTask(interval) + } + true + } + } + multiSelectListPreferenceMat(activity) { + key = Keys.libraryUpdateRestriction + titleRes = R.string.pref_library_update_restriction + entriesRes = arrayOf(R.string.wifi, R.string.charging) + entryValues = listOf("wifi", "ac") + customSummaryRes = R.string.pref_library_update_restriction_summary + + preferences.libraryUpdateInterval().asObservable() + .subscribeUntilDestroy { isVisible = it > 0 } + + onChange { + // Post to event looper to allow the preference to be updated. + Handler().post { LibraryUpdateJob.setupTask() } + true + } + } + switchPreference { + key = Keys.updateOnlyNonCompleted + titleRes = R.string.pref_update_only_non_completed + defaultValue = false + } + + intListPreference(activity) { + key = Keys.libraryUpdatePrioritization + titleRes = R.string.pref_library_update_prioritization + + // The following array lines up with the list rankingScheme in: + // ../../data/library/LibraryUpdateRanker.kt + entriesRes = arrayOf( + R.string.action_sort_alpha, R.string.action_sort_last_updated + ) + entryRange = 0..1 + defaultValue = 0 + summaryRes = R.string.pref_library_update_prioritization_summary + } + + switchPreference { + key = Keys.refreshCoversToo + titleRes = R.string.pref_refresh_covers_too + summaryRes = R.string.pref_refresh_covers_too_summary + defaultValue = true + } + + multiSelectListPreferenceMat(activity) { + key = Keys.libraryUpdateCategories + titleRes = R.string.pref_library_update_categories + entries = dbCategories.map { it.name } + entryValues = dbCategories.map { it.id.toString() } + allSelectionRes = R.string.all + + preferences.libraryUpdateCategories().asObservable().subscribeUntilDestroy { + val selectedCategories = + it.mapNotNull { id -> dbCategories.find { it.id == id.toInt() } } + .sortedBy { it.order } + + customSummary = + if (selectedCategories.isEmpty()) context.getString(R.string.all) + else selectedCategories.joinToString { it.name } + } + } } - switchPreference { - key = Keys.refreshCoversToo - titleRes = R.string.pref_refresh_covers_too - summaryRes = R.string.pref_refresh_covers_too_summary - defaultValue = true + preferenceCategory { + titleRes = R.string.pref_category_library_categories + intListPreference(activity) { + key = Keys.defaultCategory + titleRes = R.string.default_category + + val categories = listOf(Category.createDefault(context)) + dbCategories + entries = + listOf(context.getString(R.string.default_category_summary)) + categories.map { it.name }.toTypedArray() + entryValues = listOf(-1) + categories.mapNotNull { it.id }.toList() + defaultValue = "-1" + + val selectedCategory = categories.find { it.id == preferences.defaultCategory() } + summary = + selectedCategory?.name ?: context.getString(R.string.default_category_summary) + onChange { newValue -> + summary = categories.find { + it.id == newValue as Int + }?.name ?: context.getString(R.string.default_category_summary) + true + } + } + } + if (preferences.skipPreMigration().getOrDefault() || preferences.migrationSources().getOrDefault().isNotEmpty()) { + preferenceCategory { + titleRes = R.string.pref_category_library_migration + // Only show this if someone has mass migrated manga once + + switchPreference { + key = Keys.skipPreMigration + titleRes = R.string.pref_skip_pre_migration + summaryRes = R.string.pref_skip_pre_migration_summary + defaultValue = false + } + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b5849b76f2..2728edb84a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -134,12 +134,16 @@ Start screen Language System default + Date format + Display Library manga per row Portrait Landscape Default + + Updates Library update frequency Manual Hourly @@ -150,8 +154,7 @@ Daily Every 2 days Weekly - Categories to include in global update - All + Monthly Library update order Select the order in which Tachiyomi checks for update Library update restrictions @@ -166,8 +169,11 @@ Skip pre-migration Use last saved pre-migration preferences and sources to mass migrate + Categories Default category Always ask + Categories to include in global update + All Lock with biometrics Lock when idle Always @@ -181,6 +187,9 @@ Refresh covers in library as well when updating library (overwrites local covers) + Migration + + All Details @@ -263,7 +272,6 @@ Smart (based on page) Smart (based on page and theme) - Download location Only download over Wi-Fi