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 07ca0fc049..5faa288d77 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", xDripEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP"); } 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", glimpEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP"); } 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", dexcomG5Enabled); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); 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", mm640gEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g"); break; default: log.debug("Unknown entries type: " + type); @@ -425,7 +425,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", nsClientEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); } if (bundles.containsKey("sgvs")) { @@ -435,7 +435,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", nsClientEnabled); + MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); } } } 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 041f92ab84..68b506b37a 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -8,6 +8,7 @@ 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; @@ -240,7 +241,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { log.error("Unhandled exception", e); } VirtualPumpPlugin.setFakingStatus(true); - scheduleBgChange(null, false, false); // trigger refresh + scheduleBgChange(null); // trigger refresh scheduleTemporaryBasalChange(); scheduleTreatmentChange(null); scheduleExtendedBolusChange(); @@ -366,14 +367,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } // ------------------- BgReading handling ----------------------- - public boolean createIfNotExists(BgReading bgReading, String from, boolean isFromActiveBgSource) { + public boolean createIfNotExists(BgReading bgReading, String from) { 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, isFromActiveBgSource); + scheduleBgChange(bgReading); return true; } if (!old.isEqual(bgReading)) { @@ -381,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, false, isFromActiveBgSource); + scheduleBgChange(bgReading); return false; } } catch (SQLException e) { @@ -399,11 +400,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - private static void scheduleBgChange(@Nullable final BgReading bgReading, boolean isNew, boolean isFromActiveBgSource) { + private static void scheduleBgChange(@Nullable final BgReading bgReading) { class PostRunnable implements Runnable { public void run() { log.debug("Firing EventNewBg"); - MainApp.bus().post(new EventNewBG(bgReading, isNew, isFromActiveBgSource)); + MainApp.bus().post(new EventNewBG(bgReading)); 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 e65c02a58c..dc4d434e0a 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java @@ -10,17 +10,8 @@ import info.nightscout.androidaps.db.BgReading; public class EventNewBG extends EventLoop { @Nullable public final BgReading bgReading; - public final boolean isNew; - public final boolean isFromActiveBgSource; - /** Whether the BgReading is current (enough to use for treatment decisions). */ - public boolean isCurrent() { - return bgReading != null && bgReading.date + 9 * 60 * 1000 > System.currentTimeMillis(); - } - - public EventNewBG(@Nullable BgReading bgReading, boolean isNew, boolean isFromActiveBgSource) { + public EventNewBG(BgReading bgReading) { this.bgReading = bgReading; - this.isNew = isNew; - this.isFromActiveBgSource = isFromActiveBgSource; } } 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 19b8e492d6..c60991253c 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 @@ -531,8 +531,6 @@ public class IobCobCalculatorPlugin implements PluginBase { @Subscribe public void onEventNewBG(EventNewBG ev) { - if (!ev.isFromActiveBgSource) - return; if (this != getPlugin()) { log.debug("Ignoring event for non default instance"); return; 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 5846140b1e..12db67534b 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 @@ -23,7 +23,6 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.APSInterface; @@ -160,12 +159,8 @@ public class LoopPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventAutosensCalculationFinished ev) { - if (!(ev.cause instanceof EventNewBG)) - return; - - EventNewBG bgEv = (EventNewBG) ev.cause; - if (bgEv.isNew && bgEv.isFromActiveBgSource && bgEv.isCurrent()) { - invoke("New BG", true); + if (ev.cause instanceof EventNewBG) { + invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 0d59983796..56f2276327 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -142,16 +142,14 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com @Subscribe public void onStatusEvent(final EventNewBG e) { - if (e.isFromActiveBgSource && e.isNew && e.isCurrent()) { - Activity activity = getActivity(); - if (activity != null) - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - calculateInsulin(); - } - }); - } + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + calculateInsulin(); + } + }); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java index a68864b9c8..26d5851865 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java @@ -255,8 +255,7 @@ public class PersistentNotificationPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventNewBG ev) { - if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent()) - updateNotification(); + updateNotification(); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index bc44c75911..5f11fc5fda 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -182,8 +182,7 @@ public class WearPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventNewBG ev) { - if (ev.isFromActiveBgSource) - sendDataToWatch(true, true, true); + sendDataToWatch(true, true, true); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index f1fd58c3f9..76e8ac9e4d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -235,8 +235,7 @@ public class StatuslinePlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventNewBG ev) { - if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent()) - sendStatus(); + sendStatus(); } @Subscribe