use of com.bluestacks.bugzy.data.remote.ApiResponse in project bugzy by cpunq.
the class Repository method getMilestones.
public LiveData<Resource<List<Milestone>>> getMilestones(boolean mustFetch) {
if (mFetchMilestonesLiveData != null) {
if (mFetchMilestonesLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mMilestonesPublicLiveData;
}
mMilestonesPublicLiveData.removeSource(mFetchMilestonesLiveData);
mFetchMilestonesLiveData = null;
}
mFetchMilestonesLiveData = new NetworkBoundResource<List<Milestone>, Response<ListMilestonesData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListMilestonesData> item) {
mSsRespository.updateMilestoneSearchSuggestion(item.getData().getMilestones());
db.beginTransaction();
try {
mMiscDao.insertMilestones(item.getData().getMilestones());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<Milestone> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<Milestone>> loadFromDb() {
return mMiscDao.loadMilestones();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListMilestonesData>>> createCall() {
return mApiService.getMilestones(new Request("listFixFors"));
}
}.asLiveData();
mMilestonesPublicLiveData.addSource(mFetchMilestonesLiveData, value -> {
mMilestonesPublicLiveData.setValue(value);
});
return mMilestonesPublicLiveData;
}
use of com.bluestacks.bugzy.data.remote.ApiResponse 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 com.bluestacks.bugzy.data.remote.ApiResponse 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 com.bluestacks.bugzy.data.remote.ApiResponse 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 com.bluestacks.bugzy.data.remote.ApiResponse 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