Only invoke the loop for new BGs.

This commit is contained in:
Johannes Mockenhaupt 2018-03-13 15:03:12 +01:00
parent 1e359184a9
commit 063505fdb3
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 10 additions and 8 deletions

View file

@ -241,7 +241,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
VirtualPumpPlugin.setFakingStatus(true); VirtualPumpPlugin.setFakingStatus(true);
scheduleBgChange(null); // trigger refresh scheduleBgChange(null, false); // trigger refresh
scheduleTemporaryBasalChange(); scheduleTemporaryBasalChange();
scheduleTreatmentChange(null); scheduleTreatmentChange(null);
scheduleExtendedBolusChange(); scheduleExtendedBolusChange();
@ -374,7 +374,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
if (old == null) { if (old == null) {
getDaoBgReadings().create(bgReading); getDaoBgReadings().create(bgReading);
log.debug("BG: New record from: " + from + " " + bgReading.toString()); log.debug("BG: New record from: " + from + " " + bgReading.toString());
scheduleBgChange(bgReading); scheduleBgChange(bgReading, true);
return true; return true;
} }
if (!old.isEqual(bgReading)) { if (!old.isEqual(bgReading)) {
@ -382,7 +382,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
old.copyFrom(bgReading); old.copyFrom(bgReading);
getDaoBgReadings().update(old); getDaoBgReadings().update(old);
log.debug("BG: Updating record from: " + from + " New data: " + old.toString()); log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
scheduleBgChange(bgReading); scheduleBgChange(bgReading, false);
return false; return false;
} }
} catch (SQLException e) { } 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 { class PostRunnable implements Runnable {
public void run() { public void run() {
log.debug("Firing EventNewBg"); log.debug("Firing EventNewBg");
MainApp.bus().post(new EventNewBG(bgReading)); MainApp.bus().post(new EventNewBG(bgReading, isNew));
scheduledBgPost = null; scheduledBgPost = null;
} }
} }

View file

@ -10,8 +10,10 @@ import info.nightscout.androidaps.db.BgReading;
public class EventNewBG extends EventLoop { public class EventNewBG extends EventLoop {
@Nullable @Nullable
public final BgReading bgReading; public final BgReading bgReading;
public final boolean isNew;
public EventNewBG(BgReading bgReading) { public EventNewBG(BgReading bgReading, boolean isNew) {
this.bgReading = bgReading; this.bgReading = bgReading;
this.isNew = isNew;
} }
} }

View file

@ -159,8 +159,8 @@ public class LoopPlugin implements PluginBase {
@Subscribe @Subscribe
public void onStatusEvent(final EventAutosensCalculationFinished ev) { public void onStatusEvent(final EventAutosensCalculationFinished ev) {
if (ev.cause instanceof EventNewBG) { if (ev.cause instanceof EventNewBG && ((EventNewBG) ev.cause).isNew) {
invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true); invoke("New BG", true);
} }
} }