use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class ListenerService method syncTreatmentsData.
private synchronized void syncTreatmentsData(DataMap dataMap, Context context) {
Log.d(TAG, "syncTreatmentsData");
boolean changed = false;
String action = dataMap.getString("action");
if (action.equals("delete")) {
Log.d(TAG, "syncTreatmentsData Delete Treatments");
deleteTreatment(dataMap);
showTreatments(context, "treats");
} else {
ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
if (entries != null) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
Log.d(TAG, "syncTreatmentsData add Treatments Table entries count=" + entries.size());
// ensure database has already been initialized
Sensor.InitDb(context);
for (DataMap entry : entries) {
if (entry != null) {
String record = entry.getString("data");
if (record != null) {
Treatments data = gson.fromJson(record, Treatments.class);
Treatments exists = Treatments.byuuid(data.uuid);
if (exists != null) {
Log.d(TAG, "syncTreatmentsData save existing Treatments for action insert uuid=" + data.uuid + " timestamp=" + data.timestamp + " timeString=" + JoH.dateTimeText(data.timestamp) + " carbs=" + data.carbs + " insulin=" + data.insulin + " exists.systime=" + JoH.dateTimeText(exists.systimestamp));
if (exists.timestamp != data.timestamp) {
// currently only tracking timestamp on watch
changed = true;
}
exists.enteredBy = data.enteredBy;
exists.eventType = data.eventType;
exists.insulin = data.insulin;
exists.carbs = data.carbs;
exists.created_at = data.created_at;
exists.notes = data.notes;
exists.timestamp = data.timestamp;
exists.systimestamp = exists.systimestamp > 0 ? exists.systimestamp : data.timestamp < last_send_previous_treatments ? data.timestamp : last_send_previous_treatments > 0 ? last_send_previous_treatments - 1 : JoH.tsl();
exists.save();
} else {
changed = true;
data.systimestamp = data.timestamp < last_send_previous_treatments ? data.timestamp : last_send_previous_treatments > 0 ? last_send_previous_treatments - 1 : JoH.tsl();
data.save();
Log.d(TAG, "syncTreatmentsData create new treatment for action insert uuid=" + data.uuid + " timestamp=" + data.timestamp + " timeString=" + JoH.dateTimeText(data.timestamp) + " carbs=" + data.carbs + " insulin=" + data.insulin + " systime=" + JoH.dateTimeText(data.systimestamp));
}
}
}
}
if (changed) {
showTreatments(context, "treats");
}
}
}
}
use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class ListenerService method sendSensorLocalMessage.
private void sendSensorLocalMessage(int steps, long timestamp) {
DataMap dataMap = new DataMap();
dataMap.putInt("steps", steps);
dataMap.putLong("steps_timestamp", timestamp);
sendLocalMessage("steps", dataMap);
}
use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class ListenerService method sendSyncRequested.
private synchronized void sendSyncRequested(String path, long syncLogsRequested) {
if (syncLogsRequested > 0)
syncLogsRequested--;
Log.d(TAG, "sendSyncRequested syncLogsRequested=" + syncLogsRequested);
DataMap dataMap = new DataMap();
dataMap.putLong("timestamp", System.currentTimeMillis());
dataMap.putLong("syncLogsRequested", syncLogsRequested);
sendData(path, dataMap.toByteArray());
}
use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class ListenerService method syncCalibrationData.
private synchronized void syncCalibrationData(DataMap dataMap, Context context) {
// KS
Log.d(TAG, "syncCalibrationData");
boolean changed = false;
ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
if (entries != null) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
Log.d(TAG, "syncCalibrationData add Calibration Table entries count=" + entries.size());
// ensure database has already been initialized
Sensor.InitDb(context);
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
for (DataMap entry : entries) {
if (entry != null) {
// bgs should be refactored to avoid confusion
String calibration = entry.getString("bgs");
if (calibration != null) {
Calibration bgData = gson.fromJson(calibration, Calibration.class);
Calibration exists = Calibration.findByUuid(bgData.uuid);
bgData.sensor = sensor;
if (exists != null) {
Log.d(TAG, "syncCalibrationData Calibration exists for uuid=" + bgData.uuid + " bg=" + bgData.bg + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
if (exists.slope != bgData.slope || exists.slope_confidence != bgData.slope_confidence || exists.timestamp != bgData.timestamp || exists.bg != bgData.bg) {
// slope* indicates if shown on graph
changed = true;
}
exists.adjusted_raw_value = bgData.adjusted_raw_value;
exists.bg = bgData.bg;
exists.check_in = bgData.check_in;
exists.distance_from_estimate = bgData.distance_from_estimate;
exists.estimate_bg_at_time_of_calibration = bgData.estimate_bg_at_time_of_calibration;
exists.estimate_raw_at_time_of_calibration = bgData.estimate_raw_at_time_of_calibration;
exists.first_decay = bgData.first_decay;
exists.first_intercept = bgData.first_intercept;
exists.first_scale = bgData.first_scale;
exists.first_slope = bgData.first_slope;
exists.intercept = bgData.intercept;
exists.possible_bad = bgData.possible_bad;
exists.raw_timestamp = bgData.raw_timestamp;
exists.raw_value = bgData.raw_value;
exists.second_decay = bgData.second_decay;
exists.second_intercept = bgData.second_intercept;
exists.second_scale = bgData.second_scale;
exists.second_slope = bgData.second_slope;
exists.sensor = sensor;
exists.sensor_age_at_time_of_estimation = bgData.sensor_age_at_time_of_estimation;
exists.sensor_confidence = bgData.sensor_confidence;
exists.sensor_uuid = bgData.sensor_uuid;
exists.slope = bgData.slope;
exists.slope_confidence = bgData.slope_confidence;
exists.timestamp = bgData.timestamp;
exists.save();
} else {
changed = true;
bgData.save();
// final boolean adjustPast = mPrefs.getBoolean("rewrite_history", true);
Log.d(TAG, "syncCalibrationData Calibration does not exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
// Calibration.adjustRecentBgReadings(adjustPast ? 30 : 2);
}
exists = Calibration.findByUuid(bgData.uuid);
if (exists != null)
Log.d(TAG, "syncCalibrationData Calibration GSON saved BG: " + exists.toS());
else
Log.d(TAG, "syncCalibrationData Calibration GSON NOT saved");
}
}
}
} else {
Log.d(TAG, "syncCalibrationData No Active Sensor!! Request WEARABLE_INITDB_PATH");
sendData(WEARABLE_INITDB_PATH, null);
}
if (changed) {
showTreatments(context, "cals");
}
}
}
use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class ListenerService method getWearLogData.
private synchronized DataMap getWearLogData(int count, long last_send_time, int min_count, long syncLogsRequested) {
forceGoogleApiConnect();
// FORCE ALWAYS SEND // TODO revisit this
min_count = 0;
Log.d(TAG, "getWearLogData last_send_time:" + JoH.dateTimeText(last_send_time) + " max count=" + count + " min_count=" + min_count + " syncLogsRequested=" + syncLogsRequested);
UserError last_log = UserError.last();
if (last_log != null) {
Log.d(TAG, "getWearLogData last_log.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
}
if (last_log != null && last_send_time <= last_log.timestamp) {
// startTime
long last_send_success = last_send_time;
Log.d(TAG, "getWearLogData last_send_time < last_bg.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
List<UserError> logs = UserError.latestAsc(count, last_send_time);
if (!logs.isEmpty() && logs.size() > min_count) {
// Log.d(TAG, "getWearLogData count = " + logs.size());
DataMap entries = dataMap(last_log);
final ArrayList<DataMap> dataMaps = new ArrayList<>(logs.size());
for (UserError log : logs) {
dataMaps.add(dataMap(log));
last_send_success = (long) log.timestamp;
// Log.d(TAG, "getWearLogData set last_send_sucess:" + JoH.dateTimeText(last_send_sucess) + " Log:" + log.toString());
}
// MOST IMPORTANT LINE FOR TIMESTAMP
entries.putLong("time", new Date().getTime());
entries.putLong("syncLogsRequested", syncLogsRequested);
entries.putDataMapArrayList("entries", dataMaps);
Log.i(TAG, "getWearLogData SYNCED logs up to " + JoH.dateTimeText(last_send_success) + " count = " + logs.size() + " syncLogsRequested=" + syncLogsRequested);
return entries;
} else
Log.i(TAG, "getWearLogData SYNCED logs up to " + JoH.dateTimeText(last_send_success) + " count = 0" + " syncLogsRequested=" + syncLogsRequested);
}
return null;
}
Aggregations