Add isActiveBg to EventNewBg.
(cherry picked from commit a8291ff)
This commit is contained in:
parent
063505fdb3
commit
7f45316a24
3 changed files with 15 additions and 14 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue