Skip to content

Commit

Permalink
reduce code duplication, remove useless string
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 committed Nov 3, 2023
1 parent e1da2ff commit 7ae0d07
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }]
Expand All @@ -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 }]
Expand All @@ -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()

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@
<string name="prefs_keyboard_height_scale">Keyboard height scale</string>
<!-- Title of the settings for setting bottom padding height -->
<string name="prefs_bottom_padding_scale">Bottom padding scale</string>
<!-- Description of prefs_bottom_padding_scale -->
<string name="prefs_bottom_padding_scale_summary">Set size of the empty space below the keyboard</string>
<!-- Description for English (UK) keyboard subtype [CHAR LIMIT=25]
(UK) should be an abbreviation of United Kingdom to fit in the CHAR LIMIT. -->
<string name="subtype_en_GB">English (UK)</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/xml/prefs_screen_appearance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
<org.dslul.openboard.inputmethod.latin.settings.SeekBarDialogPreference
android:key="pref_bottom_padding_scale"
android:title="@string/prefs_bottom_padding_scale"
android:summary="@string/prefs_bottom_padding_scale_summary"
latin:minValue="0"
latin:maxValue="500" /> <!-- percentage -->

Expand Down

0 comments on commit 7ae0d07

Please sign in to comment.