Last active
January 19, 2018 10:31
-
-
Save communikein/b933037a87a6c8f128d7c20cbbf79612 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
@Singleton | |
public class PoisRepository { | |
private final PoisDao mDao; | |
private final WebService mWebService; | |
private final AppExecutors mExecutors; | |
private MutableLiveData<List<Poi>> mPois; | |
@Inject | |
public PoisRepository(PoisDao poisDao, WebService webService, AppExecutors executors) { | |
this.mDao = poisDao; | |
this.mWebService = webService; | |
MutableLiveData<List<Poi>> mWebServerPois = new MutableLiveData<>(); | |
mWebService.getPois().enqueue((call, response) -> { | |
mWebServerPois.setValue(response.body()); | |
}); | |
mWebServerPois.observeForever(newOnlineData -> mExecutors.diskIO().execute(() -> { | |
if (newOnlineData != null) { | |
mPoisDao.deletePois(); | |
mPoisDao.bulkInsertPois((ArrayList<Poi>) newOnlineData); | |
} | |
} | |
} | |
public LiveData<List<Poi>> getObservableAllPois() { | |
return mPoisDao.getObservablePois(); | |
} | |
public LiveData<Poi> getObservablePoi(String id) { | |
return mPoisDao.getObservablePoi(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment