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);
}
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;
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}