Madalin Valceleanu
06/12/2020, 6:38 AMJoost Klitsie
06/12/2020, 7:40 AMapp:visible="@{viewState.isLoaded || viewState.addLoading || viewState.addError || viewState.NoMoreElements}">
If you have MVVM, why not put this logic also in the ViewModel? Then you can expose 1 ui state containing the list as well as the visibility of the recyclerview.
This xml logic (where you have 4 options) is difficult to test (I mean do you really want to write 5 espresso tests to test this?)
I think a viewState object containing the actual state of your view (instead of the state of the app) does make more sense in general, and mapping the app states (isLoaded) to view states (isVisible = true) within the view should require a presenter layer, as now you are basically mapping twice. It is hard to understand: Where do I put the logic? Because now you have a ViewModel that maps a state to the UI, the UI that maps states to events and XML that maps states to actually displaying something.
With UI that maps states to event, I mean for example within the CharacterDetailFragment:
when (viewState) { is CharacterDetailViewState.Loading -> progressDialog.show(R.string.character_detail_dialog_loading_text)
Joost Klitsie
06/12/2020, 7:40 AMMadalin Valceleanu
06/12/2020, 7:49 AMxml level
, view
or ViewModel.
Because in my case the logic start to begin more complex about the visibility of the specific component it’s good handle that more on the View level
, because ViewModel
in that case contains view logic. Imagine in the future you have different condition for each visual component. Making you ViewModel
containing a lot of logic about presentation componentsJoost Klitsie
06/12/2020, 7:58 AMview.Visibility = if (state.isVisible) VISIBLE else GONE
)
For both MVP and MVVM, shared business logic can then go into the Model, for example by the use of UseCases.