Created
August 10, 2019 09:40
-
-
Save mbobiosio/1147c73b728d8fc494cf1e5b7adc0143 to your computer and use it in GitHub Desktop.
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 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