Last active
November 29, 2017 20:01
-
-
Save julianfalcionelli/1989b1ef5bdd837b85e97beffaa5f93e to your computer and use it in GitHub Desktop.
Using Retrofit with Cache
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 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