diff --git a/app/libs/sightparser-release.aar b/app/libs/sightparser-release.aar index 4e474e608e..0d656738d2 100644 Binary files a/app/libs/sightparser-release.aar and b/app/libs/sightparser-release.aar differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 00d59f09bb..e8ed6a2f7f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,6 +18,7 @@ + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java index 1ddc4fd4b7..c3cab11772 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java @@ -161,18 +161,54 @@ class HistoryIntentAdapter { Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME); String alertType = intent.getStringExtra(HistoryBroadcast.EXTRA_ALERT_TYPE); if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null) return; - try { - JSONObject data = new JSONObject(); - String enteredBy = SP.getString("careportal_enteredby", ""); - if (!enteredBy.equals("")) data.put("enteredBy", enteredBy); - data.put("created_at", DateUtil.toISOString(date)); - data.put("eventType", CareportalEvent.NOTE); - data.put("notes", MainApp.instance().getString(getAlertText(alertType))); - NSUpload.uploadCareportalEntryToNS(data); - } catch (JSONException e) { - e.printStackTrace(); + logNote(date, MainApp.instance().getString(getAlertText(alertType))); + } + } + + void processPumpStatusChangedIntent(Intent intent) { + Date newStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME); + if (SP.getBoolean("insight_automatic_careportal_events", false)) { + String newStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_NEW_STATUS); + switch (newStatus) { + case "STARTED": + logNote(newStatusTime, MainApp.instance().getString(R.string.pump_started)); + break; + case "STOPPED": + logNote(newStatusTime, MainApp.instance().getString(R.string.pump_stopped)); + break; + case "PAUSED": + logNote(newStatusTime, MainApp.instance().getString(R.string.pump_paused)); + break; } } + if (intent.hasExtra(HistoryBroadcast.EXTRA_OLD_STATUS_TIME)) { + String oldStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_OLD_STATUS); + if (oldStatus.equals("STOPPED") ||oldStatus.equals("PAUSED")) { + Date oldStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_OLD_STATUS_TIME); + int duration = (int) ((newStatusTime.getTime() - oldStatusTime.getTime()) / 60000); + + long serialNumber = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER)); + long recordId = intent.getLongExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1); + long uniqueRecordId = getRecordUniqueID(serialNumber, recordId); + + logAdapter.createTBRrecord(oldStatusTime, 0, duration, uniqueRecordId); + } + } + } + + private void logNote(Date date, String note) { + try { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null) return; + JSONObject data = new JSONObject(); + String enteredBy = SP.getString("careportal_enteredby", ""); + if (!enteredBy.equals("")) data.put("enteredBy", enteredBy); + data.put("created_at", DateUtil.toISOString(date)); + data.put("eventType", CareportalEvent.NOTE); + data.put("notes", note); + NSUpload.uploadCareportalEntryToNS(data); + } catch (JSONException e) { + e.printStackTrace(); + } } private int getAlertText(String type) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java index 0e254e3341..efce8d7a40 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java @@ -47,6 +47,7 @@ public class HistoryReceiver { filter.addAction(ACTION_CARTRIDGE_INSERTED); filter.addAction(ACTION_BATTERY_INSERTED); filter.addAction(ACTION_OCCURENCE_OF_ALERT); + filter.addAction(ACTION_PUMP_STATUS_CHANGED); MainApp.instance().registerReceiver(historyReceiver, filter); } @@ -108,6 +109,9 @@ public class HistoryReceiver { case ACTION_OCCURENCE_OF_ALERT: intentAdapter.processOccurenceOfAlertIntent(intent); break; + case ACTION_PUMP_STATUS_CHANGED: + intentAdapter.processPumpStatusChangedIntent(intent); + break; } } }; diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a07ec4b40c..2f51b46c1f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -735,4 +735,7 @@ Zeit/Datum des abgegebenen Boluses auf der Pumpe erscheint falsch, IOB ist wahrscheinlich nicht korrekt. Bitte prüfe Zeit/Datum der Pumpe. Anzahl TBRs Anzahl Boluse + Pumpe gestoppt + Pumpe gestartet + Pumpe pausiert diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b368e5336f..cce0d0d716 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -999,6 +999,9 @@ openapsmb_max_iob Maximum total IOB OpenAPS can\'t go over [U] This value is called Max IOB in OpenAPS context\nOpenAPS will not add more insulin if current IOB is greater than this value + Pump stopped + Pump started + Pump paused Meal max absorption time [h] Time at which any meal is considered absorbed. Remaining carbs will be cut off. Time