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 { -}