use of in.bugzy.data.model.CaseStatus in project bugzy by cpunq.
the class Repository method getStatuses.
public LiveData<Resource<List<CaseStatus>>> getStatuses(boolean mustFetch) {
if (mFetchStatusesLiveData != null) {
if (mFetchStatusesLiveData.getValue().status == Status.LOADING && !mustFetch) {
// If the content is in loading state and the request doesn't require us to fetch again
return mStatusesPublicLiveData;
}
mStatusesPublicLiveData.removeSource(mFetchStatusesLiveData);
mFetchStatusesLiveData = null;
}
mFetchStatusesLiveData = new NetworkBoundResource<List<CaseStatus>, Response<ListStatusesData>>(mAppExecutors) {
@Override
protected void saveCallResult(@NonNull Response<ListStatusesData> item) {
db.beginTransaction();
try {
mMiscDao.insertStatuses(item.getData().getStatuses());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
@Override
protected boolean shouldFetch(@Nullable List<CaseStatus> data) {
if (data == null || data.size() == 0) {
return true;
}
if (mustFetch) {
return true;
}
return false;
}
@NonNull
@Override
protected LiveData<List<CaseStatus>> loadFromDb() {
return mMiscDao.loadStatuses();
}
@NonNull
@Override
protected LiveData<ApiResponse<Response<ListStatusesData>>> createCall() {
return mApiService.getStatuses(new Request("listStatuses"));
}
}.asLiveData();
mStatusesPublicLiveData.addSource(mFetchStatusesLiveData, value -> {
mStatusesPublicLiveData.setValue(value);
});
return mStatusesPublicLiveData;
}
use of in.bugzy.data.model.CaseStatus in project bugzy by cpunq.
the class CaseEditActivity method subscribeToViewModel.
public void subscribeToViewModel() {
mCaseEditViewModel.getMilestones().observe(this, value -> {
if (value != null && value.data != null) {
showMilestones(value.data);
}
});
mCaseEditViewModel.getAreas().observe(this, value -> {
if (value != null && value.data != null) {
showAreas(value.data);
}
});
mCaseEditViewModel.getProjects().observe(this, value -> {
if (value.data != null) {
showProjects(value.data);
}
});
mCaseEditViewModel.getPersons().observe(this, value -> {
if (value.data != null) {
showPeople(value.data);
}
});
mCaseEditViewModel.getPriorities().observe(this, value -> {
if (value.data != null) {
showPriorities(value.data);
}
});
mCaseEditViewModel.getCategories().observe(this, value -> {
if (value.data != null) {
showCategories(value.data);
}
});
mCaseEditViewModel.getRequiredMergeIns().observe(this, value -> {
if (value != null) {
showRequiredMergeIns(value);
}
});
mCaseEditViewModel.getStatuses().observe(this, value -> {
if (value.data != null) {
showStatuses(value.data);
} else {
showStatuses(new ArrayList<CaseStatus>());
}
});
mCaseEditViewModel.getTags().observe(this, value -> {
showTags(value.data);
});
mCaseEditViewModel.getToken().observe(this, token -> {
mToken = token;
mAdapter.setToken(token);
mAttachmentsAdapter.setToken(token);
});
mCaseEditViewModel.getCaseLiveData().observe(this, value -> {
if (value == null) {
return;
}
if (value.data != null) {
showCaseDetails(value.data);
}
if (value.status == Status.LOADING) {
showLoading();
return;
}
if (value.status == Status.ERROR) {
showCaseFetchError(value.message);
return;
}
if (value.status == Status.SUCCESS) {
hideLoading();
}
});
mCaseEditViewModel.getEditCaseStatus().observe(this, status -> {
if (status.status == Status.LOADING) {
showLoading();
return;
}
if (status.status == Status.ERROR) {
showEditCaseError(status.message);
return;
}
if (status.status == Status.SUCCESS) {
Intent i = new Intent(this, CaseDetailsActivity.class);
Bundle args = new Bundle();
args.putString("bug_id", String.valueOf(status.data.getData().getCase().getIxBug()));
args.putSerializable("bug", status.data.getData().getCase());
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtras(args);
startActivity(i);
finish();
}
});
mCaseEditViewModel.getDefaultPropSelectionLiveData().observe(this, map -> {
Log.d(TAG, "Got update: ");
for (CaseEditViewModel.PropType key : map.keySet()) {
switch(key) {
case PROJECT:
mProjectSpinner.setSelection(map.get(PROJECT));
break;
case AREA:
Log.d(TAG, "Got area update: " + map.get(AREA));
mAreaSpinner.setSelection(map.get(AREA));
break;
case MILESTONE:
mMileStoneSpinner.setSelection(map.get(MILESTONE));
break;
case CATEGORY:
mCategorySpinner.setSelection(map.get(CATEGORY));
break;
case STATUS:
mStatusesSpinner.setSelection(map.get(STATUS));
break;
case ASSIGNEDTO:
mAssignedToSpinner.setSelection(map.get(ASSIGNEDTO));
break;
case PRIORITY:
mPrioritySpinner.setSelection(map.get(PRIORITY));
break;
}
}
});
mCaseEditViewModel.getUpdateRequiredMergeInSelection().observe(this, position -> {
mRequiredMergeInSpinner.setSelection(position);
});
mCaseEditViewModel.getOpenPeopleSelector().observe(this, v -> {
mAssignedToSpinner.performClick();
});
mCaseEditViewModel.getPrimaryButtonText().observe(this, v -> {
mSaveButton.setText(v);
});
mCaseEditViewModel.getScrollAttachmentsToLast().observe(this, v -> {
if (mAttachments.size() > 0) {
mAttachmentsRecyclerView.smoothScrollToPosition(mAttachments.size() - 1);
}
});
mCaseEditViewModel.getAttachmentsLiveData().observe(this, attachments -> {
mAttachments = attachments;
mAttachmentsAdapter.setList(attachments);
mAttachmentsAdapter.notifyDataSetChanged();
});
}
Aggregations