guard double clicks
This commit is contained in:
parent
8c8674ed63
commit
e4f15c0e0d
|
@ -51,6 +51,10 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
|||
|
||||
private Handler mHandler;
|
||||
|
||||
//one shot guards
|
||||
private boolean accepted;
|
||||
private boolean okClicked;
|
||||
|
||||
public NewTreatmentDialog() {
|
||||
HandlerThread mHandlerThread = new HandlerThread(NewTreatmentDialog.class.getSimpleName());
|
||||
mHandlerThread.start();
|
||||
|
@ -109,10 +113,15 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
public synchronized void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.ok:
|
||||
|
||||
if (okClicked){
|
||||
log.debug("guarding: ok already clicked");
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
okClicked = true;
|
||||
try {
|
||||
Double insulin = SafeParse.stringToDouble(editInsulin.getText());
|
||||
final Integer carbs = SafeParse.stringToInt(editCarbs.getText());
|
||||
|
@ -132,43 +141,50 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
|||
final int finalCarbsAfterConstraints = carbsAfterConstraints;
|
||||
|
||||
final Context context = getContext();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
|
||||
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
||||
builder.setMessage(Html.fromHtml(confirmMessage));
|
||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
if (finalInsulinAfterConstraints == 0)
|
||||
detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION;
|
||||
if (finalCarbsAfterConstraints == 0)
|
||||
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
|
||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||
detailedBolusInfo.context = context;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
||||
if (!result.success) {
|
||||
try {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||
builder.setMessage(result.comment);
|
||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
||||
builder.show();
|
||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
||||
// window has been destroyed
|
||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
synchronized (builder) {
|
||||
if (accepted) {
|
||||
log.debug("guarding: already accepted");
|
||||
return;
|
||||
}
|
||||
accepted = true;
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
if (finalInsulinAfterConstraints == 0)
|
||||
detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION;
|
||||
if (finalCarbsAfterConstraints == 0)
|
||||
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
|
||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||
detailedBolusInfo.context = context;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
||||
if (!result.success) {
|
||||
try {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||
builder.setMessage(result.comment);
|
||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
||||
builder.show();
|
||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
||||
// window has been destroyed
|
||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Answers.getInstance().logCustom(new CustomEvent("Bolus"));
|
||||
});
|
||||
Answers.getInstance().logCustom(new CustomEvent("Bolus"));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -113,6 +113,11 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
|||
|
||||
Context context;
|
||||
|
||||
//one shot guards
|
||||
private boolean accepted;
|
||||
private boolean okClicked;
|
||||
|
||||
|
||||
public WizardDialog() {
|
||||
super();
|
||||
mHandlerThread = new HandlerThread(WizardDialog.class.getSimpleName());
|
||||
|
@ -296,9 +301,15 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
public synchronized void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.ok:
|
||||
if (okClicked){
|
||||
log.debug("guarding: ok already clicked");
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
okClicked = true;
|
||||
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
|
||||
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
|
||||
|
||||
|
@ -326,56 +337,63 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
|||
final int carbTime = SafeParse.stringToInt(editCarbTime.getText());
|
||||
final boolean useSuperBolus = superbolusCheckbox.isChecked();
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||
builder.setMessage(Html.fromHtml(confirmMessage));
|
||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result;
|
||||
if (useSuperBolus) {
|
||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||
if (activeloop != null) {
|
||||
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
||||
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
|
||||
synchronized (builder) {
|
||||
if (accepted) {
|
||||
log.debug("guarding: already accepted");
|
||||
return;
|
||||
}
|
||||
accepted = true;
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result;
|
||||
if (useSuperBolus) {
|
||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||
if (activeloop != null) {
|
||||
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
||||
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
|
||||
}
|
||||
pump.cancelTempBasal(true);
|
||||
result = pump.setTempBasalAbsolute(0d, 120, true);
|
||||
if (!result.success) {
|
||||
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror), result.comment, null);
|
||||
}
|
||||
}
|
||||
pump.cancelTempBasal(true);
|
||||
result = pump.setTempBasalAbsolute(0d, 120, true);
|
||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||
detailedBolusInfo.context = context;
|
||||
detailedBolusInfo.glucose = bg;
|
||||
detailedBolusInfo.glucoseType = "Manual";
|
||||
detailedBolusInfo.carbTime = carbTime;
|
||||
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
result = pump.deliverTreatment(detailedBolusInfo);
|
||||
if (!result.success) {
|
||||
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror), result.comment, null);
|
||||
try {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||
builder.setMessage(result.comment);
|
||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
||||
builder.show();
|
||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
||||
// window has been destroyed
|
||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
}
|
||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||
detailedBolusInfo.context = context;
|
||||
detailedBolusInfo.glucose = bg;
|
||||
detailedBolusInfo.glucoseType = "Manual";
|
||||
detailedBolusInfo.carbTime = carbTime;
|
||||
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
result = pump.deliverTreatment(detailedBolusInfo);
|
||||
if (!result.success) {
|
||||
try {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||
builder.setMessage(result.comment);
|
||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
||||
builder.show();
|
||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
||||
// window has been destroyed
|
||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Answers.getInstance().logCustom(new CustomEvent("Wizard"));
|
||||
});
|
||||
Answers.getInstance().logCustom(new CustomEvent("Wizard"));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -52,6 +52,7 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import info.nightscout.androidaps.BuildConfig;
|
||||
import info.nightscout.androidaps.Config;
|
||||
|
@ -689,40 +690,48 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
|
||||
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
|
||||
final Context context = getContext();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
final AtomicBoolean accepted = new AtomicBoolean(false);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||
builder.setMessage(confirmMessage);
|
||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
||||
sHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||
detailedBolusInfo.context = context;
|
||||
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
||||
if (!result.success) {
|
||||
try {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||
builder.setMessage(result.comment);
|
||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
||||
builder.show();
|
||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
||||
// window has been destroyed
|
||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
synchronized (accepted) {
|
||||
if(accepted.get()) {
|
||||
log.debug("Guarding: already accepted!");
|
||||
return;
|
||||
}
|
||||
accepted.set(true);
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
||||
sHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||
detailedBolusInfo.context = context;
|
||||
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
||||
if (!result.success) {
|
||||
try {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||
builder.setMessage(result.comment);
|
||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
||||
builder.show();
|
||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
||||
// window has been destroyed
|
||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Answers.getInstance().logCustom(new CustomEvent("QuickWizard"));
|
||||
});
|
||||
Answers.getInstance().logCustom(new CustomEvent("QuickWizard"));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue