mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-28 09:15:12 +03:00
Categorize library settings
This commit is contained in:
parent
6f84815801
commit
4f03ee814a
2 changed files with 132 additions and 116 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,12 +126,16 @@
|
|||
<string name="pref_start_screen">Start screen</string>
|
||||
<string name="pref_language">Language</string>
|
||||
<string name="system_default">System default</string>
|
||||
<string name="pref_date_format">Date format</string>
|
||||
|
||||
<!-- Library section -->
|
||||
<string name="pref_category_library_display">Display</string>
|
||||
<string name="pref_library_columns">Library manga per row</string>
|
||||
<string name="portrait">Portrait</string>
|
||||
<string name="landscape">Landscape</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="update_never">Manual</string>
|
||||
<string name="update_1hour">Hourly</string>
|
||||
|
@ -143,21 +147,20 @@
|
|||
<string name="update_48hour">Every 2 days</string>
|
||||
<string name="update_weekly">Weekly</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_restriction">Library update restrictions</string>
|
||||
<string name="pref_library_update_restriction_summary">Update only when the conditions are met</string>
|
||||
<string name="wifi">Wi-Fi</string>
|
||||
<string name="charging">Charging</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_date_format">Date format</string>
|
||||
|
||||
<string name="pref_category_library_categories">Categories</string>
|
||||
<string name="default_category">Default category</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="ext_details">Details</string>
|
||||
<string name="ext_update">Update</string>
|
||||
|
@ -239,7 +242,6 @@
|
|||
<string name="color_filter_b_value">B</string>
|
||||
<string name="color_filter_a_value">A</string>
|
||||
|
||||
|
||||
<!-- Downloads section -->
|
||||
<string name="pref_download_directory">Downloads directory</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>
|
||||
|
||||
<!-- Sync section -->
|
||||
<string name="pref_auto_update_manga_sync">Sync chapters after reading</string>
|
||||
<string name="services">Services</string>
|
||||
|
||||
<!-- Backup section -->
|
||||
|
|
Loading…
Reference in a new issue