The adapter is a clean view. Match all interactions, like clicking on a button in a RecyclerView ViewHolder, back to Activity / Fragment, and then send it to the Activity / Fragment presentation.
RecyclerView is a bit more complicated because ViewHolders can be recycled while scrolling, etc. Returning to the “parent” Activity / Fragment and the corresponding Presenter, there are much simpler and fewer errors associated with updating the ViewHolder (i.e., using animations using DiffUtils). Take a ViewHolder in the same way as a data object, but do not add a Presenter for each ViewHolder to coordinate the ViewHolder. Indeed, just make sure that the ViewHolder receives a data object that contains all the information that the ViewHolder should display, but does not make this data object “controlled” by the ViewHolders Presenter. Otherwise, you get a mess because one ViewHolder receives an update from its Presenter, perhaps the ViewHolder was reworked in the average time, the screen orientation may have changed, or the “parent” Activity / Fragment Presenter updated the entire adapter dataset and etc. Do yourself a favor and use only one Presenter, which “coordinates / controls” the data that the RecyclerView should display using the “parent” Activity / Fragment Presenter.
source share