u

    ursus

    2 years ago
    should viewmodel calculate this and emit a enum, or should it just provide the "raw" values from which view calculates it?
    r

    rax

    2 years ago
    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

    2 years ago
    Okay but what is your heuristic, should you treat null fields which should make the view dissapear, the same?
    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

    2 years ago
    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

    2 years ago
    yea
    just checking your heuristic