From 4f03ee814aae05596f947818fb54ce154e9d5f2e Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 2 Feb 2020 18:04:50 -0500 Subject: [PATCH] Categorize library settings --- .../ui/setting/SettingsLibraryController.kt | 231 +++++++++--------- app/src/main/res/values/strings.xml | 17 +- 2 files changed, 132 insertions(+), 116 deletions(-) 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 59b170e60..ec0535116 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 @@ -27,134 +27,147 @@ 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) - } + preferenceCategory { + titleRes = R.string.pref_category_library_display - 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" - } - } - intListPreference { - 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 = arrayOf("0", "1", "2", "3", "6", "12", "24", "48") - defaultValue = "0" - summary = "%s" - - onChange { newValue -> - // Always cancel the previous task, it seems that sometimes they are not updated. - LibraryUpdateJob.cancelTask() - - val interval = (newValue as String).toInt() - if (interval > 0) { - LibraryUpdateJob.setupTask(interval) + preference { + titleRes = R.string.pref_library_columns + onClick { + LibraryColumnsDialog().showDialog(router) } - true - } - } - multiSelectListPreference { - key = Keys.libraryUpdateRestriction - titleRes = R.string.pref_library_update_restriction - entriesRes = arrayOf(R.string.wifi, R.string.charging) - entryValues = arrayOf("wifi", "ac") - summaryRes = R.string.pref_library_update_restriction_summary - preferences.libraryUpdateInterval().asObservable() - .subscribeUntilDestroy { isVisible = it > 0 } + fun getColumnValue(value: Int): String { + return if (value == 0) + context.getString(R.string.default_columns) + else + value.toString() + } - onChange { - // Post to event looper to allow the preference to be updated. - Handler().post { LibraryUpdateJob.setupTask() } - 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" + } } } - switchPreference { - key = Keys.updateOnlyNonCompleted - titleRes = R.string.pref_update_only_non_completed - defaultValue = false - } val dbCategories = db.getCategories().executeAsBlocking() val categories = listOf(Category.createDefault()) + dbCategories - multiSelectListPreference { - key = Keys.libraryUpdateCategories - titleRes = R.string.pref_library_update_categories - entries = categories.map { it.name }.toTypedArray() - entryValues = categories.map { it.id.toString() }.toTypedArray() - preferences.libraryUpdateCategories().asObservable() - .subscribeUntilDestroy { - val selectedCategories = it - .mapNotNull { id -> categories.find { it.id == id.toInt() } } - .sortedBy { it.order } + preferenceCategory { + titleRes = R.string.pref_category_library_update - summary = if (selectedCategories.isEmpty()) - context.getString(R.string.all) - else - selectedCategories.joinToString { it.name } + intListPreference { + 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 = arrayOf("0", "1", "2", "3", "6", "12", "24", "48") + defaultValue = "0" + summary = "%s" + + onChange { newValue -> + // Always cancel the previous task, it seems that sometimes they are not updated. + LibraryUpdateJob.cancelTask() + + val interval = (newValue as String).toInt() + if (interval > 0) { + LibraryUpdateJob.setupTask(interval) } - } - intListPreference { - key = Keys.libraryUpdatePrioritization - titleRes = R.string.pref_library_update_prioritization + true + } + } + multiSelectListPreference { + key = Keys.libraryUpdateRestriction + titleRes = R.string.pref_library_update_restriction + entriesRes = arrayOf(R.string.wifi, R.string.charging) + entryValues = arrayOf("wifi", "ac") + summaryRes = R.string.pref_library_update_restriction_summary - // The following array lines up with the list rankingScheme in: - // ../../data/library/LibraryUpdateRanker.kt - val priorities = arrayOf( - Pair("0", R.string.action_sort_alpha), - Pair("1", R.string.action_sort_last_updated) - ) - val defaultPriority = priorities[0] + preferences.libraryUpdateInterval().asObservable() + .subscribeUntilDestroy { isVisible = it > 0 } - entriesRes = priorities.map { it.second }.toTypedArray() - entryValues = priorities.map { it.first }.toTypedArray() - defaultValue = defaultPriority.first + 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 + } + multiSelectListPreference { + key = Keys.libraryUpdateCategories + titleRes = R.string.pref_library_update_categories + entries = categories.map { it.name }.toTypedArray() + entryValues = categories.map { it.id.toString() }.toTypedArray() + preferences.libraryUpdateCategories().asObservable() + .subscribeUntilDestroy { + val selectedCategories = it + .mapNotNull { id -> categories.find { it.id == id.toInt() } } + .sortedBy { it.order } - val selectedPriority = priorities.find { it.first.toInt() == preferences.libraryUpdatePrioritization().getOrDefault() } - summaryRes = selectedPriority?.second ?: defaultPriority.second - onChange { newValue -> - summaryRes = priorities.find { - it.first == (newValue as String) - }?.second ?: defaultPriority.second - true + summary = if (selectedCategories.isEmpty()) + context.getString(R.string.all) + else + selectedCategories.joinToString { it.name } + } + } + intListPreference { + key = Keys.libraryUpdatePrioritization + titleRes = R.string.pref_library_update_prioritization + + // The following array lines up with the list rankingScheme in: + // ../../data/library/LibraryUpdateRanker.kt + val priorities = arrayOf( + Pair("0", R.string.action_sort_alpha), + Pair("1", R.string.action_sort_last_updated) + ) + val defaultPriority = priorities[0] + + entriesRes = priorities.map { it.second }.toTypedArray() + entryValues = priorities.map { it.first }.toTypedArray() + defaultValue = defaultPriority.first + + val selectedPriority = priorities.find { it.first.toInt() == preferences.libraryUpdatePrioritization().getOrDefault() } + summaryRes = selectedPriority?.second ?: defaultPriority.second + onChange { newValue -> + summaryRes = priorities.find { + it.first == (newValue as String) + }?.second ?: defaultPriority.second + true + } } } - intListPreference { - key = Keys.defaultCategory - titleRes = R.string.default_category - entries = arrayOf(context.getString(R.string.default_category_summary)) + - categories.map { it.name }.toTypedArray() - entryValues = arrayOf("-1") + categories.map { it.id.toString() }.toTypedArray() - defaultValue = "-1" + preferenceCategory { + titleRes = R.string.pref_category_library_categories - 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 String).toInt() - }?.name ?: context.getString(R.string.default_category_summary) - true + intListPreference { + key = Keys.defaultCategory + titleRes = R.string.default_category + + entries = arrayOf(context.getString(R.string.default_category_summary)) + + categories.map { it.name }.toTypedArray() + entryValues = arrayOf("-1") + categories.map { it.id.toString() }.toTypedArray() + 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 String).toInt() + }?.name ?: context.getString(R.string.default_category_summary) + true + } } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d0182d860..1ff5d3869 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -126,12 +126,16 @@ Start screen Language System default + Date format + Display Library manga per row Portrait Landscape Default + + Updates Library update frequency Manual Hourly @@ -143,21 +147,20 @@ Every 2 days Weekly Monthly - Categories to include in global update - All Library update order Library update restrictions Update only when the conditions are met Wi-Fi Charging Only update ongoing manga - Sync chapters after reading - Confirm before updating - Date format + + Categories Default category Always ask + Categories to include in global update + All - + All Details Update @@ -239,7 +242,6 @@ B A - Downloads directory Only download over Wi-Fi @@ -256,6 +258,7 @@ Categories to include in download + Sync chapters after reading Services