From 982e46d958a27882977d9341e7122e73695eb4b6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 10 Oct 2017 19:25:21 +0200 Subject: [PATCH] prepare profileswitch function for watch --- .../Dialogs/NewNSTreatmentDialog.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index 5dc21f4f38..2477b0019b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -717,4 +717,35 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick }); } + public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) { + sHandler.post(new Runnable() { + @Override + public void run() { + ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis()); + if (profileSwitch == null) { + profileSwitch = new ProfileSwitch(); + profileSwitch.date = System.currentTimeMillis(); + profileSwitch.source = Source.USER; + profileSwitch.profileName = MainApp.getConfigBuilder().getProfileName(); + profileSwitch.profileJson = MainApp.getConfigBuilder().getProfile().getData().toString(); + profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName(); + profileSwitch.durationInMinutes = duration; + profileSwitch.isCPP = percentage != 100 || timeshift != 0; + profileSwitch.timeshift = timeshift; + profileSwitch.percentage = percentage; + } + MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch); + + PumpInterface pump = MainApp.getConfigBuilder(); + if (pump != null) { + pump.setNewBasalProfile(profileSwitch.getProfileObject()); + MainApp.bus().post(new EventNewBasalProfile()); + } else { + log.error("No active pump selected"); + } + Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch")); + } + }); + } + }