From 650111d1b7e9fd28c16ab398baa840b041715bc6 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 7 Feb 2017 11:09:16 +0100 Subject: [PATCH] wear event for bolus requests to show card early on --- .../events/EventBolusRequested.java | 21 +++++++++++++++++++ .../ConfigBuilder/ConfigBuilderPlugin.java | 5 +++++ .../androidaps/plugins/Wear/WearPlugin.java | 16 ++++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 43 insertions(+) create mode 100644 app/src/main/java/info/nightscout/androidaps/events/EventBolusRequested.java diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventBolusRequested.java b/app/src/main/java/info/nightscout/androidaps/events/EventBolusRequested.java new file mode 100644 index 0000000000..1f41119b4b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/events/EventBolusRequested.java @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.events; + +/** + * Created by adrian on 07/02/17. + */ + +public class EventBolusRequested { + private double amount; + + public EventBolusRequested (double amount){ + this.amount = amount; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } +} 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 1a21fb9dd6..69e6b910c7 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 @@ -26,6 +26,7 @@ import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.events.EventBolusRequested; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTreatmentChange; @@ -424,6 +425,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress"); } + MainApp.bus().post(new EventBolusRequested(insulin)); + PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context); BolusProgressDialog.bolusEnded = true; @@ -469,6 +472,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress"); } + MainApp.bus().post(new EventBolusRequested(insulin)); + PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context); BolusProgressDialog.bolusEnded = true; 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 9ee4e974a8..3d01bafb16 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 @@ -7,6 +7,7 @@ import com.squareup.otto.Subscribe; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.events.EventBolusRequested; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventPreferenceChange; @@ -17,6 +18,7 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Wear.wearintegration.WatchUpdaterService; +import info.nightscout.utils.ToastUtils; /** * Created by adrian on 17/11/16. @@ -151,6 +153,20 @@ public class WearPlugin implements PluginBase { ctx.startService(intent); } + @Subscribe + public void onStatusEvent(final EventBolusRequested ev) { + ToastUtils.showToastInUiThread(ctx, "EventBolusRequested !!!"); + String status = String.format(MainApp.sResources.getString(R.string.bolusrequested), ev.getAmount()); + + Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS); + intent.putExtra("progresspercent", 0); + intent.putExtra("progressstatus", status); + ToastUtils.showToastInUiThread(ctx, "before startService"); + ctx.startService(intent); + ToastUtils.showToastInUiThread(ctx, "after startService"); + + } + public static boolean isEnabled() { return fragmentEnabled; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6903b66124..1aa42e39b4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -252,6 +252,7 @@ To deliver bolus %.2fU reply with code %s Bolus failed Bolus %.2fU delivered successfully + Going to deliver %.2fU Bolus %.2fU delivered successfully Delivering %.2fU Allow remote commands via SMS