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); log.debug("Received Dexcom Data", data);
try { try {
JSONObject json = new JSONObject(data); JSONArray jsonArray = new JSONArray(data);
bgReading.value = json.getInt("m_trend"); log.debug("Received Dexcom Data size:" + jsonArray.length());
bgReading.direction = json.getString("m_trend"); for(int i = 0; i < jsonArray.length(); i++) {
bgReading.date = json.getLong("m_time"); JSONObject json = jsonArray.getJSONObject(i);
bgReading.raw = 0; bgReading.value = json.getInt("m_value");
MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); 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)) { if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
NSUpload.uploadBg(bgReading); NSUpload.uploadBg(bgReading);

View file

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