diff --git a/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java b/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java index 3ea93dd0b1..00a04df4c4 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java +++ b/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java @@ -28,5 +28,6 @@ public class DetailedBolusInfo { public JSONObject boluscalc = null; // additional bolus wizard info public Context context = null; // context for progress dialog public boolean addToTreatments = true; - public long pumpId = 0; // id of record if comming from pump history (not a newly created treatment) + public long pumpId = 0; // id of record if comming from pump history (not a newly created treatment) + public boolean isSMB = false; // is a Super-MicroBolus } 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 cdcda5c229..562085996a 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -60,7 +60,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public static final String DATABASE_CAREPORTALEVENTS = "CareportalEvents"; public static final String DATABASE_PROFILESWITCHES = "ProfileSwitches"; - private static final int DATABASE_VERSION = 7; + private static final int DATABASE_VERSION = 8; private static Long earliestDataChange = null; @@ -113,17 +113,23 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { @Override public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { try { - log.info(DatabaseHelper.class.getName(), "onUpgrade"); - TableUtils.dropTable(connectionSource, TempTarget.class, true); - TableUtils.dropTable(connectionSource, Treatment.class, true); - TableUtils.dropTable(connectionSource, BgReading.class, true); - TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true); - TableUtils.dropTable(connectionSource, DbRequest.class, true); - TableUtils.dropTable(connectionSource, TemporaryBasal.class, true); - TableUtils.dropTable(connectionSource, ExtendedBolus.class, true); - TableUtils.dropTable(connectionSource, CareportalEvent.class, true); - TableUtils.dropTable(connectionSource, ProfileSwitch.class, true); - onCreate(database, connectionSource); + if (oldVersion == 7 && newVersion == 8) { + log.debug("Upgrading database from v7 to v8"); + TableUtils.dropTable(connectionSource, Treatment.class, true); + TableUtils.createTableIfNotExists(connectionSource, Treatment.class); + } else { + log.info(DatabaseHelper.class.getName(), "onUpgrade"); + TableUtils.dropTable(connectionSource, TempTarget.class, true); + TableUtils.dropTable(connectionSource, Treatment.class, true); + TableUtils.dropTable(connectionSource, BgReading.class, true); + TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true); + TableUtils.dropTable(connectionSource, DbRequest.class, true); + TableUtils.dropTable(connectionSource, TemporaryBasal.class, true); + TableUtils.dropTable(connectionSource, ExtendedBolus.class, true); + TableUtils.dropTable(connectionSource, CareportalEvent.class, true); + TableUtils.dropTable(connectionSource, ProfileSwitch.class, true); + onCreate(database, connectionSource); + } } catch (SQLException e) { log.error("Can't drop databases", e); throw new RuntimeException(e); @@ -683,6 +689,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d; treatment.pumpId = trJson.has("pumpId") ? trJson.getLong("pumpId") : 0; treatment._id = trJson.getString("_id"); + treatment.isSMB = trJson.getBoolean("isSMB"); if (trJson.has("eventType")) { treatment.mealBolus = !trJson.get("eventType").equals("Correction Bolus"); double carbs = treatment.carbs; diff --git a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java index aaf7778cd6..722b534c7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java @@ -47,6 +47,8 @@ public class Treatment implements DataPointWithLabelInterface { public double carbs = 0d; @DatabaseField public boolean mealBolus = true; // true for meal bolus , false for correction bolus + @DatabaseField + public boolean isSMB = false; @DatabaseField public int insulinInterfaceID = InsulinInterface.FASTACTINGINSULIN; @@ -79,6 +81,7 @@ public class Treatment implements DataPointWithLabelInterface { "date= " + date + ", date= " + DateUtil.dateAndTimeString(date) + ", isValid= " + isValid + + ", isSMB= " + isSMB + ", _id= " + _id + ", pumpId= " + pumpId + ", insulin= " + insulin + @@ -110,6 +113,8 @@ public class Treatment implements DataPointWithLabelInterface { return false; if (pumpId != other.pumpId) return false; + if (isSMB != other.isSMB) + return false; if (!Objects.equals(_id, other._id)) return false; return true; @@ -122,6 +127,7 @@ public class Treatment implements DataPointWithLabelInterface { carbs = t.carbs; mealBolus = t.mealBolus; pumpId = t.pumpId; + isSMB = t.isSMB; } // ----------------- DataPointInterface -------------------- diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index aeb1f7181d..09ecbc9370 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -252,6 +252,7 @@ public class NSUpload { if (detailedBolusInfo.carbs != 0d) data.put("carbs", (int) detailedBolusInfo.carbs); data.put("created_at", DateUtil.toISOString(detailedBolusInfo.date)); data.put("date", detailedBolusInfo.date); + data.put("isSMB", detailedBolusInfo.isSMB); if (detailedBolusInfo.pumpId != 0) data.put("pumpId", detailedBolusInfo.pumpId); if (detailedBolusInfo.glucose != 0d)