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); JSONObject json = jsonArray.getJSONObject(i);
bgReading.value = json.getInt("m_value"); bgReading.value = json.getInt("m_value");
bgReading.direction = json.getString("m_trend"); bgReading.direction = json.getString("m_trend");
bgReading.date = json.getLong("m_time"); bgReading.date = json.getLong("m_time") * 1000L;
bgReading.raw = 0; bgReading.raw = 0;
MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
} if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
NSUpload.uploadBg(bgReading); NSUpload.uploadBg(bgReading);
} }
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

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

View file

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