diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index ffbfb4b01c..2422e4ade6 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -169,7 +169,7 @@ public class MainApp extends Application { else Answers.getInstance().logCustom(new CustomEvent("AppStart")); - new Thread(new Runnable() { + new Thread(new Runnable() { @Override public void run() { SystemClock.sleep(5000); diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 540df96fe8..c8d8dbe808 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -228,6 +228,9 @@ public class DataService extends IntentService { if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { NSUpload.uploadBg(bgReading); } + if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } } } catch (JSONException e) { diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 5b2db2c912..ea662e434d 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -159,12 +159,16 @@ public class Profile { LongSparseArray sparse = new LongSparseArray<>(); for (Integer index = 0; index < array.length(); index++) { try { - JSONObject o = array.getJSONObject(index); + final JSONObject o = array.getJSONObject(index); long tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds")); Double value = o.getDouble("value") * multiplier; sparse.put(tas, value); } catch (JSONException e) { log.error("Unhandled exception", e); + try { + log.error(array.getJSONObject(index).toString()); + } catch (JSONException e1) { + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java index ce18c32734..1ce92249f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java @@ -69,11 +69,6 @@ public class NotificationStore { } } - WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class); - if (wearPlugin != null && wearPlugin.isEnabled()) { - wearPlugin.overviewNotification(n.id, "OverviewNotification:\n" + n.text); - } - Collections.sort(store, new NotificationComparator()); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index f927c107f1..a30e237672 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -185,7 +185,7 @@ public class DanaRSService extends Service { while (!msg.done && bleComm.isConnected()) { SystemClock.sleep(100); } - lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded; + lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded - 45 * 60 * 1000L; // always load last 45 min log.debug("Events loaded"); return new PumpEnactResult().success(true); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 2020e6d14d..4e5b85177a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -527,7 +527,7 @@ public class DanaRv2ExecutionService extends Service { waitMsec(100); } waitMsec(200); - lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded; + lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - 45 * 60 * 1000L; //always load last 45 min; return new PumpEnactResult().success(true); } diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index d6e8254cd6..f115358703 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -3,33 +3,37 @@ package info.nightscout.utils; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ResolveInfo; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; +import java.util.Locale; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.DeviceStatus; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger; -import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA; import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResultMA; @@ -449,4 +453,44 @@ public class NSUpload { } + public static void sendToXdrip(BgReading bgReading) { + final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); + + try { + final JSONArray entriesBody = new JSONArray(); + JSONObject json = new JSONObject(); + json.put("sgv", bgReading.value); + if (bgReading.direction == null) { + json.put("direction", "NONE"); + } else { + json.put("direction", bgReading.direction); + } + json.put("device", "G5"); + json.put("type", "sgv"); + json.put("date", bgReading.date); + json.put("dateString", format.format(bgReading.date)); + entriesBody.put(json); + + final Bundle bundle = new Bundle(); + bundle.putString("action", "add"); + bundle.putString("collection", "entries"); + bundle.putString("data", entriesBody.toString()); + final Intent intent = new Intent(XDRIP_PLUS_NS_EMULATOR); + intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + MainApp.instance().sendBroadcast(intent); + List receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0); + if (receivers.size() < 1) { + log.debug("No xDrip receivers found. "); + } else { + log.debug(receivers.size() + " xDrip receivers"); + } + + + } catch (JSONException e) { + e.printStackTrace(); + } + + } + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 61a9abb50d..a25ef122b7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -787,6 +787,9 @@ Show detailed delta Show delta with one more decimal place Unsupported pump firmware + Send BG data to xDrip+ + dexcomg5_xdripupload + In xDrip+ select 640g/Eversense data source Stopping bolus delivery Bolus delivery stopped Programming pump for bolusing diff --git a/app/src/main/res/xml/pref_dexcomg5.xml b/app/src/main/res/xml/pref_dexcomg5.xml index 75631b3b85..03c49bf624 100644 --- a/app/src/main/res/xml/pref_dexcomg5.xml +++ b/app/src/main/res/xml/pref_dexcomg5.xml @@ -9,6 +9,12 @@ android:key="@string/key_dexcomg5_nsupload" android:title="@string/dexcomg5_nsupload_title" /> + + \ No newline at end of file