feat(YouTube - Settings): Sort preference screens below other types of preference
This commit is contained in:
parent
14ea9674c4
commit
9561db50a8
|
@ -32,21 +32,29 @@ abstract class AbstractPreferenceScreen(
|
||||||
preferences: MutableList<BasePreference> = mutableListOf(),
|
preferences: MutableList<BasePreference> = mutableListOf(),
|
||||||
val categories: MutableList<Category> = mutableListOf()
|
val categories: MutableList<Category> = mutableListOf()
|
||||||
) : BasePreferenceCollection(key, title, preferences) {
|
) : BasePreferenceCollection(key, title, preferences) {
|
||||||
override fun transform(): PreferenceScreen {
|
override fun transform() = PreferenceScreen(
|
||||||
return PreferenceScreen(
|
key,
|
||||||
key,
|
StringResource(
|
||||||
StringResource("${key}_title", title),
|
"${key}_title", title
|
||||||
preferences.sortedBy { it.title.value.removePunctuation().lowercase() } +
|
),
|
||||||
categories.sortedBy { it.title.removePunctuation().lowercase() }.map { it.transform() },
|
preferences.sortedWith(
|
||||||
summary?.let { summary ->
|
compareBy(
|
||||||
StringResource("${key}_summary", summary)
|
{ it is PreferenceScreen },
|
||||||
}
|
{ it.title.value.removePunctuation().lowercase() }
|
||||||
)
|
)
|
||||||
}
|
) + categories.sortedBy {
|
||||||
|
it.title.removePunctuation().lowercase()
|
||||||
|
}.map {
|
||||||
|
it.transform()
|
||||||
|
},
|
||||||
|
summary?.let { summary ->
|
||||||
|
StringResource("${key}_summary", summary)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
private fun ensureScreenInserted() {
|
private fun ensureScreenInserted() {
|
||||||
// Add to screens if not yet done
|
// Add to screens if not yet done
|
||||||
if(!this@AbstractPreferenceScreen.root.contains(this))
|
if (!this@AbstractPreferenceScreen.root.contains(this))
|
||||||
this@AbstractPreferenceScreen.root.add(this)
|
this@AbstractPreferenceScreen.root.add(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +67,7 @@ abstract class AbstractPreferenceScreen(
|
||||||
key: String,
|
key: String,
|
||||||
title: String,
|
title: String,
|
||||||
preferences: MutableList<BasePreference> = mutableListOf()
|
preferences: MutableList<BasePreference> = mutableListOf()
|
||||||
): BasePreferenceCollection(key, title, preferences) {
|
) : BasePreferenceCollection(key, title, preferences) {
|
||||||
override fun transform(): PreferenceCategory {
|
override fun transform(): PreferenceCategory {
|
||||||
return PreferenceCategory(
|
return PreferenceCategory(
|
||||||
key,
|
key,
|
||||||
|
@ -72,7 +80,7 @@ abstract class AbstractPreferenceScreen(
|
||||||
ensureScreenInserted()
|
ensureScreenInserted()
|
||||||
|
|
||||||
// Add to categories if not yet done
|
// Add to categories if not yet done
|
||||||
if(!this@Screen.categories.contains(this))
|
if (!this@Screen.categories.contains(this))
|
||||||
this@Screen.categories.add(this)
|
this@Screen.categories.add(this)
|
||||||
|
|
||||||
this.preferences.addAll(preferences)
|
this.preferences.addAll(preferences)
|
||||||
|
|
Loading…
Reference in a new issue