I am retrieving my response from my API with rxjava with funcs as follows:
@Override
public Single<MyInfoResponse> getMyInfoApiCall() {
return Rx2AndroidNetworking.get(ApiEndPoint.ENDPOINT_MY_INFO)
.addHeaders(mApiHeader.getProtectedApiHeader())
.build()
.getObjectSingle(MyInfoResponse.class);
}
Now ,I am retrieving this data and using it in my UI code( with usual compositedisposables) as follows:
@Override
public void onViewPrepared() {
getCompositeDisposable().add(getDataManager()
.getMyInfoApiCall()
.subscribeOn(getSchedulerProvider().io())
.observeOn(getSchedulerProvider().ui())
.subscribe(myInfoResponse -> {
getDataManager().updateMyManagerInfo(myInfoResponse);
if (myInfoResponse != null && myInfoResponse.getData() != null) {
getMvpView().updateMyRepo(myInfoResponse.getData());
}
}, throwable -> {
if (!isViewAttached()) {
return;
}
getMvpView().hideLoading();
// handle the error here
if (throwable instanceof ANError) {
ANError anError = (ANError) throwable;
handleApiError(anError);
}
}));
}
Now everytime I have internet connectivity and it tries to retrieve data it works fine, but as soon as I lose internet connectivity, I am trying to cache this data so it still displays on the UI until the network connectivity is back and ready to update data real time. How do I go about this in the easiest and the most ideal way possible?