G5 fix time value

This commit is contained in:
Milos Kozak 2017-11-29 23:00:41 +01:00
parent b73e12b731
commit 04742c60cd
3 changed files with 10 additions and 8 deletions

View file

@ -222,14 +222,14 @@ public class DataService extends IntentService {
JSONObject json = jsonArray.getJSONObject(i);
bgReading.value = json.getInt("m_value");
bgReading.direction = json.getString("m_trend");
bgReading.date = json.getLong("m_time");
bgReading.date = json.getLong("m_time") * 1000L;
bgReading.raw = 0;
MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
}
if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
NSUpload.uploadBg(bgReading);
}
}
} catch (JSONException e) {
e.printStackTrace();
}

View file

@ -343,7 +343,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
// ------------------- BgReading handling -----------------------
public void createIfNotExists(BgReading bgReading, String from) {
public boolean createIfNotExists(BgReading bgReading, String from) {
try {
bgReading.date = roundDateToSec(bgReading.date);
BgReading old = getDaoBgReadings().queryForId(bgReading.date);
@ -351,7 +351,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoBgReadings().create(bgReading);
log.debug("BG: New record from: " + from + " " + bgReading.toString());
scheduleBgChange();
return;
return true;
}
if (!old.isEqual(bgReading)) {
log.debug("BG: Similiar found: " + old.toString());
@ -359,11 +359,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoBgReadings().update(old);
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
scheduleBgChange();
return;
return false;
}
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return false;
}
private static void scheduleBgChange() {

View file

@ -776,5 +776,6 @@
<string name="dexcomg5_nsupload_title">Upload BG data to NS</string>
<string name="key_dexcomg5_nsupload">dexcomg5_nsupload</string>
<string name="dexcomg5_upload">G5 upload settings</string>
<string name="customapp">Customized APK for download</string>
</resources>