|
@@ -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()
|
|
|
- }
|
|
|
+ preference {
|
|
|
+ titleRes = R.string.pref_library_columns
|
|
|
+ onClick {
|
|
|
+ LibraryColumnsDialog().showDialog(router)
|
|
|
+ }
|
|
|
|
|
|
- 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)
|
|
|
+ fun getColumnValue(value: Int): String {
|
|
|
+ return if (value == 0)
|
|
|
+ context.getString(R.string.default_columns)
|
|
|
+ else
|
|
|
+ value.toString()
|
|
|
}
|
|
|
- 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 }
|
|
|
-
|
|
|
- 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 }
|
|
|
-
|
|
|
- summary = if (selectedCategories.isEmpty())
|
|
|
- context.getString(R.string.all)
|
|
|
- else
|
|
|
- selectedCategories.joinToString { it.name }
|
|
|
+ preferenceCategory {
|
|
|
+ titleRes = R.string.pref_category_library_update
|
|
|
+
|
|
|
+ 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
|
|
|
-
|
|
|
- // 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
|
|
|
+ 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 }
|
|
|
+
|
|
|
+ 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 }
|
|
|
+
|
|
|
+ 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"
|
|
|
-
|
|
|
- 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_categories
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|