Search in sources :

Example 26 with Treatments

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;
}
Also used : ArrayList(java.util.ArrayList) Treatments(com.eveningoutpost.dexdrip.Models.Treatments) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap)

Aggregations

Treatments (com.eveningoutpost.dexdrip.Models.Treatments)26 ArrayList (java.util.ArrayList)12 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)8 DataMap (com.google.android.gms.wearable.DataMap)8 Date (java.util.Date)8 BloodTest (com.eveningoutpost.dexdrip.Models.BloodTest)6 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)6 IOException (java.io.IOException)6 URISyntaxException (java.net.URISyntaxException)6 JSONException (org.json.JSONException)6 MongoClientURI (com.mongodb.MongoClientURI)4 ResponseBody (com.squareup.okhttp.ResponseBody)4 URI (java.net.URI)4 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)4 PowerManager (android.os.PowerManager)2 ListAdapter (android.widget.ListAdapter)2 AddCalibration (com.eveningoutpost.dexdrip.AddCalibration)2 InfluxDBUploader (com.eveningoutpost.dexdrip.InfluxDB.InfluxDBUploader)2 Forecast (com.eveningoutpost.dexdrip.Models.Forecast)2