From e5ed63a46fb862f201090888c76466fc978001ca Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 3 May 2018 00:13:49 +0200 Subject: [PATCH] fix name on future profile switches --- .../Dialogs/NewNSTreatmentDialog.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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 56aa0158cf..46c1e3666d 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 @@ -715,14 +715,26 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget")); } } else { - NSUpload.uploadCareportalEntryToNS(data); + if (JsonHelper.safeGetString(data, "eventType").equals(CareportalEvent.PROFILESWITCH)) { + ProfileSwitch profileSwitch = prepareProfileSwitch( + profileStore, + JsonHelper.safeGetString(data, "profile"), + JsonHelper.safeGetInt(data, "duration"), + JsonHelper.safeGetInt(data, "percentage"), + JsonHelper.safeGetInt(data, "timeshift"), + eventTime.getTime() + ); + NSUpload.uploadProfileSwitch(profileSwitch); + } else { + NSUpload.uploadCareportalEntryToNS(data); + } FabricPrivacy.getInstance().logCustom(new CustomEvent("NSTreatment")); } } - public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) { + public static ProfileSwitch prepareProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift, long date) { ProfileSwitch profileSwitch = new ProfileSwitch(); - profileSwitch.date = System.currentTimeMillis(); + profileSwitch.date = date; profileSwitch.source = Source.USER; profileSwitch.profileName = profileName; profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString(); @@ -731,6 +743,11 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick profileSwitch.isCPP = percentage != 100 || timeshift != 0; profileSwitch.timeshift = timeshift; profileSwitch.percentage = percentage; + return profileSwitch; + } + + public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) { + ProfileSwitch profileSwitch = prepareProfileSwitch(profileStore, profileName, duration, percentage, timeshift, System.currentTimeMillis()); TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch); FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch")); }