diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 7c7b373414..aa7de54dff 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -1230,6 +1230,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleCareportalEventChange(); } + public CareportalEvent getCareportalEventFromTimestamp(long timestamp) { + try { + return getDaoCareportalEvents().queryForId(timestamp); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + @Nullable public CareportalEvent getLastCareportalEvent(String event) { try { 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 7ca901f81d..1ddc4fd4b7 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 @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.PumpInsight.history; import android.content.Intent; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.TDD; import info.nightscout.utils.DateUtil; @@ -141,8 +142,7 @@ class HistoryIntentAdapter { private void uploadCareportalEvent(Date date, String event) { if (SP.getBoolean("insight_automatic_careportal_events", false)) { - CareportalEvent careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(event); - if (careportalEvent == null || careportalEvent.date == date.getTime()) return; + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null) return; try { JSONObject data = new JSONObject(); String enteredBy = SP.getString("careportal_enteredby", ""); @@ -155,4 +155,49 @@ class HistoryIntentAdapter { } } } + + void processOccurenceOfAlertIntent(Intent intent) { + if (SP.getBoolean("insight_automatic_careportal_events", false)) { + 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(); + } + } + } + + private int getAlertText(String type) { + if (type.equals("Error6MechanicalError")) return R.string.alert_e6; + if (type.equals("Error7ElectronicError")) return R.string.alert_e7; + if (type.equals("Error10RewindError")) return R.string.alert_e10; + if (type.equals("Error13LanguageError")) return R.string.alert_e13; + if (type.equals("Maintenance20CartridgeNotInserted")) return R.string.alert_m20; + if (type.equals("Maintenance21CartridgeEmpty")) return R.string.alert_m21; + if (type.equals("Maintenance22BatteryEmpty")) return R.string.alert_m22; + if (type.equals("Maintenance23AutomaticOff")) return R.string.alert_m23; + if (type.equals("Maintenance24Occlusion")) return R.string.alert_m24; + if (type.equals("Maintenance25LoantimeOver")) return R.string.alert_m25; + if (type.equals("Maintenance26CartridgeChangeNotCompleted")) return R.string.alert_m26; + if (type.equals("Maintenance27DataDownloadFailed")) return R.string.alert_m27; + if (type.equals("Maintenance28PauseModeTimeout")) return R.string.alert_m28; + if (type.equals("Maintenance29BatteryTypeNotSet")) return R.string.alert_m29; + if (type.equals("Maintenance30CartridgeTypeNotSet")) return R.string.alert_m30; + if (type.equals("Warning31CartridgeLow")) return R.string.alert_w31; + if (type.equals("Warning32BatteryLow")) return R.string.alert_w32; + if (type.equals("Warning33InvalidDateTime")) return R.string.alert_w33; + if (type.equals("Warning34EndOfWarranty")) return R.string.alert_w34; + if (type.equals("Warning36TBRCancelled")) return R.string.alert_w36; + if (type.equals("Warning38BolusCancelled")) return R.string.alert_w38; + if (type.equals("Warning39LoantimeWarning")) return R.string.alert_w39; + return 0; + } } 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 b1eb736f40..2af6af864e 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 @@ -104,6 +104,9 @@ public class HistoryReceiver { case ACTION_BATTERY_INSERTED: intentAdapter.processBatteryInsertedIntent(intent); break; + case ACTION_OCCURENCE_OF_ALERT: + intentAdapter.processOccurenceOfAlertIntent(intent); + break; } } }; diff --git a/app/src/main/res/values-de/alerts.xml b/app/src/main/res/values-de/alerts.xml new file mode 100644 index 0000000000..886122994d --- /dev/null +++ b/app/src/main/res/values-de/alerts.xml @@ -0,0 +1,27 @@ + + + Warnung W31: Ampulle fast leer + Warnung W32: Batterie fast leer + Warnung W33: Zeit/Datum ungültig + Warnung W34: Garantie abgelaufen + Warnung W36: TBR abgebrochen + Warnung W38: Bolus abgebrochen + Warnung W39: Leihdauer-Warnung + + Wartung M20: Keine Ampulle eingesetzt + Wartung M21: Ampulle leer + Wartung M22: Batterie leer + Wartung M23: Sicherheitsabschaltung + Wartung M24: Verstopfung + Wartung M25: Leihdauer abgelaufen + Wartung M26: Ampullenwechsel nicht abgeschlossen + Wartung M27: Datenübertragung fehlgeschlagen + Wartung M28: Zeitüberschreitung bei Pause + Wartung M29: Batterietyp nicht eingestellt + Wartung M30: Ampullentyp nicht eingestellt + + Fehler E6: Mechanikfehler + Fehler E7: Elektronikfehler + Fehler E10: Fehler beim Zurückfahren + Fehler E13: Fehler in der Sprachanzeige + \ No newline at end of file diff --git a/app/src/main/res/values/alerts.xml b/app/src/main/res/values/alerts.xml new file mode 100644 index 0000000000..d78c448898 --- /dev/null +++ b/app/src/main/res/values/alerts.xml @@ -0,0 +1,27 @@ + + + Warning W31: Cartridge low + Warning W32: Battery low + Warning W33: Invalid time/date + Warning W34: End of warranty + Warning W36: TBR cancelled + Warning W38: Bolus canelled + Warning W39: Loantime warning + + Maintenance M20: Cartridge not inserted + Maintenance M21: Cartridge empty + Maintenance M22: Battery empty + Maintenance M23: Automatic off + Maintenance M24: Occlusion + Maintenance M25: Loantime over - end of operation + Maintenance M26: Cartridge change not completed + Maintenance M27: Data download failed + Maintenance M28: Pause mode timeout + Maintenance M29: Battery type not set + Maintenance M30: Cartridge type not set + + Error E6: Mechanical error + Error E7: Electronic error + Error E10: Rewind error + Error E13: Language error + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6f65ca4af5..a0f5def32d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -989,4 +989,6 @@ IobCobCalculator Waiting for time synchronization (%d sec) Disconnected (%d m) + Automatic careportal events + Automatically upload insulin, cannula and battery changes to Nightscout diff --git a/app/src/main/res/xml/pref_insightpump.xml b/app/src/main/res/xml/pref_insightpump.xml index 93d51f1318..662a6fec0f 100644 --- a/app/src/main/res/xml/pref_insightpump.xml +++ b/app/src/main/res/xml/pref_insightpump.xml @@ -16,7 +16,7 @@ android:summary="@string/automatically_connect_when"/> - \ No newline at end of file + android:key="insight_automatic_careportal_events" + android:title="@string/automatic_careportal_events" + android:summary="@string/automatically_upload_insulin_cannula_and_battery_changes_to_nightscout"/> + \ No newline at end of file