diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index ca811af251..b9bc74f526 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -356,7 +356,7 @@ public class DataService extends IntentService { String activeProfile = bundles.getString("activeprofile"); String profile = bundles.getString("profile"); NSProfile nsProfile = new NSProfile(new JSONObject(profile), activeProfile); - MainApp.bus().post(new EventNewBasalProfile(nsProfile)); + MainApp.bus().post(new EventNewBasalProfile(nsProfile, "NSClient")); PumpInterface pump = MainApp.getConfigBuilder(); if (pump != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java index 3e270e8a1b..b3750f59c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java @@ -7,8 +7,10 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; */ public class EventNewBasalProfile { public NSProfile newNSProfile = null; + public String from = ""; - public EventNewBasalProfile(NSProfile newProfile) { + public EventNewBasalProfile(NSProfile newProfile, String from) { newNSProfile = newProfile; + this.from = from; } } 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 34641f5ebb..f0cf085e16 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 @@ -618,7 +618,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick if (pump != null) { pump.setNewBasalProfile(nsProfile); log.debug("Setting new profile: " + profile); - MainApp.bus().post(new EventNewBasalProfile(nsProfile)); + MainApp.bus().post(new EventNewBasalProfile(nsProfile, "NewNSTreatmentDialog")); } else { log.error("No active pump selected"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 0e9e4512ae..b28927d3ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -156,7 +156,7 @@ public class IobCobCalculatorPlugin implements PluginBase { private void loadBgData() { //log.debug("Locking loadBgData"); synchronized (dataLock) { - onNewProfile(new EventNewBasalProfile(null)); + onNewProfile(new EventNewBasalProfile(null, "IobCobCalculator init")); bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia)), false); log.debug("BG data loaded. Size: " + bgReadings.size()); } @@ -545,6 +545,20 @@ public class IobCobCalculatorPlugin implements PluginBase { if (profile != null) { dia = profile.getDia(); } + if (ev.newNSProfile == null) { // on init no need of reset + return; + } + synchronized (dataLock) { + log.debug("Invalidating cached data because of new profile from " + ev.from + ". IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records"); + iobTable = new LongSparseArray<>(); + autosensDataTable = new LongSparseArray<>(); + } + sHandler.post(new Runnable() { + @Override + public void run() { + calculateSensitivityData(); + } + }); } // When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated