From 7f45316a241d71dc79ac4efaee2a93266de39524 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 17 Mar 2018 13:22:12 +0100 Subject: [PATCH] Add isActiveBg to EventNewBg. (cherry picked from commit a8291ff) --- .../nightscout/androidaps/Services/DataService.java | 12 ++++++------ .../nightscout/androidaps/db/DatabaseHelper.java | 13 ++++++------- .../nightscout/androidaps/events/EventNewBG.java | 4 +++- 3 files changed, 15 insertions(+), 14 deletions(-) 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 14465ccdc9..704d10bb23 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -192,7 +192,7 @@ public class DataService extends IntentService { bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP); bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW); - MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP"); + MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP", xDripEnabled); } private void handleNewDataFromGlimp(Intent intent) { @@ -206,7 +206,7 @@ public class DataService extends IntentService { bgReading.date = bundle.getLong("myTimestamp"); bgReading.raw = 0; - MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP"); + MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP", glimpEnabled); } private void handleNewDataFromDexcomG5(Intent intent) { @@ -229,7 +229,7 @@ public class DataService extends IntentService { bgReading.direction = json.getString("m_trend"); bgReading.date = json.getLong("m_time") * 1000L; bgReading.raw = 0; - boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5", dexcomG5Enabled); if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { NSUpload.uploadBg(bgReading); } @@ -268,7 +268,7 @@ public class DataService extends IntentService { bgReading.date = json_object.getLong("date"); bgReading.raw = json_object.getDouble("sgv"); - MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g"); + MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g", mm640gEnabled); break; default: log.debug("Unknown entries type: " + type); @@ -428,7 +428,7 @@ public class DataService extends IntentService { JSONObject sgvJson = new JSONObject(sgvstring); NSSgv nsSgv = new NSSgv(sgvJson); BgReading bgReading = new BgReading(nsSgv); - MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); + MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled); } if (bundles.containsKey("sgvs")) { @@ -438,7 +438,7 @@ public class DataService extends IntentService { JSONObject sgvJson = jsonArray.getJSONObject(i); NSSgv nsSgv = new NSSgv(sgvJson); BgReading bgReading = new BgReading(nsSgv); - MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); + MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled); } } } catch (Exception e) { 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 f7285d4691..52b4f6c40b 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -8,7 +8,6 @@ import android.support.annotation.Nullable; import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; import com.j256.ormlite.dao.CloseableIterator; import com.j256.ormlite.dao.Dao; -import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.stmt.Where; @@ -241,7 +240,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { log.error("Unhandled exception", e); } VirtualPumpPlugin.setFakingStatus(true); - scheduleBgChange(null, false); // trigger refresh + scheduleBgChange(null, false, false); // trigger refresh scheduleTemporaryBasalChange(); scheduleTreatmentChange(null); scheduleExtendedBolusChange(); @@ -367,14 +366,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } // ------------------- BgReading handling ----------------------- - public boolean createIfNotExists(BgReading bgReading, String from) { + public boolean createIfNotExists(BgReading bgReading, String from, boolean isActiveBgSource) { try { bgReading.date = roundDateToSec(bgReading.date); BgReading old = getDaoBgReadings().queryForId(bgReading.date); if (old == null) { getDaoBgReadings().create(bgReading); log.debug("BG: New record from: " + from + " " + bgReading.toString()); - scheduleBgChange(bgReading, true); + scheduleBgChange(bgReading, true, isActiveBgSource); return true; } if (!old.isEqual(bgReading)) { @@ -382,7 +381,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, false); + scheduleBgChange(bgReading, false, isActiveBgSource); return false; } } catch (SQLException e) { @@ -400,11 +399,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - private static void scheduleBgChange(@Nullable final BgReading bgReading, boolean isNew) { + private static void scheduleBgChange(@Nullable final BgReading bgReading, boolean isNew, boolean isActiveBgSource) { class PostRunnable implements Runnable { public void run() { log.debug("Firing EventNewBg"); - MainApp.bus().post(new EventNewBG(bgReading, isNew)); + MainApp.bus().post(new EventNewBG(bgReading, isNew, isActiveBgSource)); 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 28116c7bd3..52c5d188fe 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java @@ -11,9 +11,11 @@ public class EventNewBG extends EventLoop { @Nullable public final BgReading bgReading; public final boolean isNew; + public final boolean isActiveBgSource; - public EventNewBG(BgReading bgReading, boolean isNew) { + public EventNewBG(@Nullable BgReading bgReading, boolean isNew, boolean isActiveBgSource) { this.bgReading = bgReading; this.isNew = isNew; + this.isActiveBgSource = isActiveBgSource; } }