mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 23:12:47 +00:00
reduce code duplication, remove useless string
This commit is contained in:
parent
e1da2ffdc1
commit
7ae0d0783d
3 changed files with 8 additions and 15 deletions
|
@ -96,10 +96,7 @@ class AppearanceSettingsFragment : SubScreenFragment() {
|
|||
colorsPref.apply {
|
||||
entryValues = if (style == KeyboardTheme.STYLE_HOLO) KeyboardTheme.COLORS
|
||||
else KeyboardTheme.COLORS.filterNot { it == KeyboardTheme.THEME_HOLO_WHITE }.toTypedArray()
|
||||
entries = entryValues.map {
|
||||
val resId = resources.getIdentifier("theme_name_$it", "string", requireContext().packageName)
|
||||
if (resId == 0) it else getString(resId)
|
||||
}.toTypedArray()
|
||||
entries = entryValues.getNamesFromResourcesIfAvailable("theme_name_")
|
||||
if (value !in entryValues)
|
||||
value = entryValues.first().toString()
|
||||
summary = entries[entryValues.indexOfFirst { it == value }]
|
||||
|
@ -113,10 +110,7 @@ class AppearanceSettingsFragment : SubScreenFragment() {
|
|||
colorsNightPref?.apply {
|
||||
entryValues = if (style == KeyboardTheme.STYLE_HOLO) KeyboardTheme.COLORS_DARK
|
||||
else KeyboardTheme.COLORS_DARK.filterNot { it == KeyboardTheme.THEME_HOLO_WHITE }.toTypedArray()
|
||||
entries = entryValues.map {
|
||||
val resId = resources.getIdentifier("theme_name_$it", "string", requireContext().packageName)
|
||||
if (resId == 0) it else getString(resId)
|
||||
}.toTypedArray()
|
||||
entries = entryValues.getNamesFromResourcesIfAvailable("theme_name_")
|
||||
if (value !in entryValues)
|
||||
value = entryValues.first().toString()
|
||||
summary = entries[entryValues.indexOfFirst { it == value }]
|
||||
|
@ -132,10 +126,7 @@ class AppearanceSettingsFragment : SubScreenFragment() {
|
|||
private fun setupTheme() {
|
||||
stylePref.apply {
|
||||
entryValues = KeyboardTheme.STYLES
|
||||
entries = entryValues.map {
|
||||
val resId = resources.getIdentifier("style_name_$it", "string", requireContext().packageName)
|
||||
if (resId == 0) it else getString(resId)
|
||||
}.toTypedArray()
|
||||
entries = entryValues.getNamesFromResourcesIfAvailable("style_name_")
|
||||
if (value !in entryValues)
|
||||
value = entryValues.first().toString()
|
||||
|
||||
|
@ -179,6 +170,11 @@ class AppearanceSettingsFragment : SubScreenFragment() {
|
|||
})
|
||||
}
|
||||
|
||||
private fun Array<CharSequence>.getNamesFromResourcesIfAvailable(prefix: String) =
|
||||
map { val resId = resources.getIdentifier("$prefix$it", "string", requireContext().packageName)
|
||||
if (resId == 0) it else getString(resId)
|
||||
}.toTypedArray()
|
||||
|
||||
companion object {
|
||||
private const val PERCENTAGE_FLOAT = 100.0f
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue