Make accent summary use string resources

Make accent summaries use string resources instead of the names of the colors in resources themselves, in order to make the names translatable.
This commit is contained in:
OxygenCobalt 2020-12-04 20:17:28 -07:00
parent a49ad5ddad
commit 276c099f84
2 changed files with 44 additions and 6 deletions

View file

@ -12,16 +12,16 @@ import androidx.core.text.toSpanned
import org.oxycblt.auxio.R
import java.util.Locale
// Functions for managing colors/accents/whatever.
// Functions for managing colors/accents.
// Pairs of the base accent and its theme
val ACCENTS = listOf(
val ACCENTS = arrayOf(
Pair(R.color.red, R.style.Theme_Red), // 0
Pair(R.color.pink, R.style.Theme_Pink), // 1
Pair(R.color.purple, R.style.Theme_Purple), // 2
Pair(R.color.deep_purple, R.style.Theme_DeepPurple), // 3
Pair(R.color.indigo, R.style.Theme_Indigo), // 4
Pair(R.color.blue, R.style.Theme_Blue), // 5
Pair(R.color.blue, R.style.Theme_Blue), // 5 - Default!
Pair(R.color.light_blue, R.style.Theme_LightBlue), // 6
Pair(R.color.cyan, R.style.Theme_Cyan), // 7
Pair(R.color.teal, R.style.Theme_Teal), // 8
@ -37,6 +37,21 @@ val ACCENTS = listOf(
Pair(R.color.blue_grey, R.style.Theme_BlueGrey) // 18
)
// The names for each colors. These are translatable, so make sure to use these instead of getting
// the color name directly.
private val ACCENT_NAMES = arrayOf(
R.string.color_label_red, R.string.color_label_pink,
R.string.color_label_purple, R.string.color_label_deep_purple,
R.string.color_label_indigo, R.string.color_label_blue,
R.string.color_label_light_blue, R.string.color_label_cyan,
R.string.color_label_teal, R.string.color_label_green,
R.string.color_label_light_green, R.string.color_label_lime,
R.string.color_label_yellow, R.string.color_label_amber,
R.string.color_label_orange, R.string.color_label_deep_orange,
R.string.color_label_brown, R.string.color_label_grey,
R.string.color_label_blue_grey
)
lateinit var accent: Pair<Int, Int>
/**
@ -102,11 +117,13 @@ fun resolveAttr(context: Context, @AttrRes attr: Int): Int {
/**
* Get the name of an accent.
* TODO: Make these use translatable string resources!!!!
*/
fun getAccentItemSummary(context: Context, newAccent: Pair<Int, Int>): String {
return context.resources.getResourceEntryName(newAccent.first)
.replace("_", " ").capitalize(Locale.getDefault())
val accentIndex = ACCENTS.indexOf(newAccent)
check(accentIndex != -1) { "Invalid accent given" }
return context.getString(ACCENT_NAMES[accentIndex])
}
/**

View file

@ -91,6 +91,27 @@
<string name="placeholder_album">Unknown Album</string>
<string name="placeholder_no_date">No Date</string>
<!-- Color Label namespace | Accent names -->
<string name="color_label_red">Red</string>
<string name="color_label_pink">Pink</string>
<string name="color_label_purple">Purple</string>
<string name="color_label_deep_purple">Deep Purple</string>
<string name="color_label_indigo">Indigo</string>
<string name="color_label_blue">Blue</string>
<string name="color_label_light_blue">Light blue</string>
<string name="color_label_cyan">Cyan</string>
<string name="color_label_teal">Teal</string>
<string name="color_label_green">Green</string>
<string name="color_label_light_green">Light Green</string>
<string name="color_label_lime">Lime</string>
<string name="color_label_yellow">Yellow</string>
<string name="color_label_amber">Amber</string>
<string name="color_label_orange">Orange</string>
<string name="color_label_deep_orange">Deep Orange</string>
<string name="color_label_brown">Brown</string>
<string name="color_label_grey">Grey</string>
<string name="color_label_blue_grey">Blue Grey</string>
<!-- Format Namespace | Value formatting/plurals -->
<string name="format_info">%1$s / %2$s</string>
<string name="format_double_info">%1$s / %2$s / %3$s</string>