Move categories up in library settings

This commit is contained in:
arkon 2020-05-23 10:33:49 -04:00
parent 914f5e569b
commit 4fdb4f14a8

View File

@ -44,6 +44,9 @@ class SettingsLibraryController : SettingsController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
titleRes = R.string.pref_category_library titleRes = R.string.pref_category_library
val dbCategories = db.getCategories().executeAsBlocking()
val categories = listOf(Category.createDefault()) + dbCategories
preferenceCategory { preferenceCategory {
titleRes = R.string.pref_category_display titleRes = R.string.pref_category_display
@ -74,8 +77,40 @@ class SettingsLibraryController : SettingsController() {
} }
} }
val dbCategories = db.getCategories().executeAsBlocking() preferenceCategory {
val categories = listOf(Category.createDefault()) + dbCategories 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 { preferenceCategory {
titleRes = R.string.pref_category_library_update titleRes = R.string.pref_category_library_update
@ -170,41 +205,6 @@ class SettingsLibraryController : SettingsController() {
defaultValue = false 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() { class LibraryColumnsDialog : DialogController() {