I trying to refactor one of my activity class to implement mvp(using mvp mosby library) . I have a RecyclerView and in this view there is some items that some changes apply to them during the run time. for example I do some I/O operation and change one row.
I think it's better to keep my items in presenter class; what is the best practice for this? keep this in 1)presenter or 2)activity or 3)only keep view related item in adapter and all other item in presenter.
the activity now keep items directly and change item row in activity and then notify adapter. isn't better to move all this line in adapter and notify adapter in the adapter class? for example i want change icon of some row.where and which class is responsible for that? adapter? activity? now I want to implement it like this in adapter:
changeItemIcon(int position, int iconRes){
mImages.get(position).setICon(iconRes);
notifyItemChanged(position);
}
I invoke this method on activity and invoke activity method from presenter.
is it good? what is the best practice to do this?
UPDATE
also I find this question ( Best way to update data with a RecyclerView adapter ) that using adapter method for changing items. but what about modify? Need I keep reference to items in my activity?
changeItemIcon
method. That's a change to the underlying data that is being adapted. Where that code belongs depends on what's responsible for that data. Probably in the presenter, which sounds like it's your activity (consider extracting that functionality to it's own class so you can reuse it) – McbaseAdapter
. PS: I would not worry that much about random examples from the internet or whether your code is MVP or not. The library has examples which shows certain patterns to do things. Whether that is MVP or not does not matter as long as you have clean code. And that's simpler when you do it however the library inventor imagined you do. – Mc