Skip to content

Instantly share code, notes, and snippets.

@mbobiosio
Created August 10, 2019 09:40
Show Gist options
  • Save mbobiosio/1147c73b728d8fc494cf1e5b7adc0143 to your computer and use it in GitHub Desktop.
Save mbobiosio/1147c73b728d8fc494cf1e5b7adc0143 to your computer and use it in GitHub Desktop.
private ArrayList<WeekModel> mDataList = new ArrayList<>();
//Implementation in use
private void fetchData() {
mDisposable.add(mWeekService.getLessons()
.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);
}
})
);
}
//From medium article.
private ExampleNetwork mExampleNetwork;
private void getDetails(String id) {
mExampleNetwork.getCachedDetails(id) // From Cache
.doFinally(() -> {
mExampleNetwork
.getDetails(id) // From Network
.subscribe(details -> onDetailsReceived(details), this::onError);
})
.subscribe(details -> onDetailsReceived(details), this::onError);
}
private void onDetailsReceived(Details details) {
if (mDetails == null || !mDetails.equals(details)) { // Implement equals with your criteria
mDetails = details;
updateUI();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment