I have a class with the following enum and variables:
enum class ExerciseSetState {
NOT_STARTED, PASSED, FAILED
}
@Entity
class ExerciseEntity(
...
@Ignore var setState: ExerciseSetState = ExerciseSetState.NOT_STARTED
....
)
And in my databinding layout, I want to set the color based on this state variable:
<TextView
android:id="@+id/tv_exer_rep_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="@{String.valueOf(exercise.setReps)}"
android:backgroundColor="@{exercise.setState == ExerciseSetState.PASSED? (Color.GREEN : exercise.setState == ExerciseSetState.FAILED ? Color.RED: Color.TRANSPARENT )}"/>
Unfortunately I have this pretty horrible ternary expression in order to compute the color based off the value.
What is the idiomatic way of implementing this?