use of in.bugzy.data.remote.model.SearchCasesRequest 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);
// });
}
Aggregations