I am following MVP architecture in my application. My HomeActivity contains a Sliding Panel with list icon having selector that is upon selecting the Sliding Panel item the icon state is changed and i am not using any list selector.
I am keeping a model class NavItemData for populating the navigation drawer and using a class SlidingPanelItemSelector that extends StateListDrawable generates the appropriate selector for the sliding panel icon.
In MVP architecture we have a presenter class that communicates with the model and generates the input for views. In my case if am using the presenter for getting the data for Sliding Panel i am calling a class from presenter that using android context is that's a good approach, or we are having any alternative solution that strictly following MVP architecture?
Currently i am using a ViewBinderUtils class and injected it directly to the activity class and gets the list of data for Sliding Panel. Is it following Mvp Architcture?
SlidingPanelItemSelector.class
public class SlidingPanelItemSelector extends StateListDrawable {
private Context mContext;
public SlidingPanelItemSelector(Context mContext){
this.mContext = mContext;
}
public StateListDrawable getHomeSelector(){
StateListDrawable stateListDrawable = new StateListDrawable();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
stateListDrawable.addState(new int[]{android.R.attr.state_pressed},
mContext.getDrawable(R.drawable.ic_nav_home_active));
stateListDrawable.addState(new int[]{},mContext.getDrawable(R.drawable.ic_nav_home));
}else{
stateListDrawable.addState(new int[]{android.R.attr.state_pressed},
mContext.getResources().getDrawable(R.drawable.ic_nav_home_active));
stateListDrawable.addState(new int[]{},mContext.getResources().getDrawable(R.drawable.ic_nav_home));
}
return stateListDrawable;
}
}
ViewBinderUtils.class
public class ViewDataBinderUtils {
Context mContext;
@Inject
public ViewDataBinderUtils(@ActivityContext Context mContext) {
this.mContext = mContext;
}
public List<SlidingPanelData> getListData(String [] titles){
List<SlidingPanelData> items = new ArrayList<>();
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getHomeSelector(),titles[0],true));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getConfigurationSelector(),titles[1],false ));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getConfigurationSelector(),titles[2],false));
items.add(new SlidingPanelData(true));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getQuoteSelector(),titles[3],false));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getEquipmentInventorySelector(),titles[4],false));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getCustomerSelector(),titles[5],false));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getQuoterSelector(),titles[6],false));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getSalesProgramsSelector(),titles[7],false));
items.add(new SlidingPanelData( new SlidingPanelItemSelector(mContext).getCreditAppsSelector(),titles[8],false));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getRetailOffersSelector(),titles[9],false));
items.add(new SlidingPanelData(true));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getPayOffersSelector(),titles[10],true));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getAlertsSelector(),titles[11],true));
items.add(new SlidingPanelData(true));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getTermofUseSelector(),titles[12],false));
items.add(new SlidingPanelData(new SlidingPanelItemSelector(mContext).getLegalInfoSelector(),titles[11],false));
return items;
}
}