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 3044355e95..ef306ec969 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 @@ -44,6 +44,9 @@ class SettingsLibraryController : SettingsController() { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { titleRes = R.string.pref_category_library + val dbCategories = db.getCategories().executeAsBlocking() + val categories = listOf(Category.createDefault()) + dbCategories + preferenceCategory { titleRes = R.string.pref_category_display @@ -74,8 +77,40 @@ class SettingsLibraryController : SettingsController() { } } - val dbCategories = db.getCategories().executeAsBlocking() - val categories = listOf(Category.createDefault()) + dbCategories + preferenceCategory { + titleRes = R.string.pref_category_library_categories + + preference { + titleRes = R.string.action_edit_categories + + val catCount = dbCategories.size + summary = context.resources.getQuantityString(R.plurals.num_categories, catCount, catCount) + + onClick { + router.pushController(CategoryController().withFadeTransaction()) + } + } + + 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 + } + } + } preferenceCategory { titleRes = R.string.pref_category_library_update @@ -170,41 +205,6 @@ class SettingsLibraryController : SettingsController() { defaultValue = false } } - - preferenceCategory { - titleRes = R.string.pref_category_library_categories - - preference { - titleRes = R.string.action_edit_categories - - val catCount = dbCategories.size - summary = context.resources.getQuantityString(R.plurals.num_categories, catCount, catCount) - - onClick { - router.pushController(CategoryController().withFadeTransaction()) - } - } - - 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 - } - } - } } class LibraryColumnsDialog : DialogController() {