use of com.eveningoutpost.dexdrip.Models.Treatments in project xDrip-plus by jamorham.
the class WatchUpdaterService method sendWearTreatmentsData.
public static boolean sendWearTreatmentsData(Integer count, long startTime, List<Treatments> list) {
try {
if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
googleApiClient.connect();
}
if (googleApiClient != null) {
Treatments last = list != null && list.size() > 0 ? list.get(0) : Treatments.last();
if (last != null) {
Log.d(TAG, "sendWearTreatmentsData last.timestamp:" + JoH.dateTimeText(last.timestamp));
} else {
Log.d(TAG, "sendWearTreatmentsData no treatments exist");
return true;
}
List<Treatments> graph;
if (list != null)
graph = list;
else if (startTime == 0)
graph = Treatments.latest(count);
else
graph = Treatments.latestForGraph(count, startTime);
if (!graph.isEmpty()) {
Log.d(TAG, "sendWearTreatmentsData graph size=" + graph.size());
final ArrayList<DataMap> dataMaps = new ArrayList<>(graph.size());
DataMap entries = dataMap(last);
for (Treatments data : graph) {
dataMaps.add(dataMap(data));
}
Log.d(TAG, "sendWearTreatmentsData entries=" + entries);
// MOST IMPORTANT LINE FOR TIMESTAMP
entries.putLong("time", new Date().getTime());
entries.putString("action", "insert");
entries.putDataMapArrayList("entries", dataMaps);
new SendToDataLayerThread(WEARABLE_TREATMENTS_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
} else
Log.d(TAG, "sendWearTreatmentsData treatments count = 0");
} else {
Log.e(TAG, "sendWearTreatmentsData No connection to wearable available for send treatment!");
return false;
}
} catch (NullPointerException e) {
Log.e(TAG, "Nullpointer exception in sendWearTreatmentsData: " + e);
return false;
}
return true;
}
Aggregations