Don't show confirmation on empty message/input

This commit is contained in:
Roumen Georgiev 2018-03-01 16:57:36 +02:00 committed by GitHub
parent 38933ac323
commit bea486d816
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -278,75 +278,80 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
if (!initialEventTime.equals(eventTime)) { if (!initialEventTime.equals(eventTime)) {
confirmMessage += "<br/> Time: " + DateUtil.dateAndTimeString(eventTime); confirmMessage += "<br/> Time: " + DateUtil.dateAndTimeString(eventTime);
} }
if(confirmMessage.length() > 0) {
final int finalCarbsAfterConstraints = carbsAfterConstraints; final int finalCarbsAfterConstraints = carbsAfterConstraints;
final Context context = getContext(); final Context context = getContext();
final AlertDialog.Builder builder = new AlertDialog.Builder(context); final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(this.getContext().getString(R.string.confirmation)); builder.setTitle(this.getContext().getString(R.string.confirmation));
if (confirmMessage.startsWith("<br/>")) if (confirmMessage.startsWith("<br/>"))
confirmMessage = confirmMessage.substring("<br/>".length()); confirmMessage = confirmMessage.substring("<br/>".length());
builder.setMessage(Html.fromHtml(confirmMessage));
builder.setPositiveButton(getString(R.string.ok), (dialog, id) -> {
synchronized (builder) {
if (accepted) {
log.debug("guarding: already accepted");
return;
}
accepted = true;
if (suspendLoopCheckbox.isChecked()) { builder.setMessage(Html.fromHtml(confirmMessage));
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); builder.setPositiveButton(getString(R.string.ok), (dialog, id) -> {
activeloop.suspendTo(System.currentTimeMillis() + 30L * 60 * 1000); synchronized (builder) {
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { if (accepted) {
@Override log.debug("guarding: already accepted");
public void run() { return;
if (!result.success) { }
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); accepted = true;
if (suspendLoopCheckbox.isChecked()) {
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
activeloop.suspendTo(System.currentTimeMillis() + 30L * 60 * 1000);
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
}
} }
} });
}); }
}
if (startActivityTTCheckbox.isChecked() || (startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked())) { if (startActivityTTCheckbox.isChecked() || (startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked())) {
TempTarget tempTarget = new TempTarget(); TempTarget tempTarget = new TempTarget();
tempTarget.date = System.currentTimeMillis(); tempTarget.date = System.currentTimeMillis();
tempTarget.durationInMinutes = (int) ttDuration; tempTarget.durationInMinutes = (int) ttDuration;
tempTarget.reason = "Activity"; tempTarget.reason = "Activity";
tempTarget.source = Source.USER; tempTarget.source = Source.USER;
tempTarget.low = (double) finalTT; tempTarget.low = (double) finalTT;
tempTarget.high = (double) finalTT; tempTarget.high = (double) finalTT;
MainApp.getDbHelper().createOrUpdate(tempTarget); MainApp.getDbHelper().createOrUpdate(tempTarget);
} else if (ESMCheckbox.isChecked()) { } else if (ESMCheckbox.isChecked()) {
TempTarget tempTarget = new TempTarget(); TempTarget tempTarget = new TempTarget();
tempTarget.date = System.currentTimeMillis(); tempTarget.date = System.currentTimeMillis();
tempTarget.durationInMinutes = (int) esDuration; tempTarget.durationInMinutes = (int) esDuration;
tempTarget.reason = "Eating soon"; tempTarget.reason = "Eating soon";
tempTarget.source = Source.USER; tempTarget.source = Source.USER;
tempTarget.low = (double) finalEsTT; tempTarget.low = (double) finalEsTT;
tempTarget.high = (double) finalEsTT; tempTarget.high = (double) finalEsTT;
MainApp.getDbHelper().createOrUpdate(tempTarget); MainApp.getDbHelper().createOrUpdate(tempTarget);
} }
if (finalCarbsAfterConstraints > 0 || food != null) { if (finalCarbsAfterConstraints > 0 || food != null) {
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.date = eventTime.getTime(); detailedBolusInfo.date = eventTime.getTime();
detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION; detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION;
detailedBolusInfo.carbs = finalCarbsAfterConstraints; detailedBolusInfo.carbs = finalCarbsAfterConstraints;
// detailedBolusInfo.food = food; // detailedBolusInfo.food = food;
detailedBolusInfo.context = context; detailedBolusInfo.context = context;
detailedBolusInfo.source = Source.USER; detailedBolusInfo.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
}
} }
} });
}); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setNegativeButton(getString(R.string.cancel), null); builder.show();
builder.show(); dismiss();
dismiss(); } else
dismiss();
} catch (Exception e) { } catch (Exception e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
} }
@Override @Override