Last active
July 5, 2017 15:27
-
-
Save letroll/e155b2d32841318436e17de3311e2ac6 to your computer and use it in GitHub Desktop.
[pagination avec rxjava] pagination avec rxjava #android #rxjava #rx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void downloadDataWhenDiscussionUnresolved(String numPage) { | |
Observable<Discussions> operationObservable = getDiscussionsObservable(numPage); | |
operationObservable.subscribe(new Subscriber<Discussions>() { | |
@Override | |
public void onCompleted() { | |
Log.d(TAG, "onCompleted() called"); | |
} | |
@Override | |
public void onError(Throwable e) { | |
} | |
@Override | |
public void onNext(Discussions discussions) { | |
Log.d(TAG, "onNext() called with: discussions = [" + discussions + "]"); | |
downloadDataWhenDiscussionUnresolved(discussions.getNextPage()); | |
} | |
}); | |
} | |
@NonNull | |
private Observable<Discussions> getDiscussionsObservable(final String numPage) { | |
return Observable.create(new Observable.OnSubscribe<Discussions>() { | |
@Override | |
public void call(Subscriber<? super Discussions> subscriber) { | |
subscribe(discussionManager.getDiscussionsUnResolved(numPage), discussions -> { | |
refreshData(discussions, null != mDiscussions); | |
if (null != discussions && null != discussions.getNextPage() && mDiscussions.getDiscussions().size() < 10) { | |
subscriber.onNext(discussions); | |
} else { | |
subscriber.onCompleted(); | |
} | |
}, new ObserverError() { | |
@Override | |
public void onError(Throwable error) { | |
subscriber.onError(error); | |
} | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment