From 8c49119b15f6fa80dce507513162473c60274d6e Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Wed, 25 Jul 2018 23:47:59 +0200 Subject: [PATCH] processing the acceptance of the TBR request from the wearable --- .../plugins/Overview/OverviewFragment.java | 6 ++++ .../plugins/Wear/ActionStringHandler.java | 35 +++++++++++++++++++ .../events/EventWearAcceptOpenLoopChange.java | 9 +++++ .../androidaps/data/ListenerService.java | 19 +++++++++- 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Wear/events/EventWearAcceptOpenLoopChange.java 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 390a746e55..889b0c569f 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 @@ -109,6 +109,7 @@ import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog; +import info.nightscout.androidaps.plugins.Wear.events.EventWearAcceptOpenLoopChange; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; @@ -967,6 +968,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, scheduleUpdateGUI("EventNewOpenLoopNotification"); } + @Subscribe + public void onStatusEvent(final EventWearAcceptOpenLoopChange ev) { + scheduleUpdateGUI("EventWearAcceptOpenLoopChange"); + } + @Subscribe public void onStatusEvent(final EventTempTargetChange ev) { scheduleUpdateGUI("EventTempTargetChange"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index e8b102f8d5..0eaf205b1a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -1,10 +1,12 @@ package info.nightscout.androidaps.plugins.Wear; +import android.app.NotificationManager; import android.content.Context; import android.os.HandlerThread; import android.support.annotation.NonNull; import com.crashlytics.android.answers.CustomEvent; + import java.text.DateFormat; import java.text.DecimalFormat; import java.text.SimpleDateFormat; @@ -34,6 +36,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; @@ -47,11 +50,14 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; import info.nightscout.androidaps.plugins.Treatments.CarbsGenerator; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.Wear.events.EventWearAcceptOpenLoopChange; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.HardLimits; +import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; @@ -638,6 +644,35 @@ public class ActionStringHandler { doECarbs(carbs, starttime, duration); } else if ("dismissoverviewnotification".equals(act[0])) { MainApp.bus().post(new EventDismissNotification(SafeParse.stringToInt(act[1]))); + } else if ("changeRequest".equals(act[0])) { + // accept change request + final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; + Profile profile = MainApp.getConfigBuilder().getProfile(); + + MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() { + @Override + public void run() { + if (result.enacted) { + finalLastRun.tbrSetByPump = result; + finalLastRun.lastEnact = new Date(); + finalLastRun.lastOpenModeAccept = new Date(); + NSUpload.uploadDeviceStatus(); + ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class); + if (objectivesPlugin != null) { + ObjectivesPlugin.manualEnacts++; + ObjectivesPlugin.saveProgress(); + } + } + MainApp.bus().post(new EventWearAcceptOpenLoopChange()); + } + }); + FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp")); + + NotificationManager notificationManager = + (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(Constants.notificationID); + + } lastBolusWizard = null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/events/EventWearAcceptOpenLoopChange.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/events/EventWearAcceptOpenLoopChange.java new file mode 100644 index 0000000000..8422399a3b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/events/EventWearAcceptOpenLoopChange.java @@ -0,0 +1,9 @@ +package info.nightscout.androidaps.plugins.Wear.events; + +import info.nightscout.androidaps.events.Event; + +/** + * Created by mike on 07.08.2016. + */ +public class EventWearAcceptOpenLoopChange extends Event { +} diff --git a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java index 403d8d0ddd..acdd738e46 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -61,6 +61,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA"; private static final String ACTION_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS"; private static final String ACTION_CONFIRMATION = "com.dexdrip.stephenblack.nightwatch.CONFIRMACTION"; + private static final String ACTION_CONFIRMCHANGE = "com.dexdrip.stephenblack.nightwatch.CONFIRMCHANGE"; private static final String ACTION_INITIATE_ACTION = "com.dexdrip.stephenblack.nightwatch.INITIATE_ACTION"; @@ -227,6 +228,17 @@ public class ListenerService extends WearableListenerService implements GoogleAp String actionstring = intent.getStringExtra("actionstring"); sendConfirmActionstring(actionstring); + } else if(intent != null && ACTION_CONFIRMCHANGE.equals(intent.getAction())){ + googleApiConnect(); + + //dismiss notification + NotificationManagerCompat notificationManager = + NotificationManagerCompat.from(ListenerService.this); + notificationManager.cancel(CHANGE_NOTIF_ID); + + String actionstring = intent.getStringExtra("actionstring"); + sendConfirmActionstring(actionstring); + } else if(intent != null && ACTION_INITIATE_ACTION.equals(intent.getAction())){ googleApiConnect(); @@ -447,7 +459,12 @@ public class ListenerService extends WearableListenerService implements GoogleAp public static void confirmAction(Context context, String actionstring) { Intent intent = new Intent(context, ListenerService.class); intent.putExtra("actionstring", actionstring); - intent.setAction(ACTION_CONFIRMATION); + + if (actionstring.equals("changeRequest")) { + intent.setAction(ACTION_CONFIRMCHANGE); + } else { + intent.setAction(ACTION_CONFIRMATION); + } context.startService(intent); }