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