I agree that view-models should never hold or receive references to aView or Activity, but ruling…
Aidan Mcwilliams
231

anything from the android framework in a view-model is overkill in my opinion

I thought the same way until I tried to apply that as a hard rule. It just makes your design better. View.VISIBLE can be set in the View. Resources are easy to mock but consider instead of doing:

myLiveDataString.setValue(mContext.getResources().getString(R.string.label1))

Just save the ID (.R is perfectly fine in ViewModels)

myLiveDataStringId.setValue(R.string.label1)

and let the view get the resource. If you need to do string manipulation use the framework’s.

(We’re actually mocking Context in Blueprints)

As for testing, a lot of Android classes don’t need Roboelectric (sic)

I’d say none, but it can make you cut some corners.

I know some people have doubts about the data-binding library, so it’s good to see an alternative approach is available.

It’s *not* an alternative. Both are observables but they’re used for different things. A combination of both is very powerful, in my opinion.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.