Android MVP architecture standard for loading UI with Model class having android resource -


i following mvp architecture in application. homeactivity contains sliding panel list icon having selector upon selecting sliding panel item icon state changed , not using list selector.

i keeping model class navitemdata populating navigation drawer , using class slidingpanelitemselector extends statelistdrawable generates appropriate selector sliding panel icon.

in mvp architecture have presenter class communicates model , generates input views. in case if using presenter getting data sliding panel calling class presenter using android context that's approach, or we having alternative solution strictly following mvp architecture?

currently using viewbinderutils class , injected directly activity class , gets list of data sliding panel. 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;     } } 

the presenter should isolated context stuff, because part should know context view(v) part. didn't understand goal classes, in generic way should follow logic

if using presenter getting data sliding panel calling class presenter using android context

create interface responsible manage communication between view (v) presenter (p).

communication.java

public interface communication {     void showloading();     void hideloading();     void setslidingdata(string [] titles); } 

your view should implement interface comunication, , has reference presenter. , if need use context interactor (i), should have class manages (in case requestholder).

view.java

public view implements communication{     private presenter mpresenter;         @override         protected void oncreate(bundle savedinstancestate) {            // view implements comunication interface            mpresenter = new presenter(this);         }         (...)        private void getdata(){          mpresenter.getdata(new requestholder(getapplicationcontext()));        }         @override        public void setslidingdata(string [] titles){           list<slidingpaneldata> items = new arraylist<>();           items.add(new slidingpaneldata(new slidingpanelitemselector(getapplicationcontext()).gethomeselector(),titles[0],true));        }     } 

in presenter has reference interface

presenter.java

private communication mview;  public presenter(communication view) {     mview = view; }  /** event receive data model **/ public void onevent(getdatamessage event){    mview.setslidingdata(event.getdata()); }   public void getdata(final requestholder holder){    new getdatainteractor(holder); } 

requestholder.java

// can put data important interactor public requestholder(final context context, int accountid) {     super(context);  } //getters , setters 

with can access context inside interactor, without mix concepts


in sum,

  • view 1 provides context
  • view has reference presenter
  • presenter "talks" view between interface

in specific case, why don't create list needs context in view part , fills list items = new arraylist<>(); in presenter part? keep isolated


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -