use of com.bluestacks.bugzy.data.remote.model.ListCasesData 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);
});
}
use of com.bluestacks.bugzy.data.remote.model.ListCasesData in project bugzy by cpunq.
the class CasesRepository method cases.
public LiveData<Resource<FilterCasesResult>> cases(final String filter, boolean sortChanged) {
return sorted(new NetworkBoundResource<FilterCasesResult, Response<ListCasesData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListCasesData> item) {
db.beginTransaction();
try {
mCaseDao.upsertCases(item.getData().getCases());
mCaseDao.upsertFilterCaseIds(new FilterCasesResult(filter, item.getData().getCaseIds(), null));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable FilterCasesResult data) {
if (sortChanged) {
// network thing this time.
return false;
}
return true;
}
@NonNull
@Override
protected LiveData<FilterCasesResult> loadFromDb() {
return Transformations.switchMap(mCaseDao.loadCasesForFilter(filter), filterCasesData -> {
if (filterCasesData == null) {
return AbsentLiveData.create();
}
return Transformations.map(mCaseDao.loadCasesById(filterCasesData.getCaseIds()), kases -> {
filterCasesData.setCases(kases);
return filterCasesData;
});
});
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListCasesData>>> createCall() {
String[] cols = new String[] { "sTitle", "ixPriority", "sStatus", "sProject", "sFixFor", "sPersonAssignedTo", "sPersonOpenedBy", "sArea", "sCategory" };
ListCasesRequest request = new ListCasesRequest(cols, filter);
return mApiService.listCases(request);
}
}.asLiveData());
}
Aggregations