Last active
October 13, 2016 22:11
-
-
Save FireZenk/820bcdaeca2ea769f0b23e6b07d906a0 to your computer and use it in GitHub Desktop.
Demo snippets from the "Clean Architecture: As we have applied in Mr.Milú" slides
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 Mediator { | |
public Observable<Auth> login(Login loginModel) { | |
if (loginStrategy.isAlreadyLogged()) | |
return Observable.from(authCache); | |
else | |
return repository.login(loginMapper.toRequest(loginModel)) | |
.map(entity -> authMapper.fromResponse(entity)); | |
} | |
} | |
[...] | |
public class LoginMapper implements RequestMapper<LoginEntity, Login> { | |
@Override public LoginEntity toRequest(Login model) { | |
// return an entity with username and password | |
} | |
} | |
[...] | |
public class AuthMapper implements ResponseMapper<Auth, AuthEntity> { | |
@Override public Auth fromResponse(AuthEntity entity) { | |
// return a model with auth tokens | |
} | |
} | |
[...] | |
public class AuthEntity { | |
private String auth_token; | |
private String refresh_token; | |
// Also getters and setters | |
} | |
[...] | |
public interface Repository { | |
Observable<AuthEntity> login(LoginEntity authEntity) | |
} |
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 extends MeigicPresenter<LoginView> { | |
[...] | |
private void loginIn(String username, String password) { | |
loginSubscription = loginUseCase | |
.withUsername(username) | |
.withPassword(password) | |
.subscribe(onSuccess, onFailure); | |
} | |
private void onSuccess(Auth auth) { | |
// Do something | |
} | |
private void onFailure(Throwable throwable) { | |
// Do something | |
} | |
} | |
[...] | |
public class LoginUseCase extends UseCase<Observable<Auth>> implements Command { | |
public LoginUseCase withUsername(String username) { | |
// Adds the username and returns this | |
} | |
public LoginUseCase withPassword(String password) { | |
// Adds the password and returns this | |
} | |
@Override public Subscription execute() { | |
// Call network that returns and observable Auth model | |
} | |
} | |
[...] | |
public class Auth { | |
private String authToken; | |
private String refreshToken; | |
// Also getters and setters | |
} |
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 SampleActivity | |
extends MeigicActivity<SampleActivityPresenter, SampleActivityView> | |
implements SampleActivityView { | |
@Override protected SampleActivityPresenter initPresenter() { | |
// Presenter instance | |
} | |
@Override protected void initView() { | |
// Setup the view and helper additions | |
} | |
} | |
[...] | |
public class SampleActivityPresenter extends MeigicPresenter<SampleActivityView> { | |
public SampleActivityPresenter(SampleActivityView view) { | |
super(view); | |
} | |
@Override public void setup() { | |
// Presenter init here | |
} | |
@Override public void destroy() { | |
// Presenter destroy here | |
} | |
} | |
[...] | |
public interface SampleActivityView extends MeigicView { | |
// View interface methods | |
} | |
[...] | |
public class ColorHelper extends MeigicHelper { | |
public ColorHelper(Context context, View view) { | |
super(context, view); | |
} | |
void changeColor() { | |
// Do something | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment