G5: accept arrays

This commit is contained in:
Milos Kozak 2017-11-29 17:22:45 +01:00
parent 7fc9efde40
commit b73e12b731
2 changed files with 12 additions and 7 deletions

View file

@ -216,12 +216,16 @@ public class DataService extends IntentService {
log.debug("Received Dexcom Data", data);
try {
JSONObject json = new JSONObject(data);
bgReading.value = json.getInt("m_trend");
bgReading.direction = json.getString("m_trend");
bgReading.date = json.getLong("m_time");
bgReading.raw = 0;
MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
JSONArray jsonArray = new JSONArray(data);
log.debug("Received Dexcom Data size:" + jsonArray.length());
for(int i = 0; i < jsonArray.length(); i++) {
JSONObject json = jsonArray.getJSONObject(i);
bgReading.value = json.getInt("m_value");
bgReading.direction = json.getString("m_trend");
bgReading.date = json.getLong("m_time");
bgReading.raw = 0;
MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
}
if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
NSUpload.uploadBg(bgReading);

View file

@ -354,9 +354,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return;
}
if (!old.isEqual(bgReading)) {
log.debug("BG: Similiar found: " + old.toString());
old.copyFrom(bgReading);
getDaoBgReadings().update(old);
log.debug("BG: Updating record from: " + from + " " + old.toString());
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
scheduleBgChange();
return;
}