Skip to content

Instantly share code, notes, and snippets.

@photizzo
Created August 10, 2019 12:18
Show Gist options
  • Save photizzo/897d11c0a94b8c0e3e93601fb6066b07 to your computer and use it in GitHub Desktop.
Save photizzo/897d11c0a94b8c0e3e93601fb6066b07 to your computer and use it in GitHub Desktop.
mWeekService.getCachedLessons() // From Cache
.doFinally(() -> {
mWeekService.getLessons() // From Network
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(new Function<WeekResponse, List<WeekModel>>() {
@Override
public List<WeekModel> apply(
@io.reactivex.annotations.NonNull final WeekResponse response)
throws Exception {
return response.getResult();
}
})
.subscribe(new Consumer<List<WeekModel>>() {
@Override
public void accept(
@io.reactivex.annotations.NonNull final List<WeekModel> lessonList)
throws Exception {
mLessons.addAll(lessonList);
mWeekAdapter.set(mDataList);
}
})
);
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(new Function<WeekResponse, List<WeekModel>>() {
@Override
public List<WeekModel> apply(
@io.reactivex.annotations.NonNull final WeekResponse response)
throws Exception {
return response.getResult();
}
})
.subscribe(new Consumer<List<WeekModel>>() {
@Override
public void accept(
@io.reactivex.annotations.NonNull final List<WeekModel> lessonList)
throws Exception {
mLessons.addAll(lessonList);
mWeekAdapter.set(mDataList);
}
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment