diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 411e50d05f..e3caaf81ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -351,12 +351,15 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context); - if (bolusProgressDialog != null) { - bolusProgressDialog.dismiss(); - } + bolusProgressDialog.bolusEnded = true; - if (Config.logCongigBuilderActions) - log.debug("deliverTreatmentFromBolusWizard insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered); + if (bolusProgressDialog != null && bolusProgressDialog.running) { + try { + bolusProgressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); // TODO: handle this better + } + } if (result.success) { Treatment t = new Treatment(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index 199419a485..a105d07536 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -38,13 +38,10 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene Handler mHandler; public static HandlerThread mHandlerThread; - Context parentContext = null; - - public NewTreatmentDialog(Context context) { + public NewTreatmentDialog() { mHandlerThread = new HandlerThread(NewTreatmentDialog.class.getSimpleName()); mHandlerThread.start(); this.mHandler = new Handler(mHandlerThread.getLooper()); - parentContext = context; } @Override @@ -91,7 +88,9 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene final Double finalInsulinAfterConstraints = insulinAfterConstraints; final Integer finalCarbsAfterConstraints = carbsAfterConstraints; - AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); + final Context context = getContext(); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(this.getContext().getString(R.string.confirmation)); builder.setMessage(confirmMessage); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @@ -101,9 +100,9 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene mHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints, parentContext); + PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints, context); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentContext); + 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); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 3e845e8419..b9db84bd22 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -258,7 +258,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener { ArrayList profileList; profileList = profile.getProfileList(); - ArrayAdapter adapter = new ArrayAdapter(parentContext, + ArrayAdapter adapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, profileList); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); profileSpinner.setAdapter(adapter); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 1c225fc73a..e5235028d6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -137,7 +137,7 @@ public class OverviewFragment extends Fragment { @Override public void onClick(View view) { FragmentManager manager = getFragmentManager(); - NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog(getContext()); + NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog(); treatmentDialogFragment.show(manager, "TreatmentDialog"); } });