mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 23:51:53 +01:00
Fixed #733
Also removed custom summary in favor of using a summary provider
This commit is contained in:
parent
3553013191
commit
f9d42601e0
@ -94,14 +94,14 @@ class SettingsDownloadController : SettingsController() {
|
|||||||
entryValues = dbCategories.map { it.id.toString() }
|
entryValues = dbCategories.map { it.id.toString() }
|
||||||
allSelectionRes = R.string.all
|
allSelectionRes = R.string.all
|
||||||
|
|
||||||
preferences.downloadNew().asImmediateFlow { isVisible = it }
|
preferences.downloadNew().asImmediateFlow(viewScope) { isVisible = it }
|
||||||
|
|
||||||
preferences.downloadNewCategories().asImmediateFlow { list ->
|
preferences.downloadNewCategories().asImmediateFlow(viewScope) { list ->
|
||||||
val selectedCategories = list
|
val selectedCategories = list
|
||||||
.mapNotNull { id -> dbCategories.find { it.id == id.toInt() } }
|
.mapNotNull { id -> dbCategories.find { it.id == id.toInt() } }
|
||||||
.sortedBy { it.order }
|
.sortedBy { it.order }
|
||||||
|
|
||||||
customSummary = if (selectedCategories.isEmpty()) {
|
summary = if (selectedCategories.isEmpty()) {
|
||||||
resources?.getString(R.string.all)
|
resources?.getString(R.string.all)
|
||||||
} else {
|
} else {
|
||||||
selectedCategories.joinToString { it.name }
|
selectedCategories.joinToString { it.name }
|
||||||
@ -112,7 +112,7 @@ class SettingsDownloadController : SettingsController() {
|
|||||||
intListPreference(activity) {
|
intListPreference(activity) {
|
||||||
key = Keys.deleteRemovedChapters
|
key = Keys.deleteRemovedChapters
|
||||||
titleRes = R.string.delete_removed_chapters
|
titleRes = R.string.delete_removed_chapters
|
||||||
customSummary = activity?.getString(R.string.delete_downloaded_if_removed_online)
|
summary = activity?.getString(R.string.delete_downloaded_if_removed_online)
|
||||||
entriesRes = arrayOf(
|
entriesRes = arrayOf(
|
||||||
R.string.ask_on_chapters_page,
|
R.string.ask_on_chapters_page,
|
||||||
R.string.always_keep,
|
R.string.always_keep,
|
||||||
|
@ -96,7 +96,7 @@ class SettingsLibraryController : SettingsController() {
|
|||||||
titleRes = R.string.library_update_restriction
|
titleRes = R.string.library_update_restriction
|
||||||
entriesRes = arrayOf(R.string.wifi, R.string.charging)
|
entriesRes = arrayOf(R.string.wifi, R.string.charging)
|
||||||
entryValues = listOf("wifi", "ac")
|
entryValues = listOf("wifi", "ac")
|
||||||
customSummaryRes = R.string.library_update_restriction_summary
|
summaryRes = R.string.library_update_restriction_summary
|
||||||
|
|
||||||
preferences.libraryUpdateInterval().asObservable()
|
preferences.libraryUpdateInterval().asObservable()
|
||||||
.subscribeUntilDestroy { isVisible = it > 0 }
|
.subscribeUntilDestroy { isVisible = it > 0 }
|
||||||
@ -140,7 +140,7 @@ class SettingsLibraryController : SettingsController() {
|
|||||||
list.mapNotNull { id -> dbCategories.find { it.id == id.toInt() } }
|
list.mapNotNull { id -> dbCategories.find { it.id == id.toInt() } }
|
||||||
.sortedBy { it.order }
|
.sortedBy { it.order }
|
||||||
|
|
||||||
customSummary =
|
summary =
|
||||||
if (selectedCategories.isEmpty()) context.getString(R.string.all)
|
if (selectedCategories.isEmpty()) context.getString(R.string.all)
|
||||||
else selectedCategories.joinToString { it.name }
|
else selectedCategories.joinToString { it.name }
|
||||||
}
|
}
|
||||||
|
@ -26,26 +26,15 @@ class IntListMatPreference @JvmOverloads constructor(
|
|||||||
var entries: List<String> = emptyList()
|
var entries: List<String> = emptyList()
|
||||||
var customSelectedValue: Int? = null
|
var customSelectedValue: Int? = null
|
||||||
|
|
||||||
override fun onSetInitialValue(defaultValue: Any?) {
|
override var customSummaryProvider: SummaryProvider<MatPreference>? = SummaryProvider<MatPreference> {
|
||||||
super.onSetInitialValue(defaultValue)
|
|
||||||
defValue = defaultValue as? Int ?: defValue
|
|
||||||
}
|
|
||||||
override fun getSummary(): CharSequence {
|
|
||||||
if (customSummary != null) return customSummary!!
|
|
||||||
if (key == null) return super.getSummary()
|
|
||||||
val index = entryValues.indexOf(prefs.getInt(key, defValue).getOrDefault())
|
val index = entryValues.indexOf(prefs.getInt(key, defValue).getOrDefault())
|
||||||
return if (entries.isEmpty() || index == -1) ""
|
if (entries.isEmpty() || index == -1) ""
|
||||||
else entries[index]
|
else entries[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setSummary(summaryResId: Int) {
|
override fun onSetInitialValue(defaultValue: Any?) {
|
||||||
super.setSummary(summaryResId)
|
super.onSetInitialValue(defaultValue)
|
||||||
customSummary = summary.toString()
|
defValue = defaultValue as? Int ?: defValue
|
||||||
}
|
|
||||||
|
|
||||||
override fun setSummary(summary: CharSequence?) {
|
|
||||||
super.setSummary(summary)
|
|
||||||
customSummary = summary?.toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dialog(): MaterialDialog {
|
override fun dialog(): MaterialDialog {
|
||||||
|
@ -30,10 +30,10 @@ open class ListMatPreference @JvmOverloads constructor(
|
|||||||
super.onSetInitialValue(defaultValue)
|
super.onSetInitialValue(defaultValue)
|
||||||
defValue = defaultValue as? String ?: defValue
|
defValue = defaultValue as? String ?: defValue
|
||||||
}
|
}
|
||||||
override fun getSummary(): CharSequence {
|
|
||||||
if (customSummary != null) return customSummary!!
|
override var customSummaryProvider: SummaryProvider<MatPreference>? = SummaryProvider<MatPreference> {
|
||||||
val index = entryValues.indexOf(prefs.getStringPref(key, defValue).getOrDefault())
|
val index = entryValues.indexOf(prefs.getStringPref(key, defValue).getOrDefault())
|
||||||
return if (entries.isEmpty() || index == -1) ""
|
if (entries.isEmpty() || index == -1) ""
|
||||||
else entries[index]
|
else entries[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ open class MatPreference @JvmOverloads constructor(
|
|||||||
|
|
||||||
protected val prefs: PreferencesHelper = Injekt.get()
|
protected val prefs: PreferencesHelper = Injekt.get()
|
||||||
private var isShowing = false
|
private var isShowing = false
|
||||||
var customSummary: String? = null
|
|
||||||
|
|
||||||
@StringRes var dialogTitleRes: Int? = null
|
@StringRes var dialogTitleRes: Int? = null
|
||||||
|
|
||||||
@ -35,8 +34,30 @@ open class MatPreference @JvmOverloads constructor(
|
|||||||
isShowing = true
|
isShowing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSummary(): CharSequence {
|
protected open var customSummaryProvider: SummaryProvider<MatPreference>? = null
|
||||||
return customSummary ?: super.getSummary()
|
set(value) {
|
||||||
|
field = value
|
||||||
|
summaryProvider = customSummaryProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setSummary(summaryResId: Int) {
|
||||||
|
if (summaryResId == 0) {
|
||||||
|
summaryProvider = customSummaryProvider
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
summaryProvider = null
|
||||||
|
}
|
||||||
|
super.setSummary(summaryResId)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setSummary(summary: CharSequence?) {
|
||||||
|
if (summary == null) {
|
||||||
|
summaryProvider = customSummaryProvider
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
summaryProvider = null
|
||||||
|
}
|
||||||
|
super.setSummary(summary)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun dialog(): MaterialDialog {
|
open fun dialog(): MaterialDialog {
|
||||||
|
@ -20,13 +20,9 @@ class MultiListMatPreference @JvmOverloads constructor(
|
|||||||
ListMatPreference(activity, context, attrs) {
|
ListMatPreference(activity, context, attrs) {
|
||||||
|
|
||||||
var allSelectionRes: Int? = null
|
var allSelectionRes: Int? = null
|
||||||
var customSummaryRes: Int
|
|
||||||
get() = 0
|
|
||||||
set(value) { customSummary = context.getString(value) }
|
|
||||||
|
|
||||||
override fun getSummary(): CharSequence {
|
override var customSummaryProvider: SummaryProvider<MatPreference>? = SummaryProvider<MatPreference> {
|
||||||
if (customSummary != null) return customSummary!!
|
prefs.getStringSet(key, emptySet<String>()).getOrDefault().mapNotNull {
|
||||||
return prefs.getStringSet(key, emptySet<String>()).getOrDefault().mapNotNull {
|
|
||||||
if (entryValues.indexOf(it) == -1) null
|
if (entryValues.indexOf(it) == -1) null
|
||||||
else entryValues.indexOf(it) + if (allSelectionRes != null) 1 else 0
|
else entryValues.indexOf(it) + if (allSelectionRes != null) 1 else 0
|
||||||
}.toIntArray().joinToString(",") {
|
}.toIntArray().joinToString(",") {
|
||||||
@ -50,9 +46,9 @@ class MultiListMatPreference @JvmOverloads constructor(
|
|||||||
val pos = mutableListOf<Int>()
|
val pos = mutableListOf<Int>()
|
||||||
for (i in items.indices)
|
for (i in items.indices)
|
||||||
if (!(allSelectionRes != null && i == 0) && isItemChecked(i)) pos.add(i)
|
if (!(allSelectionRes != null && i == 0) && isItemChecked(i)) pos.add(i)
|
||||||
var value = pos.map {
|
var value = pos.mapNotNull {
|
||||||
entryValues[it - if (allSelectionRes != null) 1 else 0]
|
entryValues.getOrNull(it - if (allSelectionRes != null) 1 else 0)
|
||||||
}?.toSet() ?: emptySet()
|
}.toSet()
|
||||||
if (allSelectionRes != null && isItemChecked(0)) value = emptySet()
|
if (allSelectionRes != null && isItemChecked(0)) value = emptySet()
|
||||||
prefs.getStringSet(key, emptySet()).set(value)
|
prefs.getStringSet(key, emptySet()).set(value)
|
||||||
callChangeListener(value)
|
callChangeListener(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user