I am trying to implement MVP in my android project. But I am getting difficulty when i implement MVP with viewPagerAdapter
. To implement MVP, we used to create fragment/view and presenter instance in Activity
class.Fragment/view and presenter both will communicate with each other using contract. In this way, we decoupled view with presenter and cover all business logic with Unit test. But in case when we have tablayout
inside activity
. We have initiated fragments inside fragmentPagerAdapter
. I am not sure, how to provide tab-fragment/view reference to its corresponding presenter.If I initialize presenter inside fragmentPagerAdapter
that would bleach SRP(Single responsibility principal). If we create presenter instance inside Fragment
that would generate coupled code and then we don't need contact to establish communication between fragment and presenter. Please provide architectural solution, so that i can achieve same MVP with view pager along with adhering all clean code principal.
For reference, please find below my adapter code, where i am initializing fragments for tab:
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return getConfigurationsTabFragment();
case 1:
return UpdateTabFragment.newInstance();
case 2:
return ServiceTabFragment.newInstance();
default:
return null;
}
}