Hello guys, I've a question, from my webservice it...
# android
j
Hello guys, I've a question, from my webservice it comes like a flag true or false, so on my adapter of my recyclerView I have to print one color or other depends of the flag, do I have to add this logic in the Viewholder? Also is there any other way to test this logic besides of UI? I do the mapper to my domain object, and it's tested.
o
Things like this typically can go different ways. But my personal opinion is the UI/model object that is mapped from your data/API/json object should have a field that the view holder looks at to determine what color it should use. You can do this in whatever way, like still holding a Boolean. But it's probably more reusable for the UI model to hold the actual color, and then the view holder that takes that color and sets it on whatever view. In terms of testing , you could mock out your service layer and test your mapper /repository to ensure that the color field in the UI model matches what you expect when the json flag is true or false .
Your view ( in this case the recycle view adapter/ view holder) should be as dumb as possible. It should be as simple as "give me the color you want and I'll set it on the view". So you keep this business logic contained in either your view model or repository where you can unit test it easily as well.
Oops I think I read your question wrong, my b, short answer, yes, the logic can either go in the onBindViewHolder method or preferably in your view holder class. In terms of testing, it's quite difficult to test views (adapter, view holder etc) so as long as you do something similar to above with keeping as much of the business logic in your repository or view model etc then you should be good to go