Search in sources :

Example 1 with GithubService

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;
        }
    });
}
Also used : GithubService(uk.ivanc.archimvp.model.GithubService) Repository(uk.ivanc.archimvp.model.Repository) ArchiApplication(uk.ivanc.archimvp.ArchiApplication) Subscriber(rx.Subscriber) List(java.util.List)

Example 2 with GithubService

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);
        }
    });
}
Also used : GithubService(uk.ivanc.archimvp.model.GithubService) Action1(rx.functions.Action1) User(uk.ivanc.archimvp.model.User) ArchiApplication(uk.ivanc.archimvp.ArchiApplication)

Example 3 with GithubService

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);
}
Also used : GithubService(uk.ivanc.archimvp.model.GithubService) MainMvpView(uk.ivanc.archimvp.view.MainMvpView) MainPresenter(uk.ivanc.archimvp.presenter.MainPresenter) Before(org.junit.Before)

Example 4 with GithubService

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);
}
Also used : GithubService(uk.ivanc.archimvp.model.GithubService) RepositoryPresenter(uk.ivanc.archimvp.presenter.RepositoryPresenter) RepositoryMvpView(uk.ivanc.archimvp.view.RepositoryMvpView) Before(org.junit.Before)

Aggregations

GithubService (uk.ivanc.archimvp.model.GithubService)4 Before (org.junit.Before)2 ArchiApplication (uk.ivanc.archimvp.ArchiApplication)2 List (java.util.List)1 Subscriber (rx.Subscriber)1 Action1 (rx.functions.Action1)1 Repository (uk.ivanc.archimvp.model.Repository)1 User (uk.ivanc.archimvp.model.User)1 MainPresenter (uk.ivanc.archimvp.presenter.MainPresenter)1 RepositoryPresenter (uk.ivanc.archimvp.presenter.RepositoryPresenter)1 MainMvpView (uk.ivanc.archimvp.view.MainMvpView)1 RepositoryMvpView (uk.ivanc.archimvp.view.RepositoryMvpView)1