use of in.bugzy.data.remote.model.Request in project bugzy by cpunq.
the class Repository method getProjects.
public LiveData<Resource<List<Project>>> getProjects(boolean mustFetch) {
if (mFetchProjectsLiveData != null) {
if (mFetchProjectsLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mProjectsPublicLiveData;
}
mProjectsPublicLiveData.removeSource(mFetchProjectsLiveData);
mFetchProjectsLiveData = null;
}
mFetchProjectsLiveData = new NetworkBoundResource<List<Project>, Response<ListProjectsData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListProjectsData> item) {
db.beginTransaction();
try {
mMiscDao.insertProjects(item.getData().getProjects());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Project> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Project>> loadFromDb() {
return mMiscDao.loadProjects();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListProjectsData>>> createCall() {
return mApiService.getProjects(new Request("listProjects"));
}
}.asLiveData();
mProjectsPublicLiveData.addSource(mFetchProjectsLiveData, value -> {
mProjectsPublicLiveData.setValue(value);
});
return mProjectsPublicLiveData;
}
use of in.bugzy.data.remote.model.Request in project bugzy by cpunq.
the class Repository method getPriorities.
public LiveData<Resource<List<Priority>>> getPriorities(boolean mustFetch) {
if (mFetchPrioritiesLiveData != null) {
if (mFetchPrioritiesLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mPrioritiesPublicLiveData;
}
mPrioritiesPublicLiveData.removeSource(mFetchPrioritiesLiveData);
mFetchPrioritiesLiveData = null;
}
mFetchPrioritiesLiveData = new NetworkBoundResource<List<Priority>, Response<ListPrioritiesData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListPrioritiesData> item) {
db.beginTransaction();
try {
mMiscDao.insertPriorities(item.getData().getPriorities());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Priority> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Priority>> loadFromDb() {
return mMiscDao.loadPriorities();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListPrioritiesData>>> createCall() {
return mApiService.getPriorities(new Request("listPriorities"));
}
}.asLiveData();
mPrioritiesPublicLiveData.addSource(mFetchPrioritiesLiveData, value -> {
mPrioritiesPublicLiveData.setValue(value);
});
return mPrioritiesPublicLiveData;
}
use of in.bugzy.data.remote.model.Request in project bugzy by cpunq.
the class Repository method getAreas.
public MediatorLiveData<Resource<List<Area>>> getAreas(boolean mustFetch) {
if (mFetchAreasLiveData != null) {
if (mFetchAreasLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mAreasPublicLiveData;
}
mAreasPublicLiveData.removeSource(mFetchAreasLiveData);
mFetchAreasLiveData = null;
}
mFetchAreasLiveData = new NetworkBoundResource<List<Area>, Response<ListAreasData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListAreasData> item) {
mSsRespository.updateAreaSearchSuggestion(item.getData().getAreas());
db.beginTransaction();
try {
mMiscDao.insert(item.getData().getAreas());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Area> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Area>> loadFromDb() {
return mMiscDao.loadAreas();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListAreasData>>> createCall() {
return mApiService.getAreas(new Request("listAreas"));
}
}.asLiveData();
mAreasPublicLiveData.addSource(mFetchAreasLiveData, value -> {
mAreasPublicLiveData.setValue(value);
});
return mAreasPublicLiveData;
}
use of in.bugzy.data.remote.model.Request in project bugzy by cpunq.
the class Repository method getCategories.
public LiveData<Resource<List<Category>>> getCategories(boolean mustFetch) {
if (mFetchCategoriesLiveData != null) {
if (mFetchCategoriesLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mCategoriesPublicLiveData;
}
mCategoriesPublicLiveData.removeSource(mFetchCategoriesLiveData);
mFetchCategoriesLiveData = null;
}
mFetchCategoriesLiveData = new NetworkBoundResource<List<Category>, Response<ListCategoriesData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListCategoriesData> item) {
db.beginTransaction();
try {
mMiscDao.insertCategories(item.getData().getCategories());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Category> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Category>> loadFromDb() {
return mMiscDao.loadCategories();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListCategoriesData>>> createCall() {
return mApiService.getCategories(new Request("listCategories"));
}
}.asLiveData();
mCategoriesPublicLiveData.addSource(mFetchCategoriesLiveData, value -> {
mCategoriesPublicLiveData.setValue(value);
});
return mCategoriesPublicLiveData;
}
use of in.bugzy.data.remote.model.Request in project bugzy by cpunq.
the class Repository method getStatuses.
public LiveData<Resource<List<CaseStatus>>> getStatuses(boolean mustFetch) {
if (mFetchStatusesLiveData != null) {
if (mFetchStatusesLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mStatusesPublicLiveData;
}
mStatusesPublicLiveData.removeSource(mFetchStatusesLiveData);
mFetchStatusesLiveData = null;
}
mFetchStatusesLiveData = new NetworkBoundResource<List<CaseStatus>, Response<ListStatusesData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListStatusesData> item) {
db.beginTransaction();
try {
mMiscDao.insertStatuses(item.getData().getStatuses());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<CaseStatus> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<CaseStatus>> loadFromDb() {
return mMiscDao.loadStatuses();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListStatusesData>>> createCall() {
return mApiService.getStatuses(new Request("listStatuses"));
}
}.asLiveData();
mStatusesPublicLiveData.addSource(mFetchStatusesLiveData, value -> {
mStatusesPublicLiveData.setValue(value);
});
return mStatusesPublicLiveData;
}
Aggregations