Search in sources :

Example 1 with GithubService

use of uk.ivanc.archi.model.GithubService in project archi by ivacf.

the class MainActivity method loadGithubRepos.

public void loadGithubRepos(String username) {
    progressBar.setVisibility(View.VISIBLE);
    reposRecycleView.setVisibility(View.GONE);
    infoTextView.setVisibility(View.GONE);
    ArchiApplication application = ArchiApplication.get(this);
    GithubService githubService = application.getGithubService();
    subscription = githubService.publicRepositories(username).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Subscriber<List<Repository>>() {

        @Override
        public void onCompleted() {
            progressBar.setVisibility(View.GONE);
            if (reposRecycleView.getAdapter().getItemCount() > 0) {
                reposRecycleView.requestFocus();
                hideSoftKeyboard();
                reposRecycleView.setVisibility(View.VISIBLE);
            } else {
                infoTextView.setText(R.string.text_empty_repos);
                infoTextView.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onError(Throwable error) {
            Log.e(TAG, "Error loading GitHub repos ", error);
            progressBar.setVisibility(View.GONE);
            if (error instanceof HttpException && ((HttpException) error).code() == 404) {
                infoTextView.setText(R.string.error_username_not_found);
            } else {
                infoTextView.setText(R.string.error_loading_repos);
            }
            infoTextView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onNext(List<Repository> repositories) {
            Log.i(TAG, "Repos loaded " + repositories);
            RepositoryAdapter adapter = (RepositoryAdapter) reposRecycleView.getAdapter();
            adapter.setRepositories(repositories);
            adapter.notifyDataSetChanged();
        }
    });
}
Also used : GithubService(uk.ivanc.archi.model.GithubService) Repository(uk.ivanc.archi.model.Repository) Subscriber(rx.Subscriber) HttpException(retrofit2.adapter.rxjava.HttpException) List(java.util.List)

Example 2 with GithubService

use of uk.ivanc.archi.model.GithubService in project archi by ivacf.

the class RepositoryActivity method loadFullUser.

private void loadFullUser(String url) {
    ArchiApplication application = ArchiApplication.get(this);
    GithubService githubService = application.getGithubService();
    subscription = githubService.userFromUrl(url).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Action1<User>() {

        @Override
        public void call(User user) {
            Log.i(TAG, "Full user data loaded " + user);
            bindOwnerData(user);
            ownerLayout.setVisibility(View.VISIBLE);
        }
    });
}
Also used : GithubService(uk.ivanc.archi.model.GithubService) Action1(rx.functions.Action1) User(uk.ivanc.archi.model.User)

Aggregations

GithubService (uk.ivanc.archi.model.GithubService)2 List (java.util.List)1 HttpException (retrofit2.adapter.rxjava.HttpException)1 Subscriber (rx.Subscriber)1 Action1 (rx.functions.Action1)1 Repository (uk.ivanc.archi.model.Repository)1 User (uk.ivanc.archi.model.User)1