Search in sources :

Example 1 with User

use of com.morihacky.android.rxjava.retrofit.User in project RxJava-Android-Samples by kaushikgopal.

the class RetrofitFragment method onListContributorsWithFullUserInfoClicked.

@OnClick(R.id.btn_demo_retrofit_contributors_with_user_info)
public void onListContributorsWithFullUserInfoClicked() {
    _adapter.clear();
    _disposables.add(_githubService.contributors(_username.getText().toString(), _repo.getText().toString()).flatMap(Observable::fromIterable).flatMap(contributor -> {
        Observable<User> _userObservable = _githubService.user(contributor.login).filter(user -> !isEmpty(user.name) && !isEmpty(user.email));
        return Observable.zip(_userObservable, Observable.just(contributor), Pair::new);
    }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableObserver<Pair<User, Contributor>>() {

        @Override
        public void onComplete() {
            Timber.d("Retrofit call 2 completed ");
        }

        @Override
        public void onError(Throwable e) {
            Timber.e(e, "error while getting the list of contributors along with full " + "names");
        }

        @Override
        public void onNext(Pair<User, Contributor> pair) {
            User user = pair.first;
            Contributor contributor = pair.second;
            _adapter.add(format("%s(%s) has made %d contributions to %s", user.name, user.email, contributor.contributions, _repo.getText().toString()));
            _adapter.notifyDataSetChanged();
            Timber.d("%s(%s) has made %d contributions to %s", user.name, user.email, contributor.contributions, _repo.getText().toString());
        }
    }));
}
Also used : User(com.morihacky.android.rxjava.retrofit.User) DisposableObserver(io.reactivex.observers.DisposableObserver) Contributor(com.morihacky.android.rxjava.retrofit.Contributor) Pair(android.util.Pair) OnClick(butterknife.OnClick)

Aggregations

Pair (android.util.Pair)1 OnClick (butterknife.OnClick)1 Contributor (com.morihacky.android.rxjava.retrofit.Contributor)1 User (com.morihacky.android.rxjava.retrofit.User)1 DisposableObserver (io.reactivex.observers.DisposableObserver)1