use of uk.ivanc.archimvp.model.GithubService in project archi by ivacf.
the class MainPresenter method loadRepositories.
public void loadRepositories(String usernameEntered) {
String username = usernameEntered.trim();
if (username.isEmpty())
return;
mainMvpView.showProgressIndicator();
if (subscription != null)
subscription.unsubscribe();
ArchiApplication application = ArchiApplication.get(mainMvpView.getContext());
GithubService githubService = application.getGithubService();
subscription = githubService.publicRepositories(username).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Subscriber<List<Repository>>() {
@Override
public void onCompleted() {
Log.i(TAG, "Repos loaded " + repositories);
if (!repositories.isEmpty()) {
mainMvpView.showRepositories(repositories);
} else {
mainMvpView.showMessage(R.string.text_empty_repos);
}
}
@Override
public void onError(Throwable error) {
Log.e(TAG, "Error loading GitHub repos ", error);
if (isHttp404(error)) {
mainMvpView.showMessage(R.string.error_username_not_found);
} else {
mainMvpView.showMessage(R.string.error_loading_repos);
}
}
@Override
public void onNext(List<Repository> repositories) {
MainPresenter.this.repositories = repositories;
}
});
}
use of uk.ivanc.archimvp.model.GithubService in project archi by ivacf.
the class RepositoryPresenter method loadOwner.
public void loadOwner(String userUrl) {
ArchiApplication application = ArchiApplication.get(repositoryMvpView.getContext());
GithubService githubService = application.getGithubService();
subscription = githubService.userFromUrl(userUrl).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Action1<User>() {
@Override
public void call(User user) {
Log.i(TAG, "Full user data loaded " + user);
repositoryMvpView.showOwner(user);
}
});
}
use of uk.ivanc.archimvp.model.GithubService in project archi by ivacf.
the class MainPresenterTest method setUp.
@Before
public void setUp() {
ArchiApplication application = (ArchiApplication) RuntimeEnvironment.application;
githubService = mock(GithubService.class);
// Mock the retrofit service so we don't call the API directly
application.setGithubService(githubService);
// Change the default subscribe schedulers so all observables
// will now run on the same thread
application.setDefaultSubscribeScheduler(Schedulers.immediate());
mainPresenter = new MainPresenter();
mainMvpView = mock(MainMvpView.class);
when(mainMvpView.getContext()).thenReturn(application);
mainPresenter.attachView(mainMvpView);
}
use of uk.ivanc.archimvp.model.GithubService in project archi by ivacf.
the class RepositoryPresenterTest method setUp.
@Before
public void setUp() {
ArchiApplication application = (ArchiApplication) RuntimeEnvironment.application;
githubService = mock(GithubService.class);
// Mock the retrofit service so we don't call the API directly
application.setGithubService(githubService);
// Change the default subscribe schedulers so all observables
// will now run on the same thread
application.setDefaultSubscribeScheduler(Schedulers.immediate());
repositoryPresenter = new RepositoryPresenter();
repositoryMvpView = mock(RepositoryMvpView.class);
when(repositoryMvpView.getContext()).thenReturn(application);
repositoryPresenter.attachView(repositoryMvpView);
}
Aggregations