should viewmodel calculate this and emit a enum, o...
# android-architecture
u
should viewmodel calculate this and emit a enum, or should it just provide the "raw" values from which view calculates it?
r
Your first instinct is correct, keep the logic in ViewModel and provide final values to the view. Keep your view as dumb as possible.
u
Okay but what is your heuristic, should you treat null fields which should make the view dissapear, the same?
Copy code
if (extraOffer.promoText == null) {
    promoTextView.visibility = View.GONE
} else {
    promoTextView.visibility = View.VISIBLE
    promoTextView.text = extraOffer.promoText
}
I'd argue this is logic as well
s
There are not set/definite rules 😀 But I try to have the ViewModel emit data that is modeled to the actual UI as close as possible. If I see any if-statement in my UI (Activity, etc), it's a possible code-smell 😀 Still, translating a Boolean to VISIBLE or GONE in your Activity is fine, small stuff like that. But any slightly more complex logic should go in your ViewModel. Makes your code more testable by having more testable code 😀.
u
yea
just checking your heuristic