Add isActiveBg to EventNewBg.

(cherry picked from commit a8291ff)
This commit is contained in:
Johannes Mockenhaupt 2018-03-17 13:22:12 +01:00
parent 063505fdb3
commit 7f45316a24
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 15 additions and 14 deletions

View file

@ -192,7 +192,7 @@ public class DataService extends IntentService {
bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP); bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP);
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW); bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP"); MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP", xDripEnabled);
} }
private void handleNewDataFromGlimp(Intent intent) { private void handleNewDataFromGlimp(Intent intent) {
@ -206,7 +206,7 @@ public class DataService extends IntentService {
bgReading.date = bundle.getLong("myTimestamp"); bgReading.date = bundle.getLong("myTimestamp");
bgReading.raw = 0; bgReading.raw = 0;
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP"); MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP", glimpEnabled);
} }
private void handleNewDataFromDexcomG5(Intent intent) { private void handleNewDataFromDexcomG5(Intent intent) {
@ -229,7 +229,7 @@ public class DataService extends IntentService {
bgReading.direction = json.getString("m_trend"); bgReading.direction = json.getString("m_trend");
bgReading.date = json.getLong("m_time") * 1000L; bgReading.date = json.getLong("m_time") * 1000L;
bgReading.raw = 0; 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)) { if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
NSUpload.uploadBg(bgReading); NSUpload.uploadBg(bgReading);
} }
@ -268,7 +268,7 @@ public class DataService extends IntentService {
bgReading.date = json_object.getLong("date"); bgReading.date = json_object.getLong("date");
bgReading.raw = json_object.getDouble("sgv"); bgReading.raw = json_object.getDouble("sgv");
MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g"); MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g", mm640gEnabled);
break; break;
default: default:
log.debug("Unknown entries type: " + type); log.debug("Unknown entries type: " + type);
@ -428,7 +428,7 @@ public class DataService extends IntentService {
JSONObject sgvJson = new JSONObject(sgvstring); JSONObject sgvJson = new JSONObject(sgvstring);
NSSgv nsSgv = new NSSgv(sgvJson); NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv); BgReading bgReading = new BgReading(nsSgv);
MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled);
} }
if (bundles.containsKey("sgvs")) { if (bundles.containsKey("sgvs")) {
@ -438,7 +438,7 @@ public class DataService extends IntentService {
JSONObject sgvJson = jsonArray.getJSONObject(i); JSONObject sgvJson = jsonArray.getJSONObject(i);
NSSgv nsSgv = new NSSgv(sgvJson); NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv); BgReading bgReading = new BgReading(nsSgv);
MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled);
} }
} }
} catch (Exception e) { } catch (Exception e) {

View file

@ -8,7 +8,6 @@ import android.support.annotation.Nullable;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.CloseableIterator; import com.j256.ormlite.dao.CloseableIterator;
import com.j256.ormlite.dao.Dao; import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where; import com.j256.ormlite.stmt.Where;
@ -241,7 +240,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
VirtualPumpPlugin.setFakingStatus(true); VirtualPumpPlugin.setFakingStatus(true);
scheduleBgChange(null, false); // trigger refresh scheduleBgChange(null, false, false); // trigger refresh
scheduleTemporaryBasalChange(); scheduleTemporaryBasalChange();
scheduleTreatmentChange(null); scheduleTreatmentChange(null);
scheduleExtendedBolusChange(); scheduleExtendedBolusChange();
@ -367,14 +366,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} }
// ------------------- BgReading handling ----------------------- // ------------------- BgReading handling -----------------------
public boolean createIfNotExists(BgReading bgReading, String from) { public boolean createIfNotExists(BgReading bgReading, String from, boolean isActiveBgSource) {
try { try {
bgReading.date = roundDateToSec(bgReading.date); bgReading.date = roundDateToSec(bgReading.date);
BgReading old = getDaoBgReadings().queryForId(bgReading.date); BgReading old = getDaoBgReadings().queryForId(bgReading.date);
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, true); scheduleBgChange(bgReading, true, isActiveBgSource);
return true; return true;
} }
if (!old.isEqual(bgReading)) { if (!old.isEqual(bgReading)) {
@ -382,7 +381,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, false); scheduleBgChange(bgReading, false, isActiveBgSource);
return false; return false;
} }
} catch (SQLException e) { } 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 { class PostRunnable implements Runnable {
public void run() { public void run() {
log.debug("Firing EventNewBg"); log.debug("Firing EventNewBg");
MainApp.bus().post(new EventNewBG(bgReading, isNew)); MainApp.bus().post(new EventNewBG(bgReading, isNew, isActiveBgSource));
scheduledBgPost = null; scheduledBgPost = null;
} }
} }

View file

@ -11,9 +11,11 @@ public class EventNewBG extends EventLoop {
@Nullable @Nullable
public final BgReading bgReading; public final BgReading bgReading;
public final boolean isNew; 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.bgReading = bgReading;
this.isNew = isNew; this.isNew = isNew;
this.isActiveBgSource = isActiveBgSource;
} }
} }