SHARE
TWEET

Untitled

a guest Jul 17th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Component:
  2. @PerFragment
  3. @Component(modules = FragModule.class)
  4. public interface FragComponent {
  5.     void inject(Frag1 frag);
  6.     void inject(Frag2 frag);
  7. }
  8.  
  9. //Module:
  10. @Module
  11. public class FragModule {
  12.  
  13.  
  14.     @PerFragment
  15.     @Provides
  16.     // can use @Binds i think, 'cause no parameters...
  17.     Model1 getModel1() {
  18.         return new Model1();
  19.     }
  20.  
  21.     @PerFragment
  22.     @Provides
  23.     // can use @Binds i think, 'cause no parameters...
  24.     Model2 getModel2() {
  25.         return new Model2();
  26.     }
  27. }
  28.  
  29. //Fragment:
  30. public class Frag1 extends Fragment implements Contract1.View {
  31.  
  32. Frag1Presenter mPresenter;
  33.  
  34. @Inject Model1 mModel1;
  35.  
  36. @Override
  37.     protected void resolveDaggerDependencies() {
  38.         super.resolveDaggerDependencies();
  39.         DaggerFragComponent
  40.                 .builder()
  41.                 .fragModule(new FragModule())  //ViewManager injection
  42.                 .build()
  43.                 .inject(this);
  44.         mPresenter = new Frag1Presenter(mModel1);
  45.         mPresenter.attachView(this);
  46.     }
  47. }
  48.  
  49. //Presenter:
  50. public class Frag1Presenter {
  51.     Model1 mModel1;
  52.     Contract1.View mView;
  53.  
  54.     public Frag1Presenter(Model1 model1) {
  55.         mModel1 = model1;
  56.     }
  57.  
  58.    public void attachView(Contract1.View view) {
  59.        mView = view;
  60.    }
  61. }
RAW Paste Data
Top