From 2db63d4be4cc8dba948c7792a602cdf125545ea1 Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Wed, 25 Jul 2018 23:28:15 +0200 Subject: [PATCH 1/8] dismiss notification when accepting a TBR request --- .../androidaps/plugins/Overview/OverviewFragment.java | 4 ++++ 1 file changed, 4 insertions(+) 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 f844c11609..390a746e55 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 @@ -765,6 +765,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } }); FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp")); + // dismiss notifications + NotificationManager notificationManager = + (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(Constants.notificationID); }); builder.setNegativeButton(MainApp.gs(R.string.cancel), null); builder.show(); From 5bb6635cab74ebc8e0d605569dbaf49496022cf6 Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Wed, 25 Jul 2018 23:32:23 +0200 Subject: [PATCH 2/8] dismiss notification for TBR request if it's no longer requested --- .../info/nightscout/androidaps/plugins/Loop/LoopPlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 480646ccfc..59fbb7e694 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -407,6 +407,10 @@ public class LoopPlugin extends PluginBase { // mId allows you to update the notification later on. mNotificationManager.notify(Constants.notificationID, builder.build()); MainApp.bus().post(new EventNewOpenLoopNotification()); + // dismiss notifications + NotificationManager notificationManager = + (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(Constants.notificationID); } } From e2ef8f2d7480f77a3984a42cbbb4af9c95fe5dae Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Wed, 25 Jul 2018 23:37:26 +0200 Subject: [PATCH 3/8] send notification about TBR request to the wearable --- .../androidaps/plugins/Loop/LoopPlugin.java | 9 +++- .../plugins/Wear/ActionStringHandler.java | 13 ++++++ .../androidaps/plugins/Wear/WearPlugin.java | 9 ++++ .../wearintegration/WatchUpdaterService.java | 26 ++++++++++++ .../androidaps/data/ListenerService.java | 40 +++++++++++++++++- wear/src/main/res/drawable/notif_icon.png | Bin 0 -> 3123 bytes 6 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 wear/src/main/res/drawable/notif_icon.png diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 59fbb7e694..ff0037e6a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -45,6 +45,7 @@ import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui; import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.utils.FabricPrivacy; @@ -385,7 +386,8 @@ public class LoopPlugin extends PluginBase { .setAutoCancel(true) .setPriority(Notification.PRIORITY_HIGH) .setCategory(Notification.CATEGORY_ALARM) - .setVisibility(Notification.VISIBILITY_PUBLIC); + .setVisibility(Notification.VISIBILITY_PUBLIC) + .setLocalOnly(true); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(MainApp.instance().getApplicationContext(), MainActivity.class); @@ -407,10 +409,15 @@ public class LoopPlugin extends PluginBase { // mId allows you to update the notification later on. mNotificationManager.notify(Constants.notificationID, builder.build()); MainApp.bus().post(new EventNewOpenLoopNotification()); + + // Send to Wear + ActionStringHandler.handleInitiate("changeRequest"); + } else if (allowNotification) { // dismiss notifications NotificationManager notificationManager = (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(Constants.notificationID); + ActionStringHandler.handleInitiate("cancelChangeRequest"); } } 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 fc4728c53c..e8b102f8d5 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,8 +1,10 @@ package info.nightscout.androidaps.plugins.Wear; +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; @@ -352,6 +354,17 @@ public class ActionStringHandler { } rAction += "ecarbs " + carbsAfterConstraints + " " + starttimestamp + " " + duration; + } else if ("changeRequest".equals(act[0])) { + ////////////////////////////////////////////// CHANGE REQUEST + rTitle = MainApp.gs(R.string.openloop_newsuggestion); + rAction = "changeRequest"; + final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; + rMessage += finalLastRun.constraintsProcessed; + + WearPlugin.getPlugin().requestChangeConfirmation(rTitle, rMessage, rAction); + lastSentTimestamp = System.currentTimeMillis(); + lastConfirmActionString = rAction; + return; } else return; 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 6cb47e1a3a..1250d5c8df 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 @@ -192,6 +192,15 @@ public class WearPlugin extends PluginBase { ctx.startService(intent); } + public void requestChangeConfirmation(String title, String message, String actionstring) { + + Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_CHANGECONFIRMATIONREQUEST); + intent.putExtra("title", title); + intent.putExtra("message", message); + intent.putExtra("actionstring", actionstring); + ctx.startService(intent); + } + public static void registerWatchUpdaterService(WatchUpdaterService wus) { watchUS = wus; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index b5d30ad071..f8144a30bf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -64,6 +64,7 @@ public class WatchUpdaterService extends WearableListenerService implements public static final String ACTION_SEND_BOLUSPROGRESS = WatchUpdaterService.class.getName().concat(".BolusProgress"); public static final String ACTION_SEND_ACTIONCONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ActionConfirmationRequest"); + public static final String ACTION_SEND_CHANGECONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ChangeConfirmationRequest"); private GoogleApiClient googleApiClient; public static final String WEARABLE_DATA_PATH = "/nightscout_watch_data"; @@ -78,6 +79,7 @@ public class WatchUpdaterService extends WearableListenerService implements public static final String BASAL_DATA_PATH = "/nightscout_watch_basal"; public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress"; public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest"; + public static final String ACTION_CHANGECONFIRMATION_REQUEST_PATH = "/nightscout_watch_changeconfirmationrequest"; boolean wear_integration = false; @@ -153,6 +155,11 @@ public class WatchUpdaterService extends WearableListenerService implements String message = intent.getStringExtra("message"); String actionstring = intent.getStringExtra("actionstring"); sendActionConfirmationRequest(title, message, actionstring); + } else if (ACTION_SEND_CHANGECONFIRMATIONREQUEST.equals(action)) { + String title = intent.getStringExtra("title"); + String message = intent.getStringExtra("message"); + String actionstring = intent.getStringExtra("actionstring"); + sendChangeConfirmationRequest(title, message, actionstring); } else { sendData(); } @@ -577,6 +584,25 @@ public class WatchUpdaterService extends WearableListenerService implements } } + private void sendChangeConfirmationRequest(String title, String message, String actionstring) { + if (googleApiClient.isConnected()) { + PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_CHANGECONFIRMATION_REQUEST_PATH); + //unique content + dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); + dataMapRequest.getDataMap().putString("changeConfirmationRequest", "changeConfirmationRequest"); + dataMapRequest.getDataMap().putString("title", title); + dataMapRequest.getDataMap().putString("message", message); + dataMapRequest.getDataMap().putString("actionstring", actionstring); + + log.debug("Requesting confirmation from wear: " + actionstring); + + PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); + } else { + Log.e("changeConfirmRequest", "No connection to wearable available!"); + } + } + private void sendStatus() { if (googleApiClient.isConnected()) { 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 7297d51815..403d8d0ddd 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.data; +import android.app.Notification; +import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; @@ -49,10 +51,12 @@ public class ListenerService extends WearableListenerService implements GoogleAp public static final String BASAL_DATA_PATH = "/nightscout_watch_basal"; public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress"; public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest"; + public static final String NEW_CHANGECONFIRMATIONREQUEST_PATH = "/nightscout_watch_changeconfirmationrequest"; public static final int BOLUS_PROGRESS_NOTIF_ID = 001; public static final int CONFIRM_NOTIF_ID = 002; + public static final int CHANGE_NOTIF_ID = 556677; private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA"; private static final String ACTION_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS"; @@ -273,7 +277,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp showConfirmationDialog(title, message, actionstring); } - }else if (path.equals(NEW_STATUS_PATH)) { + } else if (path.equals(NEW_STATUS_PATH)) { dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); Intent messageIntent = new Intent(); messageIntent.setAction(Intent.ACTION_SEND); @@ -294,6 +298,11 @@ public class ListenerService extends WearableListenerService implements GoogleAp editor.putBoolean("wearcontrol", wearcontrol); editor.commit(); } + } else if (path.equals(NEW_CHANGECONFIRMATIONREQUEST_PATH)) { + String title = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("title"); + String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message"); + String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring"); + notifyChangeRequest(title, message, actionstring); } else { dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); Intent messageIntent = new Intent(); @@ -305,6 +314,35 @@ public class ListenerService extends WearableListenerService implements GoogleAp } } + private void notifyChangeRequest(String title, String message, String actionstring) { + + Notification.Builder builder = + new Notification.Builder(this); //,"AndroidAPS-Openloop"); + builder.setSmallIcon(R.drawable.notif_icon) + .setContentTitle(title) + .setContentText(message) + .setPriority(Notification.PRIORITY_HIGH); + + // Creates an explicit intent for an Activity in your app + Intent intent = new Intent(this, AcceptActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + Bundle params = new Bundle(); + params.putString("title", title); + params.putString("message", message); + params.putString("actionstring", actionstring); + intent.putExtras(params); + + PendingIntent resultPendingIntent = + PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + builder.setContentIntent(resultPendingIntent); + builder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}); + + NotificationManager mNotificationManager = + (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + // mId allows you to update the notification later on. + mNotificationManager.notify(CHANGE_NOTIF_ID, builder.build()); + } + private void showBolusProgress(int progresspercent, String progresstatus) { Intent cancelIntent = new Intent(this, ListenerService.class); cancelIntent.setAction(ACTION_CANCELBOLUS); diff --git a/wear/src/main/res/drawable/notif_icon.png b/wear/src/main/res/drawable/notif_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..480d0eaf778f20b95946a31a32b13136dd303327 GIT binary patch literal 3123 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 N002ovPDHLkV1oL{+4uke literal 0 HcmV?d00001 From 8c49119b15f6fa80dce507513162473c60274d6e Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Wed, 25 Jul 2018 23:47:59 +0200 Subject: [PATCH 4/8] 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); } From 971e25826544f33051ba4130a16b61ee78b7442a Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Wed, 25 Jul 2018 23:48:54 +0200 Subject: [PATCH 5/8] cancel TBR request notification on wearable if accepted or no longer valid --- .../plugins/Overview/OverviewFragment.java | 2 ++ .../plugins/Wear/ActionStringHandler.java | 6 +++++ .../androidaps/plugins/Wear/WearPlugin.java | 6 +++++ .../wearintegration/WatchUpdaterService.java | 23 ++++++++++++++++++- .../androidaps/data/ListenerService.java | 10 ++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) 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 889b0c569f..e15488d998 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.ActionStringHandler; import info.nightscout.androidaps.plugins.Wear.events.EventWearAcceptOpenLoopChange; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; @@ -770,6 +771,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NotificationManager notificationManager = (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(Constants.notificationID); + ActionStringHandler.handleInitiate("cancelChangeRequest"); }); builder.setNegativeButton(MainApp.gs(R.string.cancel), null); builder.show(); 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 0eaf205b1a..4d4f01310b 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 @@ -371,6 +371,12 @@ public class ActionStringHandler { lastSentTimestamp = System.currentTimeMillis(); lastConfirmActionString = rAction; return; + } else if ("cancelChangeRequest".equals(act[0])) { + ////////////////////////////////////////////// CANCEL CHANGE REQUEST NOTIFICATION + rAction = "cancelChangeRequest"; + + WearPlugin.getPlugin().requestNotificationCancel(rAction); + return; } else return; 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 1250d5c8df..72b2397213 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 @@ -100,6 +100,12 @@ public class WearPlugin extends PluginBase { ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS)); } + void requestNotificationCancel(String actionstring) { + Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_CANCEL_NOTIFICATION); + intent.putExtra("actionstring", actionstring); + ctx.startService(intent); + } + @Subscribe public void onStatusEvent(final EventPreferenceChange ev) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index f8144a30bf..9f3a26d905 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -63,8 +63,8 @@ public class WatchUpdaterService extends WearableListenerService implements public static final String ACTION_SEND_BASALS = WatchUpdaterService.class.getName().concat(".SendBasals"); public static final String ACTION_SEND_BOLUSPROGRESS = WatchUpdaterService.class.getName().concat(".BolusProgress"); public static final String ACTION_SEND_ACTIONCONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ActionConfirmationRequest"); - public static final String ACTION_SEND_CHANGECONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ChangeConfirmationRequest"); + public static final String ACTION_CANCEL_NOTIFICATION = WatchUpdaterService.class.getName().concat(".CancelNotification"); private GoogleApiClient googleApiClient; public static final String WEARABLE_DATA_PATH = "/nightscout_watch_data"; @@ -80,6 +80,7 @@ public class WatchUpdaterService extends WearableListenerService implements public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress"; public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest"; public static final String ACTION_CHANGECONFIRMATION_REQUEST_PATH = "/nightscout_watch_changeconfirmationrequest"; + public static final String ACTION_CANCELNOTIFICATION_REQUEST_PATH = "/nightscout_watch_cancelnotificationrequest"; boolean wear_integration = false; @@ -160,6 +161,9 @@ public class WatchUpdaterService extends WearableListenerService implements String message = intent.getStringExtra("message"); String actionstring = intent.getStringExtra("actionstring"); sendChangeConfirmationRequest(title, message, actionstring); + } else if (ACTION_CANCEL_NOTIFICATION.equals(action)) { + String actionstring = intent.getStringExtra("actionstring"); + sendCancelNotificationRequest(actionstring); } else { sendData(); } @@ -603,6 +607,23 @@ public class WatchUpdaterService extends WearableListenerService implements } } + private void sendCancelNotificationRequest(String actionstring) { + if (googleApiClient.isConnected()) { + PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_CANCELNOTIFICATION_REQUEST_PATH); + //unique content + dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); + dataMapRequest.getDataMap().putString("cancelNotificationRequest", "cancelNotificationRequest"); + dataMapRequest.getDataMap().putString("actionstring", actionstring); + + log.debug("Canceling notification on wear: " + actionstring); + + PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); + } else { + Log.e("cancelNotificationRequest", "No connection to wearable available!"); + } + } + private void sendStatus() { if (googleApiClient.isConnected()) { 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 acdd738e46..52dfc97ad1 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -52,6 +52,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress"; public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest"; public static final String NEW_CHANGECONFIRMATIONREQUEST_PATH = "/nightscout_watch_changeconfirmationrequest"; + public static final String ACTION_CANCELNOTIFICATION_REQUEST_PATH = "/nightscout_watch_cancelnotificationrequest"; public static final int BOLUS_PROGRESS_NOTIF_ID = 001; @@ -315,6 +316,9 @@ public class ListenerService extends WearableListenerService implements GoogleAp String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message"); String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring"); notifyChangeRequest(title, message, actionstring); + } else if (path.equals(ACTION_CANCELNOTIFICATION_REQUEST_PATH)) { + String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring"); + cancelNotificationRequest(actionstring); } else { dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); Intent messageIntent = new Intent(); @@ -355,6 +359,12 @@ public class ListenerService extends WearableListenerService implements GoogleAp mNotificationManager.notify(CHANGE_NOTIF_ID, builder.build()); } + private void cancelNotificationRequest(String actionstring) { + NotificationManager mNotificationManager = + (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + mNotificationManager.cancel(CHANGE_NOTIF_ID); + } + private void showBolusProgress(int progresspercent, String progresstatus) { Intent cancelIntent = new Intent(this, ListenerService.class); cancelIntent.setAction(ACTION_CANCELBOLUS); From 79abcdb0d794643c0e9b85497684c5fa0d2f5dbf Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Thu, 26 Jul 2018 11:47:39 +0200 Subject: [PATCH 6/8] moved tbr accepting to a new method of the LoopPlugin --- .../events/EventAcceptOpenLoopChange.java | 5 +++ .../androidaps/plugins/Loop/LoopPlugin.java | 25 +++++++++++++ .../plugins/Overview/OverviewFragment.java | 33 +++-------------- .../plugins/Wear/ActionStringHandler.java | 37 +------------------ .../events/EventWearAcceptOpenLoopChange.java | 9 ----- 5 files changed, 37 insertions(+), 72 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/events/EventAcceptOpenLoopChange.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Wear/events/EventWearAcceptOpenLoopChange.java diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventAcceptOpenLoopChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventAcceptOpenLoopChange.java new file mode 100644 index 0000000000..2dfbf9ae35 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/events/EventAcceptOpenLoopChange.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.events; + +/** Base class for events to update the UI, mostly a specific tab. */ +public class EventAcceptOpenLoopChange extends Event { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index ff0037e6a6..a5f9094a93 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -40,12 +40,14 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui; import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; +import info.nightscout.androidaps.events.EventAcceptOpenLoopChange; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.utils.FabricPrivacy; @@ -428,4 +430,27 @@ public class LoopPlugin extends PluginBase { } } + public void acceptChangeRequest() { + Profile profile = MainApp.getConfigBuilder().getProfile(); + + MainApp.getConfigBuilder().applyTBRRequest(lastRun.constraintsProcessed, profile, new Callback() { + @Override + public void run() { + if (result.enacted) { + lastRun.tbrSetByPump = result; + lastRun.lastEnact = new Date(); + lastRun.lastOpenModeAccept = new Date(); + NSUpload.uploadDeviceStatus(); + ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class); + if (objectivesPlugin != null) { + ObjectivesPlugin.manualEnacts++; + ObjectivesPlugin.saveProgress(); + } + } + MainApp.bus().post(new EventAcceptOpenLoopChange()); + } + }); + FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp")); + } + } 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 e15488d998..d5fd250d16 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 @@ -84,7 +84,6 @@ import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; @@ -110,7 +109,7 @@ 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.ActionStringHandler; -import info.nightscout.androidaps.plugins.Wear.events.EventWearAcceptOpenLoopChange; +import info.nightscout.androidaps.events.EventAcceptOpenLoopChange; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; @@ -749,29 +748,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> { hideTempRecommendation(); clearNotification(); - 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(); - } - } - scheduleUpdateGUI("onClickAcceptTemp"); - } - }); - FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp")); - // dismiss notifications - NotificationManager notificationManager = - (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.cancel(Constants.notificationID); - ActionStringHandler.handleInitiate("cancelChangeRequest"); + LoopPlugin.getPlugin().acceptChangeRequest(); }); builder.setNegativeButton(MainApp.gs(R.string.cancel), null); builder.show(); @@ -971,8 +948,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } @Subscribe - public void onStatusEvent(final EventWearAcceptOpenLoopChange ev) { - scheduleUpdateGUI("EventWearAcceptOpenLoopChange"); + public void onStatusEvent(final EventAcceptOpenLoopChange ev) { + scheduleUpdateGUI("EventAcceptOpenLoopChange"); } @Subscribe @@ -1015,6 +992,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NotificationManager notificationManager = (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(Constants.notificationID); + + ActionStringHandler.handleInitiate("cancelChangeRequest"); } private void updatePumpStatus(String status) { 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 4d4f01310b..0e21ec5fc2 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,12 +1,8 @@ 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; @@ -36,7 +32,6 @@ 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; @@ -50,14 +45,11 @@ 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; @@ -651,34 +643,7 @@ public class ActionStringHandler { } 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); - - + LoopPlugin.getPlugin().acceptChangeRequest(); } 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 deleted file mode 100644 index 8422399a3b..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/events/EventWearAcceptOpenLoopChange.java +++ /dev/null @@ -1,9 +0,0 @@ -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 { -} From ee06d1119d19439237ae078be779dbb73a5547c1 Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Thu, 26 Jul 2018 13:07:08 +0200 Subject: [PATCH 7/8] clear Notification if tbr is accepted from wearable --- .../androidaps/plugins/Wear/ActionStringHandler.java | 5 +++++ 1 file changed, 5 insertions(+) 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 0e21ec5fc2..00b1d7e646 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,5 +1,7 @@ package info.nightscout.androidaps.plugins.Wear; +import android.app.NotificationManager; +import android.content.Context; import android.os.HandlerThread; import android.support.annotation.NonNull; @@ -644,6 +646,9 @@ public class ActionStringHandler { MainApp.bus().post(new EventDismissNotification(SafeParse.stringToInt(act[1]))); } else if ("changeRequest".equals(act[0])) { LoopPlugin.getPlugin().acceptChangeRequest(); + NotificationManager notificationManager = + (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(Constants.notificationID); } lastBolusWizard = null; } From e26f33081aecfee4c113caf88ec1c88c4d894108 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 1 Aug 2018 11:41:36 +0200 Subject: [PATCH 8/8] fix wrong merge --- .../info/nightscout/androidaps/plugins/Loop/LoopPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 7a82637cc9..c9fdb45f86 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -442,9 +442,9 @@ public class LoopPlugin extends PluginBase { } public void acceptChangeRequest() { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); - MainApp.getConfigBuilder().applyTBRRequest(lastRun.constraintsProcessed, profile, new Callback() { + applyTBRRequest(lastRun.constraintsProcessed, profile, new Callback() { @Override public void run() { if (result.enacted) {