I have here an Enum:
enum class ColorEnum(
@StringRes val textResource: Int,
): Abbrev {
blu(R.string.blue) {
override fun abbrev() = "bl"
},
red(R.string.red) {
override fun abbrev() = "rd"
},
grn(R.string.green) {
override fun abbrev() = "gr"
},
wht(R.string.white) {
override fun abbrev() = "wh"
},
blk(R.string.black) {
override fun abbrev() = "bl"
},
ylw(R.string.yellow) {
override fun abbrev() = "yl"
},
brw(R.string.brown) {
override fun abbrev() = "br"
}
}
whereas the resources R.string.blue
have correct written colors like "Blue", etc. in each language.
Imagine I have a string val colorString = "Blue"
how do I map this to a colorEnum object?
val colorEnumItem = ColorEnum.valueOf("Blue")
did not work. But
val colorEnumItem = ColorEnum.valueOf("blu") did.
So how do I get the correct enum, from the long string resoruce like "Blue" ?
EDIT:I changed the example, so that the long string "Blue" and enum blu does not match.