use of com.bluestacks.bugzy.data.model.SearchResultsResource in project bugzy by cpunq.
the class CasesRepository method searchCases.
public LiveData<SearchResultsResource<List<Case>>> searchCases(final String query) {
this.recordResearch(query);
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() {
String[] cols = new String[] { "sTitle", "ixPriority", "sStatus", "sProject", "sFixFor", "sArea", "sPersonAssignedTo", "sPersonOpenedBy" };
return mApiService.searchCases(new SearchCasesRequest(cols, query));
}
}.asLiveData(), v -> {
return new SearchResultsResource<>(query, v);
});
}
Aggregations