use of in.bugzy.data.remote.model.Response in project bugzy by cpunq.
the class CasesRepository method searchCases.
public LiveData<SearchResultsResource<ListCasesData>> searchCases(final String query) {
this.recordResearch(query);
NetworkBoundTask<Response<ListCasesData>> task = new NetworkBoundTask<Response<ListCasesData>>(mAppExecutors, mGson) {
@Override
public void saveCallResult(@NonNull Response<ListCasesData> result) {
}
@NonNull
@Override
protected Call<Response<ListCasesData>> createCall() {
return mApiService.searchCasesCall(new SearchCasesRequest(mColsForCaseList, query));
}
};
mAppExecutors.networkIO().execute(task);
return Transformations.map(task.asLiveData(), v -> {
Resource<ListCasesData> resource = new Resource(v.status, v.data == null ? null : v.data.getData(), v.message);
return new SearchResultsResource<>(query, resource);
});
// return Transformations.map(new NetworkBoundResource<List<Case>, Response<ListCasesData>>(mAppExecutors) {
// List<Case> mCases = null;
//
// @Override
// protected void saveCallResult(@NonNull Response<ListCasesData> item) {
// mCases = item.getData().getCases();
// }
//
// @Override
// protected boolean shouldFetch(@Nullable List<Case> data) {
// // Fetch always
// return true;
// }
//
// @NonNull
// @Override
// protected LiveData<List<Case>> loadFromDb() {
// return new LiveData<List<Case>>() {
// @Override
// protected void onActive() {
// super.onActive();
// setValue(mCases);
// }
// };
// }
//
// @NonNull
// @Override
// protected LiveData<ApiResponse<Response<ListCasesData>>> createCall() {
// return mApiService.searchCases(new SearchCasesRequest(mColsForCaseList, query));
// }
// }.asLiveData(), v -> {
// return new SearchResultsResource<>(query, v);
// });
}
use of in.bugzy.data.remote.model.Response in project bugzy by cpunq.
the class Repository method getPeople.
public LiveData<Resource<List<Person>>> getPeople(boolean mustFetch) {
if (mFetchPeopleLiveData != null) {
if (mFetchPeopleLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mPeoplePublicLiveData;
}
mPeoplePublicLiveData.removeSource(mFetchPeopleLiveData);
mFetchPeopleLiveData = null;
}
mFetchPeopleLiveData = new NetworkBoundResource<List<Person>, Response<ListPeopleData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListPeopleData> item) {
mSsRespository.updatePeopleSearchSuggestion(item.getData().getPersons());
try {
db.beginTransaction();
db.miscDao().insertPersons(item.getData().getPersons());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Person> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Person>> loadFromDb() {
return mMiscDao.loadPersons();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListPeopleData>>> createCall() {
return mApiService.listPeople(new ListPeopleRequest());
}
}.asLiveData();
mPeoplePublicLiveData.addSource(mFetchPeopleLiveData, value -> {
mPeoplePublicLiveData.setValue(value);
});
return mPeoplePublicLiveData;
}
use of in.bugzy.data.remote.model.Response 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.Response 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.Response 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;
}
Aggregations