From 063505fdb3817592e7f7eab941fae2a96a8aa313 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 13 Mar 2018 15:03:12 +0100 Subject: [PATCH] Only invoke the loop for new BGs. --- .../info/nightscout/androidaps/db/DatabaseHelper.java | 10 +++++----- .../info/nightscout/androidaps/events/EventNewBG.java | 4 +++- .../nightscout/androidaps/plugins/Loop/LoopPlugin.java | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 06e411d856..f7285d4691 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -241,7 +241,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { log.error("Unhandled exception", e); } VirtualPumpPlugin.setFakingStatus(true); - scheduleBgChange(null); // trigger refresh + scheduleBgChange(null, false); // trigger refresh scheduleTemporaryBasalChange(); scheduleTreatmentChange(null); scheduleExtendedBolusChange(); @@ -374,7 +374,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (old == null) { getDaoBgReadings().create(bgReading); log.debug("BG: New record from: " + from + " " + bgReading.toString()); - scheduleBgChange(bgReading); + scheduleBgChange(bgReading, true); return true; } if (!old.isEqual(bgReading)) { @@ -382,7 +382,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(bgReading); getDaoBgReadings().update(old); log.debug("BG: Updating record from: " + from + " New data: " + old.toString()); - scheduleBgChange(bgReading); + scheduleBgChange(bgReading, false); return false; } } catch (SQLException e) { @@ -400,11 +400,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - private static void scheduleBgChange(@Nullable final BgReading bgReading) { + private static void scheduleBgChange(@Nullable final BgReading bgReading, boolean isNew) { class PostRunnable implements Runnable { public void run() { log.debug("Firing EventNewBg"); - MainApp.bus().post(new EventNewBG(bgReading)); + MainApp.bus().post(new EventNewBG(bgReading, isNew)); scheduledBgPost = null; } } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java index dc4d434e0a..28116c7bd3 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java @@ -10,8 +10,10 @@ import info.nightscout.androidaps.db.BgReading; public class EventNewBG extends EventLoop { @Nullable public final BgReading bgReading; + public final boolean isNew; - public EventNewBG(BgReading bgReading) { + public EventNewBG(BgReading bgReading, boolean isNew) { this.bgReading = bgReading; + this.isNew = isNew; } } 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 12db67534b..f47dfd314b 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 @@ -159,8 +159,8 @@ public class LoopPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventAutosensCalculationFinished ev) { - if (ev.cause instanceof EventNewBG) { - invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true); + if (ev.cause instanceof EventNewBG && ((EventNewBG) ev.cause).isNew) { + invoke("New BG", true); } }