Skip to content

Instantly share code, notes, and snippets.

View drawers's full-sized avatar
🟩
In greenish twilight at the bottom of the Rhine

David Rawson drawers

🟩
In greenish twilight at the bottom of the Rhine
View GitHub Profile
@ProducerModule(includes = { PlayerRepositoryModule.class, GamesRepositoryModule.class, PlayerNameModule.class, StatisticsModule.class } )
final class MainRequestModule {
@Produces
static ListenableFuture<Player> player(PlayerRepository playerRepository, String username) {
return playerRepository.retrieve(username);
}
@Produces
static ListenableFuture<Games> games(GamesRepository gamesRepository, Player player) {
@ProductionComponent(modules = { MainRequestModule.class, ExecutorModule.class })
interface MainRequestComponent {
ListenableFuture<Statistics> statistics();
}
void showStatistics(String playerName) {
MainRequestComponent component = DaggerMainRequestComponent
.builder()
.playerNameModule(new PlayerNameModule(playerName))
.build();
ListenableFuture<Statistics> futureStatistics = component.statistics();
//TODO: show games using the view inside a callback
}
@drawers
drawers / NaiveActivity.java
Last active November 1, 2017 09:26
A naive implementation of a RegistrationActivity
public void onRegisterClick(View v) {
progressBar.setVisibility(View.VISIBLE);
progressBar.animate().alpha(1).setDuration(500).start();
final String username = usernameEditText.getText().toString();
final String password = passwordEditText.getText().toString();
RegistrationDTO dto = new RegistrationDTO(username, password);
registrationService.callback(new Callback() {
@Override
public void onResponse(Call<RegistrationDTO> call, Response<RegistrationResult> response) {
progressBar.setVisibility(View.GONE);
@drawers
drawers / RegistrationContract.View.java
Created November 1, 2017 09:27
The View contract for MVP
public interface RegistrationContract {
interface View {
void showBusy(boolean isBusy);
void showAlertDialog(String message);
void showNextActivity();
@drawers
drawers / RefactoredRegistrationActivity.java
Created November 1, 2017 09:31
RegistrationActivity refactored to use MVP
public class RegistrationActivity implements RegistrationContract.View {
public void onCreate(Bundle savedInstanceState) {
//similar to before...
}
@Override
public void showBusy(boolean isBusy) {
if (isBusy) {
progressBar.setVisibility(View.VISIBLE);
@drawers
drawers / RegistrationContract.Presenter.java
Last active November 1, 2017 09:37
The contract for a presenter
public interface RegistrationContract {
interface Presenter {
void takeView(View v);
void dropView();
void register(String username, String password);
@drawers
drawers / RegistrationPresenter.java
Created November 1, 2017 09:41
Registration presenter implementation
public class RegistrationPresenter implements RegistrationContract.Presenter {
private final RegistrationService registrationService;
private final Storage storage;
@Nullable
private RegistrationContract.View view;
public RegistrationPresenter(RegistrationService registrationService, Storage storage) {
@drawers
drawers / RegistrationContract.Interactor.java
Created November 1, 2017 09:51
A contract for an Interactor
public interface RegistrationContract {
interface Interactor {
void onRegisterButtonClick(String username, String password);
}
}
@drawers
drawers / RegistrationInteractor.java
Created November 1, 2017 09:54
An implementation of an interactor
public class RegistrationInteractor implements RegistrationContract.Interactor {
private final RegistrationContract.Presenter presenter;
RegistrationInteractor(RegistrationContract.presenter presenter); {
this.presenter = presenter;
}
@Override
public void onRegisterButtonClick(String username, String password) {