Skip to content

Instantly share code, notes, and snippets.

@amin3536
Last active August 8, 2018 18:51
Show Gist options
  • Save amin3536/a5b396245673683f98fbe3a6b3dd8d57 to your computer and use it in GitHub Desktop.
Save amin3536/a5b396245673683f98fbe3a6b3dd8d57 to your computer and use it in GitHub Desktop.
private Flowable<List<User>> getUser(int id){
return db.getUserById(id).
/// if there is no user in the database get data from
.flatMp(userList->
if(userList.size=0)
api.getUserById(userId)
.subscribeOn(Schedulers.io())
//check your request
.filter(statusPojo::getStatus)
// save data to room
.subscribe(new DisposableObserver<User>() {
@Override
public void onNext(User user) {
// save data to room
}
@Override
public void onError(Throwable e) {
Timber.e(e);
}
@Override
public void onComplete() {
}
});
return Flowable.just(data)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment