Categorize library settings
This commit is contained in:
parent
6f84815801
commit
4f03ee814a
@ -27,134 +27,147 @@ 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
|
||||||
|
|
||||||
preference {
|
preferenceCategory {
|
||||||
titleRes = R.string.pref_library_columns
|
titleRes = R.string.pref_category_library_display
|
||||||
onClick {
|
|
||||||
LibraryColumnsDialog().showDialog(router)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getColumnValue(value: Int): String {
|
preference {
|
||||||
return if (value == 0)
|
titleRes = R.string.pref_library_columns
|
||||||
context.getString(R.string.default_columns)
|
onClick {
|
||||||
else
|
LibraryColumnsDialog().showDialog(router)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
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()
|
fun getColumnValue(value: Int): String {
|
||||||
.subscribeUntilDestroy { isVisible = it > 0 }
|
return if (value == 0)
|
||||||
|
context.getString(R.string.default_columns)
|
||||||
|
else
|
||||||
|
value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
onChange {
|
Observable.combineLatest(
|
||||||
// Post to event looper to allow the preference to be updated.
|
preferences.portraitColumns().asObservable(),
|
||||||
Handler().post { LibraryUpdateJob.setupTask() }
|
preferences.landscapeColumns().asObservable()
|
||||||
true
|
) { 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 dbCategories = db.getCategories().executeAsBlocking()
|
||||||
val categories = listOf(Category.createDefault()) + dbCategories
|
val categories = listOf(Category.createDefault()) + dbCategories
|
||||||
|
|
||||||
multiSelectListPreference {
|
preferenceCategory {
|
||||||
key = Keys.libraryUpdateCategories
|
titleRes = R.string.pref_category_library_update
|
||||||
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())
|
intListPreference {
|
||||||
context.getString(R.string.all)
|
key = Keys.libraryUpdateInterval
|
||||||
else
|
titleRes = R.string.pref_library_update_interval
|
||||||
selectedCategories.joinToString { it.name }
|
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)
|
||||||
}
|
}
|
||||||
}
|
true
|
||||||
intListPreference {
|
}
|
||||||
key = Keys.libraryUpdatePrioritization
|
}
|
||||||
titleRes = R.string.pref_library_update_prioritization
|
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:
|
preferences.libraryUpdateInterval().asObservable()
|
||||||
// ../../data/library/LibraryUpdateRanker.kt
|
.subscribeUntilDestroy { isVisible = it > 0 }
|
||||||
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()
|
onChange {
|
||||||
entryValues = priorities.map { it.first }.toTypedArray()
|
// Post to event looper to allow the preference to be updated.
|
||||||
defaultValue = defaultPriority.first
|
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() }
|
summary = if (selectedCategories.isEmpty())
|
||||||
summaryRes = selectedPriority?.second ?: defaultPriority.second
|
context.getString(R.string.all)
|
||||||
onChange { newValue ->
|
else
|
||||||
summaryRes = priorities.find {
|
selectedCategories.joinToString { it.name }
|
||||||
it.first == (newValue as String)
|
}
|
||||||
}?.second ?: defaultPriority.second
|
}
|
||||||
true
|
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)) +
|
preferenceCategory {
|
||||||
categories.map { it.name }.toTypedArray()
|
titleRes = R.string.pref_category_library_categories
|
||||||
entryValues = arrayOf("-1") + categories.map { it.id.toString() }.toTypedArray()
|
|
||||||
defaultValue = "-1"
|
|
||||||
|
|
||||||
val selectedCategory = categories.find { it.id == preferences.defaultCategory() }
|
intListPreference {
|
||||||
summary = selectedCategory?.name ?: context.getString(R.string.default_category_summary)
|
key = Keys.defaultCategory
|
||||||
onChange { newValue ->
|
titleRes = R.string.default_category
|
||||||
summary = categories.find {
|
|
||||||
it.id == (newValue as String).toInt()
|
entries = arrayOf(context.getString(R.string.default_category_summary)) +
|
||||||
}?.name ?: context.getString(R.string.default_category_summary)
|
categories.map { it.name }.toTypedArray()
|
||||||
true
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,12 +126,16 @@
|
|||||||
<string name="pref_start_screen">Start screen</string>
|
<string name="pref_start_screen">Start screen</string>
|
||||||
<string name="pref_language">Language</string>
|
<string name="pref_language">Language</string>
|
||||||
<string name="system_default">System default</string>
|
<string name="system_default">System default</string>
|
||||||
|
<string name="pref_date_format">Date format</string>
|
||||||
|
|
||||||
<!-- Library section -->
|
<!-- Library section -->
|
||||||
|
<string name="pref_category_library_display">Display</string>
|
||||||
<string name="pref_library_columns">Library manga per row</string>
|
<string name="pref_library_columns">Library manga per row</string>
|
||||||
<string name="portrait">Portrait</string>
|
<string name="portrait">Portrait</string>
|
||||||
<string name="landscape">Landscape</string>
|
<string name="landscape">Landscape</string>
|
||||||
<string name="default_columns">Default</string>
|
<string name="default_columns">Default</string>
|
||||||
|
|
||||||
|
<string name="pref_category_library_update">Updates</string>
|
||||||
<string name="pref_library_update_interval">Library update frequency</string>
|
<string name="pref_library_update_interval">Library update frequency</string>
|
||||||
<string name="update_never">Manual</string>
|
<string name="update_never">Manual</string>
|
||||||
<string name="update_1hour">Hourly</string>
|
<string name="update_1hour">Hourly</string>
|
||||||
@ -143,21 +147,20 @@
|
|||||||
<string name="update_48hour">Every 2 days</string>
|
<string name="update_48hour">Every 2 days</string>
|
||||||
<string name="update_weekly">Weekly</string>
|
<string name="update_weekly">Weekly</string>
|
||||||
<string name="update_monthly">Monthly</string>
|
<string name="update_monthly">Monthly</string>
|
||||||
<string name="pref_library_update_categories">Categories to include in global update</string>
|
|
||||||
<string name="all">All</string>
|
|
||||||
<string name="pref_library_update_prioritization">Library update order</string>
|
<string name="pref_library_update_prioritization">Library update order</string>
|
||||||
<string name="pref_library_update_restriction">Library update restrictions</string>
|
<string name="pref_library_update_restriction">Library update restrictions</string>
|
||||||
<string name="pref_library_update_restriction_summary">Update only when the conditions are met</string>
|
<string name="pref_library_update_restriction_summary">Update only when the conditions are met</string>
|
||||||
<string name="wifi">Wi-Fi</string>
|
<string name="wifi">Wi-Fi</string>
|
||||||
<string name="charging">Charging</string>
|
<string name="charging">Charging</string>
|
||||||
<string name="pref_update_only_non_completed">Only update ongoing manga</string>
|
<string name="pref_update_only_non_completed">Only update ongoing manga</string>
|
||||||
<string name="pref_auto_update_manga_sync">Sync chapters after reading</string>
|
|
||||||
<string name="pref_ask_update_manga_sync">Confirm before updating</string>
|
<string name="pref_category_library_categories">Categories</string>
|
||||||
<string name="pref_date_format">Date format</string>
|
|
||||||
<string name="default_category">Default category</string>
|
<string name="default_category">Default category</string>
|
||||||
<string name="default_category_summary">Always ask</string>
|
<string name="default_category_summary">Always ask</string>
|
||||||
|
<string name="pref_library_update_categories">Categories to include in global update</string>
|
||||||
|
<string name="all">All</string>
|
||||||
|
|
||||||
<!-- Extension section -->
|
<!-- Extension section -->
|
||||||
<string name="all_lang">All</string>
|
<string name="all_lang">All</string>
|
||||||
<string name="ext_details">Details</string>
|
<string name="ext_details">Details</string>
|
||||||
<string name="ext_update">Update</string>
|
<string name="ext_update">Update</string>
|
||||||
@ -239,7 +242,6 @@
|
|||||||
<string name="color_filter_b_value">B</string>
|
<string name="color_filter_b_value">B</string>
|
||||||
<string name="color_filter_a_value">A</string>
|
<string name="color_filter_a_value">A</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Downloads section -->
|
<!-- Downloads section -->
|
||||||
<string name="pref_download_directory">Downloads directory</string>
|
<string name="pref_download_directory">Downloads directory</string>
|
||||||
<string name="pref_download_only_over_wifi">Only download over Wi-Fi</string>
|
<string name="pref_download_only_over_wifi">Only download over Wi-Fi</string>
|
||||||
@ -256,6 +258,7 @@
|
|||||||
<string name="pref_download_new_categories">Categories to include in download</string>
|
<string name="pref_download_new_categories">Categories to include in download</string>
|
||||||
|
|
||||||
<!-- Sync section -->
|
<!-- Sync section -->
|
||||||
|
<string name="pref_auto_update_manga_sync">Sync chapters after reading</string>
|
||||||
<string name="services">Services</string>
|
<string name="services">Services</string>
|
||||||
|
|
||||||
<!-- Backup section -->
|
<!-- Backup section -->
|
||||||
|
Loading…
Reference in New Issue
Block a user