use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.
the class BaseReportFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
if (getActivity() instanceof BaseReportActivity) {
this.baseReportActivity = (BaseReportActivity) this.getActivity();
} else {
throw new NotImplementedException("The list activity for fragment must implement BaseReportActivity");
}
if (getActivity() instanceof IUpdateSubHeadingTitle) {
this.subHeadingHandler = (IUpdateSubHeadingTitle) this.getActivity();
} else {
throw new NotImplementedException("Activity for fragment does not support updateSubHeadingTitle; " + "implement IUpdateSubHeadingTitle");
}
if (!(getActivity() instanceof NotificationContext)) {
throw new NotImplementedException("Activity for fragment does not support showErrorNotification; " + "implement NotificationContext");
}
// Inflate Root
rootBinding = DataBindingUtil.inflate(inflater, getRootLayoutResId(), container, false);
View rootView = rootBinding.getRoot();
final ViewStub vsChildFragmentFrame = rootView.findViewById(R.id.vsChildFragmentFrame);
vsChildFragmentFrame.setOnInflateListener(new ViewStub.OnInflateListener() {
@Override
public void onInflate(ViewStub stub, View inflated) {
contentViewStubBinding = DataBindingUtil.bind(inflated);
contentViewStubBinding.addOnRebindCallback(new OnRebindCallback() {
@Override
public void onBound(ViewDataBinding binding) {
super.onBound(binding);
if (!skipAfterLayoutBinding)
onAfterLayoutBinding(contentViewStubBinding);
skipAfterLayoutBinding = true;
getSubHeadingHandler().updateSubHeadingTitle(getSubHeadingTitle());
}
});
onLayoutBinding(contentViewStubBinding);
}
});
vsChildFragmentFrame.setLayoutResource(getReportLayout());
jobTask = new DefaultAsyncTask(getContext()) {
@Override
public void onPreExecute() {
getBaseActivity().showPreloader();
}
@Override
public void doInBackground(final TaskResultHolder resultHolder) {
prepareFragmentData(savedInstanceState);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
getBaseActivity().hidePreloader();
if (taskResult.getResultStatus().isFailed())
return;
vsChildFragmentFrame.inflate();
}
}.executeOnThreadPool();
return rootView;
}
use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.
the class PrescriptionEditActivity method saveData.
@Override
public void saveData() {
if (saveTask != null) {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
return;
}
final Prescription prescription = (Prescription) getActiveFragment().getPrimaryData();
PrescriptionEditFragment fragment = (PrescriptionEditFragment) getActiveFragment();
try {
FragmentValidator.validate(getContext(), fragment.getContentBinding());
} catch (ValidationException e) {
NotificationHelper.showNotification(this, ERROR, e.getMessage());
return;
}
saveTask = new SavingAsyncTask(getRootView(), prescription) {
@Override
protected void onPreExecute() {
showPreloader();
}
@Override
public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
DatabaseHelper.getPrescriptionDao().saveAndSnapshot(prescription);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
finish();
} else {
// reload data
onResume();
}
saveTask = null;
}
}.executeOnThreadPool();
}
use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.
the class TreatmentEditActivity method saveData.
@Override
public void saveData() {
if (saveTask != null) {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
return;
}
final Treatment treatment = (Treatment) getActiveFragment().getPrimaryData();
TreatmentEditFragment fragment = (TreatmentEditFragment) getActiveFragment();
try {
FragmentValidator.validate(getContext(), fragment.getContentBinding());
} catch (ValidationException e) {
NotificationHelper.showNotification(this, ERROR, e.getMessage());
return;
}
saveTask = new SavingAsyncTask(getRootView(), treatment) {
@Override
protected void onPreExecute() {
showPreloader();
}
@Override
public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
DatabaseHelper.getTreatmentDao().saveAndSnapshot(treatment);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
finish();
} else {
// reload data
onResume();
}
saveTask = null;
}
}.executeOnThreadPool();
}
use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.
the class TreatmentNewActivity method saveData.
@Override
public void saveData() {
if (saveTask != null) {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
return;
}
final Treatment treatment = getStoredRootEntity();
TreatmentEditFragment fragment = (TreatmentEditFragment) getActiveFragment();
fragment.setLiveValidationDisabled(false);
try {
FragmentValidator.validate(getContext(), fragment.getContentBinding());
} catch (ValidationException e) {
NotificationHelper.showNotification(this, ERROR, e.getMessage());
return;
}
saveTask = new SavingAsyncTask(getRootView(), treatment) {
@Override
protected void onPreExecute() {
showPreloader();
}
@Override
public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
DatabaseHelper.getTreatmentDao().saveAndSnapshot(treatment);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
finish();
}
saveTask = null;
}
}.executeOnThreadPool();
}
use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.
the class CaseNewActivity method saveDataInner.
private void saveDataInner(final Case caseToSave) {
if (saveTask != null) {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
// don't save multiple times
return;
}
saveTask = new SavingAsyncTask(getRootView(), caseToSave) {
@Override
protected void onPreExecute() {
showPreloader();
}
@Override
protected void doInBackground(TaskResultHolder resultHolder) throws Exception {
DatabaseHelper.getPersonDao().saveAndSnapshot(caseToSave.getPerson());
// epid number
if (StringUtils.isBlank(caseToSave.getEpidNumber())) {
Calendar calendar = Calendar.getInstance();
String year = String.valueOf(calendar.get(Calendar.YEAR)).substring(2);
caseToSave.setEpidNumber(caseToSave.getResponsibleRegion().getEpidCode() != null ? caseToSave.getResponsibleRegion().getEpidCode() : "" + "-" + caseToSave.getResponsibleDistrict().getEpidCode() != null ? caseToSave.getResponsibleDistrict().getEpidCode() : "" + "-" + year + "-");
}
DatabaseHelper.getCaseDao().saveAndSnapshot(caseToSave);
if (!DataHelper.isNullOrEmpty(contactUuid)) {
Contact sourceContact = DatabaseHelper.getContactDao().queryUuid(contactUuid);
sourceContact.setResultingCaseUuid(caseToSave.getUuid());
sourceContact.setResultingCaseUser(ConfigProvider.getUser());
sourceContact.setContactStatus(ContactStatus.CONVERTED);
DatabaseHelper.getContactDao().saveAndSnapshot(sourceContact);
}
if (!DataHelper.isNullOrEmpty(eventParticipantUuid)) {
EventParticipant eventParticipant = DatabaseHelper.getEventParticipantDao().queryUuid(eventParticipantUuid);
eventParticipant.setResultingCaseUuid(caseToSave.getUuid());
DatabaseHelper.getEventParticipantDao().saveAndSnapshot(eventParticipant);
}
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
if (taskResult.getResultStatus().isSuccess()) {
CaseNewFragment fragment = (CaseNewFragment) getActiveFragment();
if (lineListingDiseases.contains(caseToSave.getDisease()) && Boolean.TRUE.equals(fragment.getContentBinding().rapidCaseEntryCheckBox.getValue())) {
setStoredRootEntity(buildRootEntity());
fragment.setActivityRootData(getStoredRootEntity());
fragment.updateForRapidCaseEntry(caseToSave);
setNewSubHeading(caseToSave.getPerson());
} else {
finish();
CaseEditActivity.startActivity(getContext(), caseToSave.getUuid(), CaseSection.CASE_INFO);
}
}
// do after clearing, because we want to show a success notification that would otherwise be hidden immediately
super.onPostExecute(taskResult);
saveTask = null;
}
}.executeOnThreadPool();
}
Aggregations