Skip to content

Instantly share code, notes, and snippets.

View andrzejchm's full-sized avatar

Andrzej Chmielewski andrzejchm

View GitHub Profile
public abstract class BaseActivity<M extends Serializable, V extends DroidMVPView, P extends DroidMVPPresenter<V, M>>
extends DroidMVPActivity<M, V, P> {
@Inject protected P presenter;
@NonNull @Override protected P createPresenter() {
//this field will be populated by field injeciton from dagger
// your presenter should not accept the presentationModel as its constructor's paramteter.
// Instead, it will be provided to your presenter in #attachView method.
return presenter;
}
public class GoodPresentationModel implements Serializable {
public static final Birthday TODAY = new Birthday();
private List<User> users = Collections.emptyList();
public void setUsers(List<User> users) {
this.users = users;
}
public class GoodPresenter extends SimpleDroidMVPPresenter<GoodView,GoodPresentationModel> {
public void onShowUsersButtonClicked() {
getMvpView().showProgress();
repository.getUsers(new Callback() {
public void onSuccess(List<Users> users) {
usersListFetched(users);
}
public void onFailure(Exception e) {
showProductsList(List<Product> products);
showProgress();
showUpdateCompleted();
public class GoodActivity extends DroidMVPActivity<GoodPresentationModel, GoodView, GoodPresenter> {
...
@OnClick(R.id.button) public void onButtonClicked() {
presenter.onButtonClicked();
}
...
}
public class BadActivity extends DroidMVPActivity<GoodPresentationModel, GoodView, GoodPresenter> {
...
@OnClick(R.id.button) public void onButtonClicked() {
showProgress();
presenter.onButtonClicked();
}
...
}
public Repository(int id, String name, String fullName, Owner owner,
 boolean private, String htmlUrl, String description, boolean fork,
 String url, String forksUrl, String keysUrl, String collaboratorsUrl,
 String teamsUrl, String hooksUrl, String issueEventsUrl, String eventsUrl,
 String assigneesUrl, String branchesUrl, String tagsUrl, String blobsUrl,
 String gitTagsUrl, String gitRefsUrl, String treesUrl, String statusesUrl,
 String languagesUrl, String stargazersUrl, String contributorsUrl,
 String subscribersUrl, String subscriptionUrl, String commitsUrl, String gitCommitsUrl,
 String commentsUrl, String issueCommentUrl, String contentsUrl, String compareUrl,
 String mergesUrl, String archiveUrl, String downloadsUrl, String issuesUrl,
@Test
public void testPlayground() throws Exception {
RESTMockServer.whenGET(RequestMatchers.pathEndsWith("users/andrzejchm")).thenReturnFile(
"users/andrzejchm.json");
//launches activity with default intent
rule.launchActivity(null);
Thread.sleep(10000);
}
@Test
public void testGoodAnswer() throws Exception {
RESTMockServer.whenGET(RequestMatchers.pathEndsWith("users/andrzejchm")).thenReturnFile(
"users/andrzejchm.json");
//launches activity with default intent
rule.launchActivity(null);
pageObject.typeUsername("andrzejchm");
pageObject.pressOk();
pageObject.verifyWelcomeMessageForUser("Welcome Andrzej Chmielewski!");
}
public class GetUserDetailsUsecase {
private final DB db;
@Inject public GetUserDetailsUsecase(DB db) {
this.db = db;
}
public Observable<UserDetails> getUserDetails() {
return Observable.create(new Observable.OnSubscribe<UserDetails>() {