Last active
April 30, 2018 21:10
-
-
Save patrickhammond/02876f747a438897ec36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component(modules = { | |
AndroidModule.class, | |
BusModule.class, | |
NetworkModule.class, | |
AppModule.class | |
}) | |
public interface ApplicationComponent { | |
... | |
Bus bus(); | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component(dependencies = ApplicationComponent.class, modules = LoginModule.class) | |
@ActivityScope | |
public interface LoginComponent { | |
LoginViewContract loginViewContract(); | |
void inject(LoginActivity activity); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class LoginModule { | |
private final LoginActivity activity; | |
public LoginModule(LoginActivity activity) { | |
this.activity = activity; | |
} | |
@Provides | |
@ActivityScope | |
public LoginViewContract provideLoginViewContract() { | |
return activity; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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