Skip to content

Instantly share code, notes, and snippets.

@patrickhammond
Last active April 30, 2018 21:10
Show Gist options
  • Save patrickhammond/02876f747a438897ec36 to your computer and use it in GitHub Desktop.
Save patrickhammond/02876f747a438897ec36 to your computer and use it in GitHub Desktop.
@Singleton
@Component(modules = {
AndroidModule.class,
BusModule.class,
NetworkModule.class,
AppModule.class
})
public interface ApplicationComponent {
...
Bus bus();
...
}
public LoginActivity extends BaseActivity implements LoginViewContract {
private LoginComponent component;
@Inject LoginPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
component = DaggerLoginComponent.builder()
.applicationComponent(getApplicationComponent())
.loginModule(new LoginModule(this))
.build();
component.inject(this);
super.onCreate(savedInstanceState);
}
// getApplicationComponent is a convenience method in BaseActivity, here for clarity
protected ApplicationComponent getApplicationComponent() {
return ((MyApplication) getApplication()).getComponent();
}
}
@Component(dependencies = ApplicationComponent.class, modules = LoginModule.class)
@ActivityScope
public interface LoginComponent {
LoginViewContract loginViewContract();
void inject(LoginActivity activity);
}
@Module
public class LoginModule {
private final LoginActivity activity;
public LoginModule(LoginActivity activity) {
this.activity = activity;
}
@Provides
@ActivityScope
public LoginViewContract provideLoginViewContract() {
return activity;
}
}
public class LoginPresenter implements Presenter {
public interface LoginViewContract {
...
}
private final LoginViewContract viewContract;
private final Bus bus;
...
// Bus is provided through the application component
@Inject
public LoginPresenter(LoginViewContract viewContract, Bus bus) {
this.viewContract = viewContract;
this.bus = bus;
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment