Merge pull request #907 from TebbeUbben/dev
Compatiblity for SR 1.5.8 and add 0%-TBR to history when pump has been paused or stopped
This commit is contained in:
commit
a3463841a9
Binary file not shown.
|
@ -18,6 +18,7 @@
|
|||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="sugar.free.sightremote.HISTORY_BROADCASTS" />
|
||||
|
||||
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
|
||||
|
|
|
@ -161,19 +161,55 @@ 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;
|
||||
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", MainApp.instance().getString(getAlertText(alertType)));
|
||||
data.put("notes", note);
|
||||
NSUpload.uploadCareportalEntryToNS(data);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getAlertText(String type) {
|
||||
if (type.equals("Error6MechanicalError")) return R.string.alert_e6;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -735,4 +735,7 @@
|
|||
<string name="combo_suspious_bolus_time">Zeit/Datum des abgegebenen Boluses auf der Pumpe erscheint falsch, IOB ist wahrscheinlich nicht korrekt. Bitte prüfe Zeit/Datum der Pumpe.</string>
|
||||
<string name="combo_tbr_count">Anzahl TBRs</string>
|
||||
<string name="combo_bolus_count">Anzahl Boluse</string>
|
||||
<string name="pump_stopped">Pumpe gestoppt</string>
|
||||
<string name="pump_started">Pumpe gestartet</string>
|
||||
<string name="pump_paused">Pumpe pausiert</string>
|
||||
</resources>
|
||||
|
|
|
@ -999,6 +999,9 @@
|
|||
<string name="key_openapssmb_max_iob" translatable="false">openapsmb_max_iob</string>
|
||||
<string name="openapssmb_maxiob_title">Maximum total IOB OpenAPS can\'t go over [U]</string>
|
||||
<string name="openapssmb_maxiob_summary">This value is called Max IOB in OpenAPS context\nOpenAPS will not add more insulin if current IOB is greater than this value</string>
|
||||
<string name="pump_stopped">Pump stopped</string>
|
||||
<string name="pump_started">Pump started</string>
|
||||
<string name="pump_paused">Pump paused</string>
|
||||
<string name="absorption_cutoff_title">Meal max absorption time [h]</string>
|
||||
<string name="absorption_cutoff_summary">Time at which any meal is considered absorbed. Remaining carbs will be cut off.</string>
|
||||
<string name="time">Time</string>
|
||||
|
|
Loading…
Reference in a new issue