use of com.morihacky.android.rxjava.retrofit.Contributor in project RxJava-Android-Samples by kaushikgopal.
the class PseudoCacheMergeFragment method _getCachedData.
private Observable<Pair<Contributor, Long>> _getCachedData() {
List<Pair<Contributor, Long>> list = new ArrayList<>();
Pair<Contributor, Long> dataWithAgePair;
for (String username : _contributionMap.keySet()) {
Contributor c = new Contributor();
c.login = username;
c.contributions = _contributionMap.get(username);
dataWithAgePair = new Pair<>(c, System.currentTimeMillis());
list.add(dataWithAgePair);
}
return Observable.fromIterable(list);
}
use of com.morihacky.android.rxjava.retrofit.Contributor in project RxJava-Android-Samples by kaushikgopal.
the class RetrofitFragment method onListContributorsClicked.
@OnClick(R.id.btn_demo_retrofit_contributors)
public void onListContributorsClicked() {
_adapter.clear();
//
_disposables.add(_githubService.contributors(_username.getText().toString(), _repo.getText().toString()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableObserver<List<Contributor>>() {
@Override
public void onComplete() {
Timber.d("Retrofit call 1 completed");
}
@Override
public void onError(Throwable e) {
Timber.e(e, "woops we got an error while getting the list of contributors");
}
@Override
public void onNext(List<Contributor> contributors) {
for (Contributor c : contributors) {
_adapter.add(format("%s has made %d contributions to %s", c.login, c.contributions, _repo.getText().toString()));
Timber.d("%s has made %d contributions to %s", c.login, c.contributions, _repo.getText().toString());
}
}
}));
}
use of com.morihacky.android.rxjava.retrofit.Contributor in project RxJava-Android-Samples by kaushikgopal.
the class PseudoCacheFragment method getCachedDiskData.
private Observable<Contributor> getCachedDiskData() {
List<Contributor> list = new ArrayList<>();
Map<String, Long> map = dummyDiskData();
for (String username : map.keySet()) {
Contributor c = new Contributor();
c.login = username;
c.contributions = map.get(username);
list.add(c);
}
return //
Observable.fromIterable(list).doOnSubscribe((data) -> //
new Handler(Looper.getMainLooper()).post(//
() -> adapterSubscriptionInfo.add("(disk) cache subscribed"))).doOnComplete(() -> //
new Handler(Looper.getMainLooper()).post(() -> adapterSubscriptionInfo.add("(disk) cache completed")));
}
use of com.morihacky.android.rxjava.retrofit.Contributor in project RxJava-Android-Samples by kaushikgopal.
the class PseudoCacheFragment method getFreshNetworkData.
private Observable<Contributor> getFreshNetworkData() {
String githubToken = getResources().getString(R.string.github_oauth_token);
GithubApi githubService = GithubService.createGithubService(githubToken);
return githubService.contributors("square", "retrofit").flatMap(Observable::fromIterable).doOnSubscribe((data) -> //
new Handler(Looper.getMainLooper()).post(//
() -> adapterSubscriptionInfo.add("(network) subscribed"))).doOnComplete(() -> //
new Handler(Looper.getMainLooper()).post(() -> adapterSubscriptionInfo.add("(network) completed")));
}
use of com.morihacky.android.rxjava.retrofit.Contributor 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());
}
}));
}
Aggregations