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 a10c182ad4..8c6d9f5c35 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 @@ -52,6 +52,7 @@ import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResultMA; import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressHelperActivity; import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger; @@ -448,13 +449,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain BolusProgressDialog.bolusEnded = true; - if (bolusProgressDialog != null && BolusProgressDialog.running) { - try { - bolusProgressDialog.dismiss(); - } catch (Exception e) { - e.printStackTrace(); // TODO: handle this better - } - } + MainApp.bus().post(new EventDismissBolusprogressIfRunning(result)); if (result.success) { Treatment t = new Treatment(); @@ -501,13 +496,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain BolusProgressDialog.bolusEnded = true; - if (bolusProgressDialog != null && BolusProgressDialog.running) { - try { - bolusProgressDialog.dismiss(); - } catch (Exception e) { - e.printStackTrace(); // TODO: handle this better - } - } + MainApp.bus().post(new EventDismissBolusprogressIfRunning(result)); if (Config.logCongigBuilderActions) log.debug("deliverTreatment insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index a5d45128be..31ffa468d8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -20,6 +20,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusStart; @@ -127,6 +128,13 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL started = true; } + @Subscribe + public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { + if(BolusProgressDialog.running){ + dismiss(); + } + } + @Subscribe public void onStatusEvent(final EventPumpStatusChanged c) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java new file mode 100644 index 0000000000..9d8435eaf1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.plugins.Overview.events; + +import info.nightscout.androidaps.data.PumpEnactResult; + +/** + * Created by adrian on 20/02/17. + */ + +public class EventDismissBolusprogressIfRunning { + public final PumpEnactResult result; + + public EventDismissBolusprogressIfRunning(PumpEnactResult result) { + this.result = result; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index c9520ac82c..0884cdf55e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -17,6 +17,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; +import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Wear.wearintegration.WatchUpdaterService; import info.nightscout.utils.ToastUtils; @@ -177,6 +178,20 @@ public class WearPlugin implements PluginBase { } + @Subscribe + public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { + String status; + if(ev.result.success){ + status = MainApp.sResources.getString(R.string.success); + } else { + status = MainApp.sResources.getString(R.string.nosuccess); + } + Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS); + intent.putExtra("progresspercent", 100); + intent.putExtra("progressstatus", status); + ctx.startService(intent); + } + public void requestActionConfirmation(String title, String message, String actionstring){ Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_ACTIONCONFIRMATIONREQUEST); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 58e2375142..c1e7737ac4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -540,4 +540,5 @@ Wear settings Show detailed IOB Break down IOB into bolus and basal IOB on the watchface + not successful - please check phone