use of in.bugzy.data.model.Milestone in project bugzy by cpunq.
the class Repository method getMilestones.
public LiveData<Resource<List<Milestone>>> getMilestones(boolean mustFetch) {
if (mFetchMilestonesLiveData != null) {
if (mFetchMilestonesLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mMilestonesPublicLiveData;
}
mMilestonesPublicLiveData.removeSource(mFetchMilestonesLiveData);
mFetchMilestonesLiveData = null;
}
mFetchMilestonesLiveData = new NetworkBoundResource<List<Milestone>, Response<ListMilestonesData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListMilestonesData> item) {
mSsRespository.updateMilestoneSearchSuggestion(item.getData().getMilestones());
db.beginTransaction();
try {
mMiscDao.insertMilestones(item.getData().getMilestones());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Milestone> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Milestone>> loadFromDb() {
return mMiscDao.loadMilestones();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListMilestonesData>>> createCall() {
return mApiService.getMilestones(new Request("listFixFors"));
}
}.asLiveData();
mMilestonesPublicLiveData.addSource(mFetchMilestonesLiveData, value -> {
mMilestonesPublicLiveData.setValue(value);
});
return mMilestonesPublicLiveData;
}
Aggregations