https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
u

ursus

05/02/2020, 2:11 AM
should viewmodel calculate this and emit a enum, or should it just provide the "raw" values from which view calculates it?
r

rax

05/02/2020, 2:40 AM
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

ursus

05/02/2020, 2:53 AM
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

streetsofboston

05/02/2020, 3:19 AM
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

ursus

05/02/2020, 3:43 AM
yea
just checking your heuristic
6 Views