One-short guards for Fill/Prime dialog.

This commit is contained in:
Johannes Mockenhaupt 2018-06-02 18:06:04 +02:00
parent 96fb4323f8
commit ef6ee43c32
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -61,6 +61,10 @@ public class FillDialog extends DialogFragment implements OnClickListener {
private EditText notesEdit; private EditText notesEdit;
//one shot guards
private boolean accepted;
private boolean okClicked;
final private TextWatcher textWatcher = new TextWatcher() { final private TextWatcher textWatcher = new TextWatcher() {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
@ -163,7 +167,14 @@ public class FillDialog extends DialogFragment implements OnClickListener {
} }
private void confirmAndDeliver() { private synchronized void confirmAndDeliver() {
if (okClicked) {
log.debug("guarding: ok already clicked");
dismiss();
return;
}
okClicked = true;
try { try {
Double insulin = SafeParse.stringToDouble(editInsulin.getText()); Double insulin = SafeParse.stringToDouble(editInsulin.getText());
@ -198,32 +209,40 @@ public class FillDialog extends DialogFragment implements OnClickListener {
if (insulinAfterConstraints > 0 || pumpSiteChangeCheckbox.isChecked() || insulinCartridgeChangeCheckbox.isChecked()) { if (insulinAfterConstraints > 0 || pumpSiteChangeCheckbox.isChecked() || insulinCartridgeChangeCheckbox.isChecked()) {
builder.setMessage(Html.fromHtml(Joiner.on("<br/>").join(confirmMessage))); builder.setMessage(Html.fromHtml(Joiner.on("<br/>").join(confirmMessage)));
builder.setPositiveButton(MainApp.gs(R.string.primefill), (dialog, id) -> { builder.setPositiveButton(MainApp.gs(R.string.primefill), (dialog, id) -> {
if (finalInsulinAfterConstraints > 0) { synchronized (builder) {
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); if (accepted) {
detailedBolusInfo.insulin = finalInsulinAfterConstraints; log.debug("guarding: already accepted");
detailedBolusInfo.context = context; return;
detailedBolusInfo.source = Source.USER; }
detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history) accepted = true;
detailedBolusInfo.notes = notes;
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() { if (finalInsulinAfterConstraints > 0) {
@Override DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
public void run() { detailedBolusInfo.insulin = finalInsulinAfterConstraints;
if (!result.success) { detailedBolusInfo.context = context;
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); detailedBolusInfo.source = Source.USER;
i.putExtra("soundid", R.raw.boluserror); detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history)
i.putExtra("status", result.comment); detailedBolusInfo.notes = notes;
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror)); ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @Override
MainApp.instance().startActivity(i); public void run() {
if (!result.success) {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
} }
} });
}); FabricPrivacy.getInstance().logCustom(new CustomEvent("Fill"));
FabricPrivacy.getInstance().logCustom(new CustomEvent("Fill")); }
if (pumpSiteChangeCheckbox.isChecked())
NSUpload.uploadEvent(CareportalEvent.SITECHANGE, now(), notes);
if (insulinCartridgeChangeCheckbox.isChecked())
NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, now() + 1000, notes);
} }
if (pumpSiteChangeCheckbox.isChecked())
NSUpload.uploadEvent(CareportalEvent.SITECHANGE, now(), notes);
if (insulinCartridgeChangeCheckbox.isChecked())
NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, now() + 1000, notes);
}); });
} else { } else {
builder.setMessage(MainApp.gs(R.string.no_action_selected)); builder.setMessage(MainApp.gs(R.string.no_action_selected));