commit
2a62b47be7
341 changed files with 14066 additions and 3985 deletions
|
@ -43,10 +43,15 @@ android {
|
||||||
applicationId "info.nightscout.androidaps"
|
applicationId "info.nightscout.androidaps"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
|
multiDexEnabled true
|
||||||
versionCode 1500
|
versionCode 1500
|
||||||
version "1.53"
|
version "1.55"
|
||||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||||
buildConfigField "String", "BUILDVERSION", generateGitBuild()
|
buildConfigField "String", "BUILDVERSION", generateGitBuild()
|
||||||
|
|
||||||
|
ndk {
|
||||||
|
moduleName "BleCommandUtil"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lintOptions {
|
lintOptions {
|
||||||
disable 'MissingTranslation'
|
disable 'MissingTranslation'
|
||||||
|
@ -58,7 +63,7 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
productFlavors {
|
productFlavors {
|
||||||
flavorDimensions "standard", "wear"
|
flavorDimensions "standard"
|
||||||
full {
|
full {
|
||||||
dimension "standard"
|
dimension "standard"
|
||||||
resValue "string", "app_name", "AndroidAPS"
|
resValue "string", "app_name", "AndroidAPS"
|
||||||
|
@ -107,22 +112,6 @@ android {
|
||||||
buildConfigField "boolean", "NSCLIENTOLNY", "true"
|
buildConfigField "boolean", "NSCLIENTOLNY", "true"
|
||||||
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||||
}
|
}
|
||||||
wear {
|
|
||||||
dimension "wear"
|
|
||||||
buildConfigField "boolean", "WEAR", "true"
|
|
||||||
buildConfigField "boolean", "WEAR_CONTROL", "false"
|
|
||||||
|
|
||||||
}
|
|
||||||
wearcontrol {
|
|
||||||
dimension "wear"
|
|
||||||
buildConfigField "boolean", "WEAR", "true"
|
|
||||||
buildConfigField "boolean", "WEAR_CONTROL", "true"
|
|
||||||
}
|
|
||||||
nowear {
|
|
||||||
dimension "wear"
|
|
||||||
buildConfigField "boolean", "WEAR", "false"
|
|
||||||
buildConfigField "boolean", "WEAR_CONTROL", "false"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,8 +125,7 @@ allprojects {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
wearWearApp project(path: ':wear', configuration: 'restrictedRelease')
|
wearApp project(':wear')
|
||||||
wearcontrolWearApp project(path: ':wear', configuration: 'fullRelease')
|
|
||||||
|
|
||||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
|
compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
|
||||||
|
@ -161,9 +149,9 @@ dependencies {
|
||||||
compile('com.github.tony19:logback-android-classic:1.1.1-6') {
|
compile('com.github.tony19:logback-android-classic:1.1.1-6') {
|
||||||
exclude group: 'com.google.android', module: 'android'
|
exclude group: 'com.google.android', module: 'android'
|
||||||
}
|
}
|
||||||
|
compile 'org.apache.commons:commons-lang3:3.6'
|
||||||
compile 'org.slf4j:slf4j-api:1.7.12'
|
compile 'org.slf4j:slf4j-api:1.7.12'
|
||||||
compile 'com.jjoe64:graphview:4.0.1'
|
compile 'com.jjoe64:graphview:4.0.1'
|
||||||
compile 'com.eclipsesource.j2v8:j2v8:3.1.6@aar'
|
|
||||||
compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.1.1'
|
compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.1.1'
|
||||||
compile 'com.google.android.gms:play-services-wearable:7.5.0'
|
compile 'com.google.android.gms:play-services-wearable:7.5.0'
|
||||||
compile 'junit:junit:4.12'
|
compile 'junit:junit:4.12'
|
||||||
|
|
BIN
app/libs/rhino-1.7.7.2.jar
Normal file
BIN
app/libs/rhino-1.7.7.2.jar
Normal file
Binary file not shown.
|
@ -17,6 +17,7 @@
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
|
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
|
||||||
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
|
|
||||||
|
@ -50,6 +51,13 @@
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity android:name=".plugins.PumpDanaRS.activities.BLEScanActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="info.nightscout.androidaps.plugins.PumpDanaRS.activities.BLEScanActivity" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity android:name=".plugins.PumpDanaRS.activities.PairingHelperActivity" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".receivers.DataReceiver"
|
android:name=".receivers.DataReceiver"
|
||||||
|
@ -113,6 +121,10 @@
|
||||||
android:name=".plugins.PumpDanaRv2.services.DanaRv2ExecutionService"
|
android:name=".plugins.PumpDanaRv2.services.DanaRv2ExecutionService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
<service
|
||||||
|
android:name=".plugins.PumpDanaRS.services.DanaRSService"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true"></service>
|
||||||
<service
|
<service
|
||||||
android:name=".plugins.Wear.wearintegration.WatchUpdaterService"
|
android:name=".plugins.Wear.wearintegration.WatchUpdaterService"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
|
|
12
app/src/main/assets/OpenAPSAMA/loggerhelper.js
Normal file
12
app/src/main/assets/OpenAPSAMA/loggerhelper.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
var console = { };
|
||||||
|
console.error = function error(){
|
||||||
|
for (var i = 0, len = arguments.length; i < len; i++) {
|
||||||
|
console2.log(arguments[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log = function log(){
|
||||||
|
for (var i = 0, len = arguments.length; i < len; i++) {
|
||||||
|
console2.log(arguments[i]);
|
||||||
|
}
|
||||||
|
};
|
120
app/src/main/java/com/cozmo/danar/util/BleCommandUtil.java
Normal file
120
app/src/main/java/com/cozmo/danar/util/BleCommandUtil.java
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
package com.cozmo.danar.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
|
||||||
|
public class BleCommandUtil {
|
||||||
|
public static final int DANAR_PACKET__TYPE_ENCRYPTION_REQUEST = 0x01;
|
||||||
|
public static final int DANAR_PACKET__TYPE_ENCRYPTION_RESPONSE = 0x02;
|
||||||
|
public static final int DANAR_PACKET__TYPE_COMMAND = 0xA1;
|
||||||
|
public static final int DANAR_PACKET__TYPE_RESPONSE = 0xB2;
|
||||||
|
public static final int DANAR_PACKET__TYPE_NOTIFY = 0xC3;
|
||||||
|
|
||||||
|
public static final int DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK = 0x00;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY = 0xD0;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST = 0xD1;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_RETURN = 0xD2;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION = 0x01;
|
||||||
|
|
||||||
|
public static final int DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_COMPLETE = 0x01;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_RATE_DISPLAY = 0x02;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_NOTIFY__ALARM = 0x03;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_NOTIFY__MISSED_BOLUS_ALARM = 0x04;
|
||||||
|
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__INITIAL_SCREEN_INFORMATION = 0x02;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__DELIVERY_STATUS = 0x03;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__GET_PASSWORD = 0x04;
|
||||||
|
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__BOLUS_AVG = 0x10;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__BOLUS = 0x11;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__DAILY = 0x12;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__PRIME = 0x13;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__REFILL = 0x14;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE = 0x15;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE = 0x16;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__TEMPORARY = 0x17;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__SUSPEND = 0x18;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__ALARM = 0x19;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__BASAL = 0x1A;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY = 0x1F;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__GET_SHIPPING_INFORMATION = 0x20;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_CHECK = 0x21;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__GET_USER_TIME_CHANGE_FLAG = 0x22;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__SET_USER_TIME_CHANGE_FLAG_CLEAR = 0x23;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__GET_MORE_INFORMATION = 0x24;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__SET_HISTORY_UPLOAD_MODE = 0x25;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_REVIEW__GET_TODAY_DELIVERY_TOTAL = 0x26;
|
||||||
|
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_STEP_BOLUS_INFORMATION = 0x40;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS_STATE = 0x41;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS = 0x42;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_DUAL_BOLUS = 0x43;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_STOP = 0x44;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION = 0x45;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_MENU_OPTION_STATE = 0x46;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS = 0x47;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__SET_DUAL_BOLUS = 0x48;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS_CANCEL = 0x49;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START = 0x4A;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_CALCULATION_INFORMATION = 0x4B;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_RATE = 0x4C;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_RATE = 0x4D;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_CIR_CF_ARRAY = 0x4E;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__SET_CIR_CF_ARRAY = 0x4F;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_OPTION = 0x50;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_OPTION = 0x51;
|
||||||
|
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__SET_TEMPORARY_BASAL = 0x60;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE = 0x61;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL = 0x62;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_NUMBER = 0x63;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_NUMBER = 0x64;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_BASAL_RATE = 0x65;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_BASAL_RATE = 0x66;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__GET_BASAL_RATE = 0x67;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__SET_BASAL_RATE = 0x68;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_ON = 0x69;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_OFF = 0x6A;
|
||||||
|
|
||||||
|
public static final int DANAR_PACKET__OPCODE_OPTION__GET_PUMP_TIME = 0x70;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_OPTION__SET_PUMP_TIME = 0x71;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_OPTION__GET_USER_OPTION = 0x72;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_OPTION__SET_USER_OPTION = 0x73;
|
||||||
|
|
||||||
|
public static final int DANAR_PACKET__OPCODE_BASAL__APS_SET_TEMPORARY_BASAL = 0xC1;
|
||||||
|
public static final int DANAR_PACKET__OPCODE__APS_HISTORY_EVENTS = 0xC2;
|
||||||
|
public static final int DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY = 0xC3;
|
||||||
|
|
||||||
|
public static final int DANAR_PACKET__OPCODE_ETC__SET_HISTORY_SAVE = 0xE0;
|
||||||
|
public static final int DANAR_PACKET__OPCODE_ETC__KEEP_CONNECTION = 0xFF;
|
||||||
|
|
||||||
|
static {
|
||||||
|
System.loadLibrary("BleCommandUtil");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native byte[] getEncryptedPacketJni(Object context, int opcode, byte[] bytes, String deviceName);
|
||||||
|
|
||||||
|
private static native byte[] getDecryptedPacketJni(Object context, byte[] bytes);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
|
private static BleCommandUtil mInstance = null;
|
||||||
|
|
||||||
|
public static BleCommandUtil getInstance() {
|
||||||
|
if (mInstance == null) {
|
||||||
|
mInstance = new BleCommandUtil();
|
||||||
|
}
|
||||||
|
return mInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
|
public byte[] getEncryptedPacket(int opcode, byte[] bytes, String deviceName) {
|
||||||
|
return getEncryptedPacketJni(MainApp.instance().getApplicationContext(), opcode, bytes, deviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getDecryptedPacket(byte[] bytes) {
|
||||||
|
return getDecryptedPacketJni(MainApp.instance().getApplicationContext(), bytes);
|
||||||
|
}
|
||||||
|
}
|
87
app/src/main/java/com/squareup/otto/LoggingBus.java
Normal file
87
app/src/main/java/com/squareup/otto/LoggingBus.java
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
package com.squareup.otto;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
|
/** Logs events has they're being posted to and dispatched from the event bus.
|
||||||
|
*
|
||||||
|
* A summary of event-receiver calls that occurred so far is logged
|
||||||
|
* after 10s (after startup) and then again every 60s.
|
||||||
|
* */
|
||||||
|
public class LoggingBus extends Bus {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(LoggingBus.class);
|
||||||
|
|
||||||
|
private static long everyMinute = System.currentTimeMillis() + 10 * 1000;
|
||||||
|
private Map<String, Set<String>> event2Receiver = new HashMap<>();
|
||||||
|
|
||||||
|
public LoggingBus(ThreadEnforcer enforcer) {
|
||||||
|
super(enforcer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void post(Object event) {
|
||||||
|
if (event instanceof DeadEvent) {
|
||||||
|
log.debug("Event has no receiver: " + ((DeadEvent) event).event + ", source: " + ((DeadEvent) event).source);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(event instanceof Event)) {
|
||||||
|
log.error("Posted event not an event class: " + event.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("<<< " + event);
|
||||||
|
try {
|
||||||
|
StackTraceElement caller = new Throwable().getStackTrace()[1];
|
||||||
|
String className = caller.getClassName();
|
||||||
|
className = className.substring(className.lastIndexOf(".") + 1);
|
||||||
|
log.debug(" source: " + className + "." + caller.getMethodName() + ":" + caller.getLineNumber());
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.debug(" source: <unknown>");
|
||||||
|
}
|
||||||
|
|
||||||
|
super.post(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void dispatch(Object event, EventHandler wrapper) {
|
||||||
|
try {
|
||||||
|
log.debug(">>> " + event);
|
||||||
|
Field methodField = wrapper.getClass().getDeclaredField("method");
|
||||||
|
methodField.setAccessible(true);
|
||||||
|
Method targetMethod = (Method) methodField.get(wrapper);
|
||||||
|
String className = targetMethod.getDeclaringClass().getSimpleName();
|
||||||
|
String methodName = targetMethod.getName();
|
||||||
|
String receiverMethod = className + "." + methodName;
|
||||||
|
log.debug(" receiver: " + receiverMethod);
|
||||||
|
|
||||||
|
String key = event.getClass().getSimpleName();
|
||||||
|
if (!event2Receiver.containsKey(key)) event2Receiver.put(key, new HashSet<String>());
|
||||||
|
event2Receiver.get(key).add(receiverMethod);
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
log.debug(" receiver: <unknown>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (everyMinute < System.currentTimeMillis()) {
|
||||||
|
log.debug("***************** Event -> receiver pairings seen so far ****************");
|
||||||
|
for (Map.Entry<String, Set<String>> stringSetEntry : event2Receiver.entrySet()) {
|
||||||
|
log.debug(" " + stringSetEntry.getKey());
|
||||||
|
for (String s : stringSetEntry.getValue()) {
|
||||||
|
log.debug(" -> " + s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.debug("*************************************************************************");
|
||||||
|
everyMinute = System.currentTimeMillis() + 60 * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.dispatch(event, wrapper);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,14 +9,9 @@ public class Config {
|
||||||
// MAIN FUCTIONALITY
|
// MAIN FUCTIONALITY
|
||||||
public static final boolean APS = BuildConfig.APS;
|
public static final boolean APS = BuildConfig.APS;
|
||||||
// PLUGINS
|
// PLUGINS
|
||||||
public static final boolean OPENAPSENABLED = APS;
|
|
||||||
public static final boolean LOOPENABLED = APS;
|
|
||||||
public static final boolean WEAR = BuildConfig.WEAR;
|
|
||||||
|
|
||||||
public static final boolean NSCLIENT = BuildConfig.NSCLIENTOLNY;
|
public static final boolean NSCLIENT = BuildConfig.NSCLIENTOLNY;
|
||||||
|
|
||||||
public static final boolean DANAR = true && BuildConfig.PUMPDRIVERS;
|
public static final boolean DANAR = true && BuildConfig.PUMPDRIVERS;
|
||||||
public static final boolean DANARv2 = true && BuildConfig.PUMPDRIVERS;
|
|
||||||
|
|
||||||
public static final boolean ACTION = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean ACTION = !BuildConfig.NSCLIENTOLNY;
|
||||||
public static final boolean VIRTUALPUMP = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean VIRTUALPUMP = !BuildConfig.NSCLIENTOLNY;
|
||||||
|
@ -27,8 +22,6 @@ public class Config {
|
||||||
public static final boolean SMSCOMMUNICATORENABLED = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean SMSCOMMUNICATORENABLED = !BuildConfig.NSCLIENTOLNY;
|
||||||
|
|
||||||
|
|
||||||
public static final boolean ALLPREFERENCES = !BuildConfig.NSCLIENTOLNY;
|
|
||||||
|
|
||||||
public static final boolean detailedLog = true;
|
public static final boolean detailedLog = true;
|
||||||
public static final boolean logFunctionCalls = true;
|
public static final boolean logFunctionCalls = true;
|
||||||
public static final boolean logIncommingData = true;
|
public static final boolean logIncommingData = true;
|
||||||
|
@ -40,10 +33,11 @@ public class Config {
|
||||||
public static final boolean logNSUpload = true;
|
public static final boolean logNSUpload = true;
|
||||||
public static final boolean logPumpActions = true;
|
public static final boolean logPumpActions = true;
|
||||||
public static final boolean logCongigBuilderActions = true;
|
public static final boolean logCongigBuilderActions = true;
|
||||||
public static final boolean logAutosensData = true;
|
public static final boolean logAutosensData = false;
|
||||||
|
public static final boolean logEvents = false;
|
||||||
|
|
||||||
// DanaR specific
|
// DanaR specific
|
||||||
public static final boolean logDanaBTComm = true;
|
public static final boolean logDanaBTComm = true;
|
||||||
public static final boolean logDanaMessageDetail = true;
|
public static boolean logDanaMessageDetail = true;
|
||||||
public static final boolean logDanaSerialEngine = true;
|
public static final boolean logDanaSerialEngine = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ public class Constants {
|
||||||
// Circadian Percentage Profile
|
// Circadian Percentage Profile
|
||||||
public static final int CPP_MIN_PERCENTAGE = 50;
|
public static final int CPP_MIN_PERCENTAGE = 50;
|
||||||
public static final int CPP_MAX_PERCENTAGE = 200;
|
public static final int CPP_MAX_PERCENTAGE = 200;
|
||||||
|
public static final int CPP_MIN_TIMESHIFT = -6;
|
||||||
|
public static final int CPP_MAX_TIMESHIFT = 23;
|
||||||
|
|
||||||
// Very Hard Limits Ranges
|
// Very Hard Limits Ranges
|
||||||
// First value is the Lowest and second value is the Highest a Limit can define
|
// First value is the Lowest and second value is the Highest a Limit can define
|
||||||
|
|
|
@ -58,8 +58,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
|
|
||||||
static final int CASE_STORAGE = 0x1;
|
static final int CASE_STORAGE = 0x1;
|
||||||
static final int CASE_SMS = 0x2;
|
static final int CASE_SMS = 0x2;
|
||||||
|
static final int CASE_LOCATION = 0x3;
|
||||||
|
|
||||||
private boolean askForSMS = false;
|
private boolean askForSMS = false;
|
||||||
|
private boolean askForLocation = true;
|
||||||
|
|
||||||
ImageButton menuButton;
|
ImageButton menuButton;
|
||||||
|
|
||||||
|
@ -202,6 +204,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
askForSMSPermissions();
|
askForSMSPermissions();
|
||||||
|
askForLocationPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -256,6 +259,17 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized void askForLocationPermissions() {
|
||||||
|
if (askForLocation) { //only when settings were changed an MainActivity resumes.
|
||||||
|
askForLocation = false;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
askForPermission(new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION}, CASE_LOCATION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void askForPermission(String[] permission, Integer requestCode) {
|
private void askForPermission(String[] permission, Integer requestCode) {
|
||||||
boolean test = false;
|
boolean test = false;
|
||||||
for (int i = 0; i < permission.length; i++) {
|
for (int i = 0; i < permission.length; i++) {
|
||||||
|
@ -279,6 +293,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
alert.setPositiveButton(R.string.ok, null);
|
alert.setPositiveButton(R.string.ok, null);
|
||||||
alert.show();
|
alert.show();
|
||||||
break;
|
break;
|
||||||
|
case CASE_LOCATION:
|
||||||
case CASE_SMS:
|
case CASE_SMS:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -321,6 +336,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Intent i = new Intent(v.getContext(), PreferencesActivity.class);
|
Intent i = new Intent(v.getContext(), PreferencesActivity.class);
|
||||||
|
i.putExtra("id", -1);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
|
import com.squareup.otto.LoggingBus;
|
||||||
import com.squareup.otto.ThreadEnforcer;
|
import com.squareup.otto.ThreadEnforcer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -26,32 +27,35 @@ import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesFragment;
|
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Food.FoodPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingPlugin;
|
import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingProlongedPlugin;
|
import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingProlongedPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
|
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin;
|
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefUltraRapidActingPlugin;
|
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefUltraRapidActingPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment;
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.receivers.AckAlarmReceiver;
|
import info.nightscout.androidaps.plugins.NSClientInternal.receivers.AckAlarmReceiver;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAFragment;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
|
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Persistentnotification.PersistentNotificationPlugin;
|
import info.nightscout.androidaps.plugins.Persistentnotification.PersistentNotificationPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfileFragment;
|
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfileFragment;
|
||||||
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
|
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfileFragment;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfileFragment;
|
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
||||||
import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin;
|
import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin;
|
||||||
|
@ -59,13 +63,13 @@ import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
||||||
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorFragment;
|
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Wear.WearFragment;
|
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||||
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
||||||
import info.nightscout.androidaps.receivers.DataReceiver;
|
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
||||||
|
@ -101,7 +105,8 @@ public class MainApp extends Application {
|
||||||
log.info("Version: " + BuildConfig.VERSION_NAME);
|
log.info("Version: " + BuildConfig.VERSION_NAME);
|
||||||
log.info("BuildVersion: " + BuildConfig.BUILDVERSION);
|
log.info("BuildVersion: " + BuildConfig.BUILDVERSION);
|
||||||
|
|
||||||
sBus = new Bus(ThreadEnforcer.ANY);
|
sBus = Config.logEvents ? new LoggingBus(ThreadEnforcer.ANY) : new Bus(ThreadEnforcer.ANY);
|
||||||
|
|
||||||
sInstance = this;
|
sInstance = this;
|
||||||
sResources = getResources();
|
sResources = getResources();
|
||||||
|
|
||||||
|
@ -110,7 +115,7 @@ public class MainApp extends Application {
|
||||||
if (pluginsList == null) {
|
if (pluginsList == null) {
|
||||||
pluginsList = new ArrayList<>();
|
pluginsList = new ArrayList<>();
|
||||||
// Register all tabs in app here
|
// Register all tabs in app here
|
||||||
pluginsList.add(OverviewFragment.getPlugin());
|
pluginsList.add(OverviewPlugin.getPlugin());
|
||||||
pluginsList.add(IobCobCalculatorPlugin.getPlugin());
|
pluginsList.add(IobCobCalculatorPlugin.getPlugin());
|
||||||
if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin());
|
if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin());
|
||||||
pluginsList.add(InsulinFastactingPlugin.getPlugin());
|
pluginsList.add(InsulinFastactingPlugin.getPlugin());
|
||||||
|
@ -123,21 +128,22 @@ public class MainApp extends Application {
|
||||||
pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin());
|
pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin());
|
||||||
if (Config.DANAR) pluginsList.add(DanaRPlugin.getPlugin());
|
if (Config.DANAR) pluginsList.add(DanaRPlugin.getPlugin());
|
||||||
if (Config.DANAR) pluginsList.add(DanaRKoreanPlugin.getPlugin());
|
if (Config.DANAR) pluginsList.add(DanaRKoreanPlugin.getPlugin());
|
||||||
if (Config.DANARv2) pluginsList.add(DanaRv2Plugin.getPlugin());
|
if (Config.DANAR) pluginsList.add(DanaRv2Plugin.getPlugin());
|
||||||
pluginsList.add(CareportalFragment.getPlugin());
|
//if (Config.DANAR) pluginsList.add(DanaRSPlugin.getPlugin());
|
||||||
|
pluginsList.add(CareportalPlugin.getPlugin());
|
||||||
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
|
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
|
||||||
if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance());
|
if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getPlugin());
|
||||||
if (Config.LOOPENABLED) pluginsList.add(LoopFragment.getPlugin());
|
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
|
||||||
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAFragment.getPlugin());
|
if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin());
|
||||||
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSAMAFragment.getPlugin());
|
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
||||||
pluginsList.add(NSProfileFragment.getPlugin());
|
pluginsList.add(NSProfilePlugin.getPlugin());
|
||||||
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfileFragment.getPlugin());
|
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin());
|
||||||
if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin());
|
if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin());
|
||||||
if (Config.OTHERPROFILES)
|
if (Config.OTHERPROFILES)
|
||||||
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
|
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
|
||||||
pluginsList.add(TreatmentsFragment.getPlugin());
|
pluginsList.add(TreatmentsPlugin.getPlugin());
|
||||||
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
||||||
if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin());
|
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT)
|
if (!Config.NSCLIENT)
|
||||||
pluginsList.add(SourceXdripPlugin.getPlugin());
|
pluginsList.add(SourceXdripPlugin.getPlugin());
|
||||||
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
||||||
|
@ -145,12 +151,13 @@ public class MainApp extends Application {
|
||||||
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT)
|
if (!Config.NSCLIENT)
|
||||||
pluginsList.add(SourceGlimpPlugin.getPlugin());
|
pluginsList.add(SourceGlimpPlugin.getPlugin());
|
||||||
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorFragment.getPlugin());
|
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
|
||||||
|
pluginsList.add(FoodPlugin.getPlugin());
|
||||||
|
|
||||||
if (Config.WEAR) pluginsList.add(WearFragment.getPlugin(this));
|
pluginsList.add(WearPlugin.initPlugin(this));
|
||||||
pluginsList.add(StatuslinePlugin.getPlugin(this));
|
pluginsList.add(StatuslinePlugin.initPlugin(this));
|
||||||
pluginsList.add(new PersistentNotificationPlugin(this));
|
pluginsList.add(new PersistentNotificationPlugin(this));
|
||||||
pluginsList.add(NSClientInternalFragment.getPlugin());
|
pluginsList.add(NSClientInternalPlugin.getPlugin());
|
||||||
|
|
||||||
pluginsList.add(sConfigBuilder = ConfigBuilderFragment.getPlugin());
|
pluginsList.add(sConfigBuilder = ConfigBuilderFragment.getPlugin());
|
||||||
|
|
||||||
|
@ -162,9 +169,6 @@ public class MainApp extends Application {
|
||||||
else
|
else
|
||||||
Answers.getInstance().logCustom(new CustomEvent("AppStart"));
|
Answers.getInstance().logCustom(new CustomEvent("AppStart"));
|
||||||
|
|
||||||
|
|
||||||
startKeepAliveService();
|
|
||||||
|
|
||||||
Thread t = new Thread(new Runnable() {
|
Thread t = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -172,8 +176,9 @@ public class MainApp extends Application {
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
PumpInterface pump = MainApp.getConfigBuilder();
|
||||||
if (pump != null)
|
if (pump != null)
|
||||||
pump.refreshDataFromPump("Initialization");
|
pump.refreshDataFromPump("Initialization");
|
||||||
|
startKeepAliveService();
|
||||||
}
|
}
|
||||||
});
|
}, "pump-initialization");
|
||||||
t.start();
|
t.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -183,6 +188,9 @@ public class MainApp extends Application {
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT));
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT));
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT));
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT));
|
||||||
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_FOOD));
|
||||||
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_FOOD));
|
||||||
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_FOOD));
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV));
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV));
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE));
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE));
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_STATUS));
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_STATUS));
|
||||||
|
@ -203,11 +211,6 @@ public class MainApp extends Application {
|
||||||
private void startKeepAliveService() {
|
private void startKeepAliveService() {
|
||||||
if (keepAliveReceiver == null) {
|
if (keepAliveReceiver == null) {
|
||||||
keepAliveReceiver = new KeepAliveReceiver();
|
keepAliveReceiver = new KeepAliveReceiver();
|
||||||
if (Config.DANAR) {
|
|
||||||
startService(new Intent(this, DanaRExecutionService.class));
|
|
||||||
startService(new Intent(this, DanaRKoreanExecutionService.class));
|
|
||||||
startService(new Intent(this, DanaRv2ExecutionService.class));
|
|
||||||
}
|
|
||||||
keepAliveReceiver.setAlarm(this);
|
keepAliveReceiver.setAlarm(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,17 +15,22 @@ import android.text.TextUtils;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
|
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.BluetoothDevicePreference;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||||
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
||||||
import info.nightscout.utils.LocaleHelper;
|
import info.nightscout.utils.LocaleHelper;
|
||||||
|
@ -39,6 +44,9 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
myPreferenceFragment = new MyPreferenceFragment();
|
myPreferenceFragment = new MyPreferenceFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putInt("id", getIntent().getIntExtra("id", -1));
|
||||||
|
myPreferenceFragment.setArguments(args);
|
||||||
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
|
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +70,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updatePrefSummary(Preference pref) {
|
private static void updatePrefSummary(Preference pref) {
|
||||||
if (pref instanceof ListPreference || pref instanceof BluetoothDevicePreference) {
|
if (pref instanceof ListPreference) {
|
||||||
ListPreference listPref = (ListPreference) pref;
|
ListPreference listPref = (ListPreference) pref;
|
||||||
pref.setSummary(listPref.getEntry());
|
pref.setSummary(listPref.getEntry());
|
||||||
}
|
}
|
||||||
|
@ -70,18 +78,15 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
EditTextPreference editTextPref = (EditTextPreference) pref;
|
EditTextPreference editTextPref = (EditTextPreference) pref;
|
||||||
if (pref.getKey().contains("password") || pref.getKey().contains("secret")) {
|
if (pref.getKey().contains("password") || pref.getKey().contains("secret")) {
|
||||||
pref.setSummary("******");
|
pref.setSummary("******");
|
||||||
|
} else if (pref.getKey().equals(MainApp.sResources.getString(R.string.key_danars_name))) {
|
||||||
|
pref.setSummary(SP.getString(R.string.key_danars_name, ""));
|
||||||
} else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) {
|
} else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) {
|
||||||
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
|
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
|
||||||
pref.setSummary(editTextPref.getText());
|
pref.setSummary(editTextPref.getText());
|
||||||
}
|
} else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().trim())) {
|
||||||
else if(pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().toString().trim())){
|
|
||||||
pref.setSummary(MainApp.sResources.getString(R.string.smscommunicator_allowednumbers_summary));
|
pref.setSummary(MainApp.sResources.getString(R.string.smscommunicator_allowednumbers_summary));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pref instanceof MultiSelectListPreference) {
|
|
||||||
EditTextPreference editTextPref = (EditTextPreference) pref;
|
|
||||||
pref.setSummary(editTextPref.getText());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initSummary(Preference p) {
|
public static void initSummary(Preference p) {
|
||||||
|
@ -96,85 +101,95 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MyPreferenceFragment extends PreferenceFragment {
|
public static class MyPreferenceFragment extends PreferenceFragment {
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setArguments(Bundle args) {
|
||||||
|
super.setArguments(args);
|
||||||
|
id = args.getInt("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
void addPreferencesFromResourceIfEnabled(PluginBase p, int type) {
|
||||||
|
if (p.isEnabled(type) && p.getPreferencesId() != -1)
|
||||||
|
addPreferencesFromResource(p.getPreferencesId());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (Config.ALLPREFERENCES) {
|
|
||||||
|
if (savedInstanceState != null && savedInstanceState.containsKey("id")) {
|
||||||
|
id = savedInstanceState.getInt("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id != -1) {
|
||||||
|
addPreferencesFromResource(id);
|
||||||
|
addPreferencesFromResource(R.xml.pref_advanced);
|
||||||
|
} else {
|
||||||
|
if (!Config.NSCLIENT) {
|
||||||
addPreferencesFromResource(R.xml.pref_password);
|
addPreferencesFromResource(R.xml.pref_password);
|
||||||
}
|
}
|
||||||
addPreferencesFromResource(R.xml.pref_age);
|
addPreferencesFromResource(R.xml.pref_age);
|
||||||
addPreferencesFromResource(R.xml.pref_language);
|
addPreferencesFromResource(R.xml.pref_language);
|
||||||
if (Config.ALLPREFERENCES) {
|
|
||||||
|
if (!Config.NSCLIENT) {
|
||||||
addPreferencesFromResource(R.xml.pref_quickwizard);
|
addPreferencesFromResource(R.xml.pref_quickwizard);
|
||||||
}
|
}
|
||||||
addPreferencesFromResource(R.xml.pref_careportal);
|
addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
if (Config.ALLPREFERENCES) {
|
addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginBase.CONSTRAINTS);
|
||||||
addPreferencesFromResource(R.xml.pref_treatments);
|
if (Config.APS) {
|
||||||
|
addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginBase.LOOP);
|
||||||
|
addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginBase.APS);
|
||||||
|
addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginBase.APS);
|
||||||
}
|
}
|
||||||
if (Config.APS)
|
|
||||||
addPreferencesFromResource(R.xml.pref_closedmode);
|
addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginBase.SENSITIVITY);
|
||||||
if (Config.OPENAPSENABLED) {
|
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginBase.SENSITIVITY);
|
||||||
addPreferencesFromResource(R.xml.pref_openapsma);
|
addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginBase.SENSITIVITY);
|
||||||
if (MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class) != null && MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class).isEnabled(PluginBase.APS))
|
|
||||||
addPreferencesFromResource(R.xml.pref_openapsama);
|
if (!Config.NSCLIENT) {
|
||||||
}
|
|
||||||
if (MainApp.getSpecificPlugin(SensitivityAAPSPlugin.class) != null && MainApp.getSpecificPlugin(SensitivityAAPSPlugin.class).isEnabled(PluginBase.SENSITIVITY)
|
|
||||||
|| MainApp.getSpecificPlugin(SensitivityWeightedAveragePlugin.class) != null && MainApp.getSpecificPlugin(SensitivityWeightedAveragePlugin.class).isEnabled(PluginBase.SENSITIVITY))
|
|
||||||
addPreferencesFromResource(R.xml.pref_absorption_aaps);
|
|
||||||
if (MainApp.getSpecificPlugin(SensitivityOref0Plugin.class) != null && MainApp.getSpecificPlugin(SensitivityOref0Plugin.class).isEnabled(PluginBase.SENSITIVITY))
|
|
||||||
addPreferencesFromResource(R.xml.pref_absorption_oref0);
|
|
||||||
if (Config.ALLPREFERENCES) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_profile);
|
addPreferencesFromResource(R.xml.pref_profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.DANAR) {
|
if (Config.DANAR) {
|
||||||
DanaRPlugin danaRPlugin = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
addPreferencesFromResourceIfEnabled(DanaRPlugin.getPlugin(), PluginBase.PUMP);
|
||||||
DanaRKoreanPlugin danaRKoreanPlugin = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
|
addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginBase.PUMP);
|
||||||
DanaRv2Plugin danaRv2Plugin = MainApp.getSpecificPlugin(DanaRv2Plugin.class);
|
addPreferencesFromResourceIfEnabled(DanaRv2Plugin.getPlugin(), PluginBase.PUMP);
|
||||||
if (danaRPlugin.isEnabled(PluginBase.PUMP) || danaRKoreanPlugin.isEnabled(PluginBase.PUMP)) {
|
addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginBase.PUMP);
|
||||||
addPreferencesFromResource(R.xml.pref_danar);
|
|
||||||
}
|
if (DanaRPlugin.getPlugin().isEnabled(PluginBase.PROFILE)
|
||||||
if (danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PUMP)) {
|
|| DanaRKoreanPlugin.getPlugin().isEnabled(PluginBase.PROFILE)
|
||||||
addPreferencesFromResource(R.xml.pref_danarv2);
|
|| DanaRv2Plugin.getPlugin().isEnabled(PluginBase.PROFILE)
|
||||||
}
|
|| DanaRSPlugin.getPlugin().isEnabled(PluginBase.PROFILE)) {
|
||||||
if (danaRPlugin.isEnabled(PluginBase.PROFILE) || danaRKoreanPlugin.isEnabled(PluginBase.PROFILE) || danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PROFILE)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_danarprofile);
|
addPreferencesFromResource(R.xml.pref_danarprofile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VirtualPumpPlugin virtualPumpPlugin = MainApp.getSpecificPlugin(VirtualPumpPlugin.class);
|
|
||||||
if (virtualPumpPlugin != null && virtualPumpPlugin.isEnabled(PluginBase.PUMP)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_virtualpump);
|
|
||||||
}
|
|
||||||
InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin = MainApp.getSpecificPlugin(InsulinOrefFreePeakPlugin.class);
|
|
||||||
if(insulinOrefFreePeakPlugin.isEnabled(PluginBase.INSULIN)){
|
|
||||||
addPreferencesFromResource(R.xml.pref_insulinoreffreepeak);
|
|
||||||
}
|
|
||||||
|
|
||||||
NSClientInternalPlugin nsClientInternalPlugin = MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
|
addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginBase.PUMP);
|
||||||
if (nsClientInternalPlugin != null && nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_nsclientinternal);
|
addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginBase.INSULIN);
|
||||||
}
|
|
||||||
if (Config.SMSCOMMUNICATORENABLED)
|
addPreferencesFromResourceIfEnabled(NSClientInternalPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
addPreferencesFromResource(R.xml.pref_smscommunicator);
|
addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
if (Config.ALLPREFERENCES) {
|
|
||||||
|
if (!Config.NSCLIENT) {
|
||||||
addPreferencesFromResource(R.xml.pref_others);
|
addPreferencesFromResource(R.xml.pref_others);
|
||||||
}
|
}
|
||||||
addPreferencesFromResource(R.xml.pref_advanced);
|
addPreferencesFromResource(R.xml.pref_advanced);
|
||||||
|
|
||||||
if (Config.WEAR) {
|
addPreferencesFromResourceIfEnabled(WearPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class);
|
addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
if (wearPlugin != null && wearPlugin.isEnabled(PluginBase.GENERAL)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_wear);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StatuslinePlugin statuslinePlugin = MainApp.getSpecificPlugin(StatuslinePlugin.class);
|
|
||||||
if (statuslinePlugin != null && statuslinePlugin.isEnabled(PluginBase.GENERAL)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_xdripstatus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initSummary(getPreferenceScreen());
|
initSummary(getPreferenceScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putInt("id", id);
|
||||||
|
}
|
||||||
|
|
||||||
public Preference getPreference(String key) {
|
public Preference getPreference(String key) {
|
||||||
return findPreference(key);
|
return findPreference(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,9 @@ public class DataService extends IntentService {
|
||||||
Intents.ACTION_REMOVED_TREATMENT.equals(action) ||
|
Intents.ACTION_REMOVED_TREATMENT.equals(action) ||
|
||||||
Intents.ACTION_NEW_STATUS.equals(action) ||
|
Intents.ACTION_NEW_STATUS.equals(action) ||
|
||||||
Intents.ACTION_NEW_DEVICESTATUS.equals(action) ||
|
Intents.ACTION_NEW_DEVICESTATUS.equals(action) ||
|
||||||
|
Intents.ACTION_NEW_FOOD.equals(action) ||
|
||||||
|
Intents.ACTION_CHANGED_FOOD.equals(action) ||
|
||||||
|
Intents.ACTION_REMOVED_FOOD.equals(action) ||
|
||||||
Intents.ACTION_NEW_CAL.equals(action) ||
|
Intents.ACTION_NEW_CAL.equals(action) ||
|
||||||
Intents.ACTION_NEW_MBG.equals(action))
|
Intents.ACTION_NEW_MBG.equals(action))
|
||||||
) {
|
) {
|
||||||
|
@ -316,28 +319,8 @@ public class DataService extends IntentService {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT)) {
|
|
||||||
try {
|
|
||||||
if (bundles.containsKey("treatment")) {
|
|
||||||
String trstring = bundles.getString("treatment");
|
|
||||||
handleAddChangeDataFromNS(trstring);
|
|
||||||
}
|
|
||||||
if (bundles.containsKey("treatments")) {
|
|
||||||
String trstring = bundles.getString("treatments");
|
|
||||||
JSONArray jsonArray = new JSONArray(trstring);
|
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
|
||||||
JSONObject trJson = jsonArray.getJSONObject(i);
|
|
||||||
String trstr = trJson.toString();
|
|
||||||
handleAddChangeDataFromNS(trstr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT) || intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) {
|
||||||
|
|
||||||
if (intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) {
|
|
||||||
try {
|
try {
|
||||||
if (bundles.containsKey("treatment")) {
|
if (bundles.containsKey("treatment")) {
|
||||||
String trstring = bundles.getString("treatment");
|
String trstring = bundles.getString("treatment");
|
||||||
|
@ -433,6 +416,56 @@ public class DataService extends IntentService {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (intent.getAction().equals(Intents.ACTION_NEW_FOOD) || intent.getAction().equals(Intents.ACTION_CHANGED_FOOD)) {
|
||||||
|
try {
|
||||||
|
if (bundles.containsKey("food")) {
|
||||||
|
String trstring = bundles.getString("food");
|
||||||
|
handleAddChangeFoodRecord(new JSONObject(trstring));
|
||||||
|
}
|
||||||
|
if (bundles.containsKey("foods")) {
|
||||||
|
String trstring = bundles.getString("foods");
|
||||||
|
JSONArray jsonArray = new JSONArray(trstring);
|
||||||
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
|
JSONObject trJson = jsonArray.getJSONObject(i);
|
||||||
|
handleAddChangeFoodRecord(trJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intent.getAction().equals(Intents.ACTION_REMOVED_FOOD)) {
|
||||||
|
try {
|
||||||
|
if (bundles.containsKey("food")) {
|
||||||
|
String trstring = bundles.getString("food");
|
||||||
|
JSONObject trJson = new JSONObject(trstring);
|
||||||
|
String _id = trJson.getString("_id");
|
||||||
|
handleRemovedFoodRecord(_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bundles.containsKey("foods")) {
|
||||||
|
String trstring = bundles.getString("foods");
|
||||||
|
JSONArray jsonArray = new JSONArray(trstring);
|
||||||
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
|
JSONObject trJson = jsonArray.getJSONObject(i);
|
||||||
|
String _id = trJson.getString("_id");
|
||||||
|
handleRemovedFoodRecord(_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleRemovedFoodRecord(String _id) {
|
||||||
|
MainApp.getDbHelper().foodHelper.deleteFoodById(_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleAddChangeFoodRecord(JSONObject trJson) throws JSONException {
|
||||||
|
MainApp.getDbHelper().foodHelper.createFoodFromJsonIfNotExists(trJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRemovedRecordFromNS(String _id) {
|
private void handleRemovedRecordFromNS(String _id) {
|
||||||
|
|
|
@ -8,6 +8,9 @@ public interface Intents {
|
||||||
String ACTION_NEW_PROFILE = "info.nightscout.client.NEW_PROFILE";
|
String ACTION_NEW_PROFILE = "info.nightscout.client.NEW_PROFILE";
|
||||||
String ACTION_NEW_SGV = "info.nightscout.client.NEW_SGV";
|
String ACTION_NEW_SGV = "info.nightscout.client.NEW_SGV";
|
||||||
String ACTION_NEW_DEVICESTATUS = "info.nightscout.client.NEW_DEVICESTATUS";
|
String ACTION_NEW_DEVICESTATUS = "info.nightscout.client.NEW_DEVICESTATUS";
|
||||||
|
String ACTION_NEW_FOOD = "info.nightscout.client.NEW_FOOD";
|
||||||
|
String ACTION_CHANGED_FOOD = "info.nightscout.client.CHANGED_FOOD";
|
||||||
|
String ACTION_REMOVED_FOOD = "info.nightscout.client.REMOVED_FOOD";
|
||||||
String ACTION_NEW_MBG = "info.nightscout.client.NEW_MBG";
|
String ACTION_NEW_MBG = "info.nightscout.client.NEW_MBG";
|
||||||
String ACTION_NEW_CAL = "info.nightscout.client.NEW_CAL";
|
String ACTION_NEW_CAL = "info.nightscout.client.NEW_CAL";
|
||||||
String ACTION_NEW_STATUS = "info.nightscout.client.NEW_STATUS";
|
String ACTION_NEW_STATUS = "info.nightscout.client.NEW_STATUS";
|
||||||
|
|
|
@ -29,4 +29,14 @@ public class DetailedBolusInfo {
|
||||||
public Context context = null; // context for progress dialog
|
public Context context = null; // context for progress dialog
|
||||||
public long pumpId = 0; // id of record if comming from pump history (not a newly created treatment)
|
public long pumpId = 0; // id of record if comming from pump history (not a newly created treatment)
|
||||||
public boolean isSMB = false; // is a Super-MicroBolus
|
public boolean isSMB = false; // is a Super-MicroBolus
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new Date(date).toLocaleString() +
|
||||||
|
" insulin: " + insulin +
|
||||||
|
" carbs: " + carbs +
|
||||||
|
" isValid: " + isValid +
|
||||||
|
" carbTime: " + carbTime +
|
||||||
|
" isSMB: " + isSMB;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
import info.nightscout.utils.SafeParse;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
|
||||||
public class Profile {
|
public class Profile {
|
||||||
|
@ -29,19 +30,24 @@ public class Profile {
|
||||||
|
|
||||||
private JSONObject json;
|
private JSONObject json;
|
||||||
private String units = null;
|
private String units = null;
|
||||||
double dia = Constants.defaultDIA;
|
private double dia = Constants.defaultDIA;
|
||||||
TimeZone timeZone = TimeZone.getDefault();
|
private TimeZone timeZone = TimeZone.getDefault();
|
||||||
JSONArray isf;
|
private JSONArray isf;
|
||||||
private LongSparseArray<Double> isf_v = null; // oldest at index 0
|
private LongSparseArray<Double> isf_v = null; // oldest at index 0
|
||||||
JSONArray ic;
|
private JSONArray ic;
|
||||||
private LongSparseArray<Double> ic_v = null; // oldest at index 0
|
private LongSparseArray<Double> ic_v = null; // oldest at index 0
|
||||||
JSONArray basal;
|
private JSONArray basal;
|
||||||
private LongSparseArray<Double> basal_v = null; // oldest at index 0
|
private LongSparseArray<Double> basal_v = null; // oldest at index 0
|
||||||
JSONArray targetLow;
|
private JSONArray targetLow;
|
||||||
JSONArray targetHigh;
|
private LongSparseArray<Double> targetLow_v = null; // oldest at index 0
|
||||||
|
private JSONArray targetHigh;
|
||||||
|
private LongSparseArray<Double> targetHigh_v = null; // oldest at index 0
|
||||||
|
|
||||||
|
private int percentage = 100;
|
||||||
|
private int timeshift = 0;
|
||||||
|
|
||||||
public Profile(JSONObject json, String units) {
|
public Profile(JSONObject json, String units) {
|
||||||
this(json);
|
this(json, 100, 0);
|
||||||
if (this.units == null) {
|
if (this.units == null) {
|
||||||
if (units != null)
|
if (units != null)
|
||||||
this.units = units;
|
this.units = units;
|
||||||
|
@ -52,7 +58,9 @@ public class Profile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile(JSONObject json) {
|
public Profile(JSONObject json, int percentage, int timeshift) {
|
||||||
|
this.percentage = percentage;
|
||||||
|
this.timeshift = timeshift;
|
||||||
this.json = json;
|
this.json = json;
|
||||||
try {
|
try {
|
||||||
if (json.has("units"))
|
if (json.has("units"))
|
||||||
|
@ -148,17 +156,25 @@ public class Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
private LongSparseArray<Double> convertToSparseArray(JSONArray array) {
|
private LongSparseArray<Double> convertToSparseArray(JSONArray array) {
|
||||||
|
double multiplier = getMultiplier(array);
|
||||||
|
|
||||||
LongSparseArray<Double> sparse = new LongSparseArray<>();
|
LongSparseArray<Double> sparse = new LongSparseArray<>();
|
||||||
for (Integer index = 0; index < array.length(); index++) {
|
for (Integer index = 0; index < array.length(); index++) {
|
||||||
try {
|
try {
|
||||||
JSONObject o = array.getJSONObject(index);
|
JSONObject o = array.getJSONObject(index);
|
||||||
long tas = o.getLong("timeAsSeconds");
|
long tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds"));
|
||||||
Double value = o.getDouble("value");
|
Double value = o.getDouble("value") * multiplier;
|
||||||
sparse.put(tas, value);
|
sparse.put(tas, value);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if start is at 0 (midnight)
|
||||||
|
// and add last value before midnight if not
|
||||||
|
if (sparse.keyAt(0) != 0) {
|
||||||
|
sparse.put(0, sparse.valueAt(sparse.size() - 1));
|
||||||
|
}
|
||||||
return sparse;
|
return sparse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +198,47 @@ public class Profile {
|
||||||
return lastValue;
|
return lastValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Double getValueToTime(LongSparseArray<Double> array, long timeAsSeconds) {
|
Integer getShitfTimeSecs(Integer originalTime) {
|
||||||
|
Integer shiftedTime = originalTime + timeshift * 60 * 60;
|
||||||
|
shiftedTime = (shiftedTime + 24 * 60 * 60) % (24 * 60 * 60);
|
||||||
|
if (timeshift != 0)
|
||||||
|
log.debug("(Sec) Original time: " + originalTime + " ShiftedTime: " + shiftedTime);
|
||||||
|
return shiftedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getMultiplier(LongSparseArray<Double> array) {
|
||||||
|
double multiplier = 1d;
|
||||||
|
|
||||||
|
if (array == isf_v)
|
||||||
|
multiplier = 100d / percentage;
|
||||||
|
else if (array == ic_v)
|
||||||
|
multiplier = 100d / percentage;
|
||||||
|
else if (array == basal_v)
|
||||||
|
multiplier = percentage / 100d;
|
||||||
|
else
|
||||||
|
log.error("Unknown array type");
|
||||||
|
return multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getMultiplier(JSONArray array) {
|
||||||
|
double multiplier = 1d;
|
||||||
|
|
||||||
|
if (array == isf)
|
||||||
|
multiplier = 100d / percentage;
|
||||||
|
else if (array == ic)
|
||||||
|
multiplier = 100d / percentage;
|
||||||
|
else if (array == basal)
|
||||||
|
multiplier = percentage / 100d;
|
||||||
|
else if (array == targetLow)
|
||||||
|
multiplier = 1d;
|
||||||
|
else if (array == targetHigh)
|
||||||
|
multiplier = 1d;
|
||||||
|
else
|
||||||
|
log.error("Unknown array type");
|
||||||
|
return multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Double getValueToTime(LongSparseArray<Double> array, Integer timeAsSeconds) {
|
||||||
Double lastValue = null;
|
Double lastValue = null;
|
||||||
|
|
||||||
for (Integer index = 0; index < array.size(); index++) {
|
for (Integer index = 0; index < array.size(); index++) {
|
||||||
|
@ -197,26 +253,29 @@ public class Profile {
|
||||||
return lastValue;
|
return lastValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getValuesList(JSONArray array, JSONArray array2, DecimalFormat format, String units) {
|
private String format_HH_MM(Integer timeAsSeconds) {
|
||||||
|
String time;
|
||||||
|
int hour = timeAsSeconds / 60 / 60;
|
||||||
|
int minutes = (timeAsSeconds - hour * 60 * 60) / 60;
|
||||||
|
DecimalFormat df = new DecimalFormat("00");
|
||||||
|
time = df.format(hour) + ":" + df.format(minutes);
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getValuesList(LongSparseArray<Double> array, LongSparseArray<Double> array2, DecimalFormat format, String units) {
|
||||||
String retValue = "";
|
String retValue = "";
|
||||||
|
|
||||||
for (Integer index = 0; index < array.length(); index++) {
|
for (Integer index = 0; index < array.size(); index++) {
|
||||||
try {
|
retValue += format_HH_MM((int) array.keyAt(index));
|
||||||
JSONObject o = array.getJSONObject(index);
|
|
||||||
retValue += o.getString("time");
|
|
||||||
retValue += " ";
|
retValue += " ";
|
||||||
retValue += format.format(o.getDouble("value"));
|
retValue += format.format(array.valueAt(index));
|
||||||
if (array2 != null) {
|
if (array2 != null) {
|
||||||
JSONObject o2 = array2.getJSONObject(index);
|
|
||||||
retValue += " - ";
|
retValue += " - ";
|
||||||
retValue += format.format(o2.getDouble("value"));
|
retValue += format.format(array2.valueAt(index));
|
||||||
}
|
}
|
||||||
retValue += " " + units;
|
retValue += " " + units;
|
||||||
if (index + 1 < array.length())
|
if (index + 1 < array.size())
|
||||||
retValue += "\n";
|
retValue += "\n";
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
@ -236,7 +295,7 @@ public class Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIsfList() {
|
public String getIsfList() {
|
||||||
return getValuesList(isf, null, new DecimalFormat("0.0"), getUnits() + "/U");
|
return getValuesList(isf_v, null, new DecimalFormat("0.0"), getUnits() + "/U");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getIc() {
|
public Double getIc() {
|
||||||
|
@ -254,7 +313,7 @@ public class Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIcList() {
|
public String getIcList() {
|
||||||
return getValuesList(ic, null, new DecimalFormat("0.0"), " g/U");
|
return getValuesList(ic_v, null, new DecimalFormat("0.0"), " g/U");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getBasal() {
|
public Double getBasal() {
|
||||||
|
@ -272,7 +331,7 @@ public class Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBasalList() {
|
public String getBasalList() {
|
||||||
return getValuesList(basal, null, new DecimalFormat("0.00"), "U");
|
return getValuesList(basal_v, null, new DecimalFormat("0.00"), "U");
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BasalValue {
|
public class BasalValue {
|
||||||
|
@ -286,20 +345,14 @@ public class Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasalValue[] getBasalValues() {
|
public BasalValue[] getBasalValues() {
|
||||||
try {
|
BasalValue[] ret = new BasalValue[basal_v.size()];
|
||||||
BasalValue[] ret = new BasalValue[basal.length()];
|
|
||||||
|
|
||||||
for (Integer index = 0; index < basal.length(); index++) {
|
for (Integer index = 0; index < basal_v.size(); index++) {
|
||||||
JSONObject o = basal.getJSONObject(index);
|
Integer tas = (int) basal_v.keyAt(index);
|
||||||
Integer tas = o.getInt("timeAsSeconds");
|
Double value = basal_v.valueAt(index);
|
||||||
Double value = o.getDouble("value");
|
|
||||||
ret[index] = new BasalValue(tas, value);
|
ret[index] = new BasalValue(tas, value);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return new BasalValue[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getTargetLow() {
|
public Double getTargetLow() {
|
||||||
|
@ -311,7 +364,9 @@ public class Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getTargetLow(Integer timeAsSeconds) {
|
public Double getTargetLow(Integer timeAsSeconds) {
|
||||||
return getValueToTime(targetLow, timeAsSeconds);
|
if (targetLow_v == null)
|
||||||
|
targetLow_v = convertToSparseArray(targetLow);
|
||||||
|
return getValueToTime(targetLow_v, timeAsSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getTargetHigh() {
|
public Double getTargetHigh() {
|
||||||
|
@ -323,11 +378,13 @@ public class Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getTargetHigh(Integer timeAsSeconds) {
|
public Double getTargetHigh(Integer timeAsSeconds) {
|
||||||
return getValueToTime(targetHigh, timeAsSeconds);
|
if (targetHigh_v == null)
|
||||||
|
targetHigh_v = convertToSparseArray(targetHigh);
|
||||||
|
return getValueToTime(targetHigh_v, timeAsSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTargetList() {
|
public String getTargetList() {
|
||||||
return getValuesList(targetLow, targetHigh, new DecimalFormat("0.0"), getUnits());
|
return getValuesList(targetLow_v, targetHigh_v, new DecimalFormat("0.0"), getUnits());
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMaxDailyBasal() {
|
public double getMaxDailyBasal() {
|
||||||
|
@ -350,18 +407,6 @@ public class Profile {
|
||||||
return (int) (passed / 1000);
|
return (int) (passed / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Integer secondsFromMidnight(Date date) {
|
|
||||||
Calendar c = Calendar.getInstance();
|
|
||||||
long now = date.getTime();
|
|
||||||
c.setTime(date);
|
|
||||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
|
||||||
c.set(Calendar.MINUTE, 0);
|
|
||||||
c.set(Calendar.SECOND, 0);
|
|
||||||
c.set(Calendar.MILLISECOND, 0);
|
|
||||||
long passed = now - c.getTimeInMillis();
|
|
||||||
return (int) (passed / 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Integer secondsFromMidnight(long date) {
|
public static Integer secondsFromMidnight(long date) {
|
||||||
Calendar c = Calendar.getInstance();
|
Calendar c = Calendar.getInstance();
|
||||||
c.setTimeInMillis(date);
|
c.setTimeInMillis(date);
|
||||||
|
@ -410,4 +455,29 @@ public class Profile {
|
||||||
return toUnitsString(lowMgdl, lowMmol, units) + " - " + toUnitsString(highMgdl, highMmol, units);
|
return toUnitsString(lowMgdl, lowMmol, units) + " - " + toUnitsString(highMgdl, highMmol, units);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double percentageBasalSum() {
|
||||||
|
double result = 0d;
|
||||||
|
for (int i = 0; i < 24; i++) {
|
||||||
|
result += getBasal((Integer) (i * 60 * 60));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double baseBasalSum() {
|
||||||
|
double result = 0d;
|
||||||
|
for (int i = 0; i < 24; i++) {
|
||||||
|
result += getBasal((Integer) (i * 60 * 60)) / getMultiplier(basal_v);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPercentage() {
|
||||||
|
return percentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimeshift() {
|
||||||
|
return timeshift;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,56 @@ public class PumpEnactResult extends Object {
|
||||||
|
|
||||||
public boolean queued = false;
|
public boolean queued = false;
|
||||||
|
|
||||||
|
public PumpEnactResult success(boolean success) {
|
||||||
|
this.success = success;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult enacted(boolean enacted) {
|
||||||
|
this.enacted = enacted;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult comment(String comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult duration(Integer duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult absolute(Double absolute) {
|
||||||
|
this.absolute = absolute;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult isPercent(boolean isPercent) {
|
||||||
|
this.isPercent = isPercent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult isTempCancel(boolean isTempCancel) {
|
||||||
|
this.isTempCancel = isTempCancel;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult bolusDelivered(Double bolusDelivered) {
|
||||||
|
this.bolusDelivered = bolusDelivered;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult carbsDelivered(Double carbsDelivered) {
|
||||||
|
this.carbsDelivered = carbsDelivered;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult queued(boolean queued) {
|
||||||
|
this.queued = queued;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public String log() {
|
public String log() {
|
||||||
return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent + " Queued: " + queued;
|
return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent + " Queued: " + queued;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||||
|
import info.nightscout.androidaps.events.EventFoodDatabaseChanged;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
|
@ -59,6 +60,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public static final String DATABASE_DBREQUESTS = "DBRequests";
|
public static final String DATABASE_DBREQUESTS = "DBRequests";
|
||||||
public static final String DATABASE_CAREPORTALEVENTS = "CareportalEvents";
|
public static final String DATABASE_CAREPORTALEVENTS = "CareportalEvents";
|
||||||
public static final String DATABASE_PROFILESWITCHES = "ProfileSwitches";
|
public static final String DATABASE_PROFILESWITCHES = "ProfileSwitches";
|
||||||
|
public static final String DATABASE_FOODS = "Foods";
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 8;
|
private static final int DATABASE_VERSION = 8;
|
||||||
|
|
||||||
|
@ -85,6 +87,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
private static final ScheduledExecutorService profileSwitchEventWorker = Executors.newSingleThreadScheduledExecutor();
|
private static final ScheduledExecutorService profileSwitchEventWorker = Executors.newSingleThreadScheduledExecutor();
|
||||||
private static ScheduledFuture<?> scheduledProfileSwitchEventPost = null;
|
private static ScheduledFuture<?> scheduledProfileSwitchEventPost = null;
|
||||||
|
|
||||||
|
public FoodHelper foodHelper = new FoodHelper(this);
|
||||||
|
|
||||||
public DatabaseHelper(Context context) {
|
public DatabaseHelper(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
onCreate(getWritableDatabase(), getConnectionSource());
|
onCreate(getWritableDatabase(), getConnectionSource());
|
||||||
|
@ -104,6 +108,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
|
TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class);
|
TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class);
|
||||||
|
TableUtils.createTableIfNotExists(connectionSource, Food.class);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Can't create database", e);
|
log.error("Can't create database", e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -128,6 +133,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
||||||
TableUtils.dropTable(connectionSource, CareportalEvent.class, true);
|
TableUtils.dropTable(connectionSource, CareportalEvent.class, true);
|
||||||
TableUtils.dropTable(connectionSource, ProfileSwitch.class, true);
|
TableUtils.dropTable(connectionSource, ProfileSwitch.class, true);
|
||||||
|
TableUtils.dropTable(connectionSource, Food.class, true);
|
||||||
onCreate(database, connectionSource);
|
onCreate(database, connectionSource);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -205,6 +211,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
|
TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class);
|
TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class);
|
||||||
|
foodHelper.resetFood();
|
||||||
updateEarliestDataChange(0);
|
updateEarliestDataChange(0);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
@ -217,6 +224,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
scheduleTemporaryTargetChange();
|
scheduleTemporaryTargetChange();
|
||||||
scheduleCareportalEventChange();
|
scheduleCareportalEventChange();
|
||||||
scheduleProfileSwitchChange();
|
scheduleProfileSwitchChange();
|
||||||
|
foodHelper.scheduleFoodChange();
|
||||||
new java.util.Timer().schedule(
|
new java.util.Timer().schedule(
|
||||||
new java.util.TimerTask() {
|
new java.util.TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -655,8 +663,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
class PostRunnable implements Runnable {
|
class PostRunnable implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
log.debug("Firing EventTreatmentChange");
|
log.debug("Firing EventTreatmentChange");
|
||||||
MainApp.bus().post(new EventReloadTreatmentData());
|
MainApp.bus().post(new EventReloadTreatmentData(new EventTreatmentChange()));
|
||||||
MainApp.bus().post(new EventTreatmentChange());
|
|
||||||
if (earliestDataChange != null)
|
if (earliestDataChange != null)
|
||||||
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
||||||
earliestDataChange = null;
|
earliestDataChange = null;
|
||||||
|
@ -1357,8 +1364,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
class PostRunnable implements Runnable {
|
class PostRunnable implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
log.debug("Firing EventExtendedBolusChange");
|
log.debug("Firing EventExtendedBolusChange");
|
||||||
MainApp.bus().post(new EventReloadTreatmentData());
|
MainApp.bus().post(new EventReloadTreatmentData(new EventExtendedBolusChange()));
|
||||||
MainApp.bus().post(new EventExtendedBolusChange());
|
|
||||||
if (earliestDataChange != null)
|
if (earliestDataChange != null)
|
||||||
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
||||||
earliestDataChange = null;
|
earliestDataChange = null;
|
||||||
|
@ -1535,9 +1541,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
old = getDaoProfileSwitch().queryForId(profileSwitch.date);
|
old = getDaoProfileSwitch().queryForId(profileSwitch.date);
|
||||||
if (old != null) {
|
if (old != null) {
|
||||||
if (!old.isEqual(profileSwitch)) {
|
if (!old.isEqual(profileSwitch)) {
|
||||||
|
profileSwitch.source = old.source;
|
||||||
|
profileSwitch.profileName = old.profileName; // preserver profileName to prevent multiple CPP extension
|
||||||
getDaoProfileSwitch().delete(old); // need to delete/create because date may change too
|
getDaoProfileSwitch().delete(old); // need to delete/create because date may change too
|
||||||
old.copyFrom(profileSwitch);
|
getDaoProfileSwitch().create(profileSwitch);
|
||||||
getDaoProfileSwitch().create(old);
|
|
||||||
log.debug("PROFILESWITCH: Updating record by date from: " + Source.getString(profileSwitch.source) + " " + old.toString());
|
log.debug("PROFILESWITCH: Updating record by date from: " + Source.getString(profileSwitch.source) + " " + old.toString());
|
||||||
scheduleProfileSwitchChange();
|
scheduleProfileSwitchChange();
|
||||||
return true;
|
return true;
|
||||||
|
@ -1672,4 +1679,5 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------- Food handling ---------------
|
||||||
}
|
}
|
107
app/src/main/java/info/nightscout/androidaps/db/Food.java
Normal file
107
app/src/main/java/info/nightscout/androidaps/db/Food.java
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
package info.nightscout.androidaps.db;
|
||||||
|
|
||||||
|
import com.j256.ormlite.field.DatabaseField;
|
||||||
|
import com.j256.ormlite.table.DatabaseTable;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 20.09.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@DatabaseTable(tableName = DatabaseHelper.DATABASE_FOODS)
|
||||||
|
public class Food {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(Food.class);
|
||||||
|
|
||||||
|
@DatabaseField(id = true)
|
||||||
|
public long key;
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public boolean isValid = true;
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public String _id; // NS _id
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public String category;
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public String subcategory;
|
||||||
|
|
||||||
|
// Example:
|
||||||
|
// name="juice" portion=250 units="ml" carbs=12
|
||||||
|
// means 250ml of juice has 12g of carbs
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public double portion; // common portion in "units"
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public int carbs; // in grams
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public int fat = 0; // in grams
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public int protein = 0; // in grams
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public int energy = 0; // in kJ
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public String units = "g";
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public int gi; // not used yet
|
||||||
|
|
||||||
|
public Food() {
|
||||||
|
key = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEqual(Food other) {
|
||||||
|
if (portion != other.portion)
|
||||||
|
return false;
|
||||||
|
if (carbs != other.carbs)
|
||||||
|
return false;
|
||||||
|
if (fat != other.fat)
|
||||||
|
return false;
|
||||||
|
if (protein != other.protein)
|
||||||
|
return false;
|
||||||
|
if (energy != other.energy)
|
||||||
|
return false;
|
||||||
|
if (gi != other.gi)
|
||||||
|
return false;
|
||||||
|
if (!Objects.equals(_id, other._id))
|
||||||
|
return false;
|
||||||
|
if (!Objects.equals(name, other.name))
|
||||||
|
return false;
|
||||||
|
if (!Objects.equals(category, other.category))
|
||||||
|
return false;
|
||||||
|
if (!Objects.equals(subcategory, other.subcategory))
|
||||||
|
return false;
|
||||||
|
if (!Objects.equals(units, other.units))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copyFrom(Food other) {
|
||||||
|
isValid = other.isValid;
|
||||||
|
_id = other._id;
|
||||||
|
name = other.name;
|
||||||
|
category = other.category;
|
||||||
|
subcategory = other.subcategory;
|
||||||
|
portion = other.portion;
|
||||||
|
carbs = other.carbs;
|
||||||
|
fat = other.fat;
|
||||||
|
protein = other.protein;
|
||||||
|
energy = other.energy;
|
||||||
|
units = other.units;
|
||||||
|
gi = other.gi;
|
||||||
|
}
|
||||||
|
}
|
207
app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java
Normal file
207
app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java
Normal file
|
@ -0,0 +1,207 @@
|
||||||
|
package info.nightscout.androidaps.db;
|
||||||
|
|
||||||
|
import com.j256.ormlite.android.AndroidConnectionSource;
|
||||||
|
import com.j256.ormlite.dao.Dao;
|
||||||
|
import com.j256.ormlite.stmt.PreparedQuery;
|
||||||
|
import com.j256.ormlite.stmt.QueryBuilder;
|
||||||
|
import com.j256.ormlite.stmt.Where;
|
||||||
|
import com.j256.ormlite.table.TableUtils;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.events.EventFoodDatabaseChanged;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 24.09.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class FoodHelper {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(FoodHelper.class);
|
||||||
|
|
||||||
|
DatabaseHelper databaseHelper;
|
||||||
|
|
||||||
|
private static final ScheduledExecutorService foodEventWorker = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
private static ScheduledFuture<?> scheduledFoodEventPost = null;
|
||||||
|
|
||||||
|
public FoodHelper(DatabaseHelper databaseHelper) {
|
||||||
|
this.databaseHelper = databaseHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dao<Food, Long> getDaoFood() throws SQLException {
|
||||||
|
return databaseHelper.getDao(Food.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetFood() {
|
||||||
|
try {
|
||||||
|
TableUtils.dropTable(databaseHelper.getConnectionSource(), Food.class, true);
|
||||||
|
TableUtils.createTableIfNotExists(databaseHelper.getConnectionSource(), Food.class);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
scheduleFoodChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Food> getFoodData() {
|
||||||
|
try {
|
||||||
|
Dao<Food, Long> daoFood = getDaoFood();
|
||||||
|
List<Food> foods;
|
||||||
|
QueryBuilder<Food, Long> queryBuilder = daoFood.queryBuilder();
|
||||||
|
PreparedQuery<Food> preparedQuery = queryBuilder.prepare();
|
||||||
|
foods = daoFood.query(preparedQuery);
|
||||||
|
return foods;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean createOrUpdate(Food food) {
|
||||||
|
try {
|
||||||
|
// find by NS _id
|
||||||
|
if (food._id != null) {
|
||||||
|
Food old;
|
||||||
|
|
||||||
|
QueryBuilder<Food, Long> queryBuilder = getDaoFood().queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("_id", food._id);
|
||||||
|
PreparedQuery<Food> preparedQuery = queryBuilder.prepare();
|
||||||
|
List<Food> found = getDaoFood().query(preparedQuery);
|
||||||
|
if (found.size() > 0) {
|
||||||
|
old = found.get(0);
|
||||||
|
if (!old.isEqual(food)) {
|
||||||
|
getDaoFood().delete(old); // need to delete/create because date may change too
|
||||||
|
old.copyFrom(food);
|
||||||
|
getDaoFood().create(old);
|
||||||
|
log.debug("FOOD: Updating record by _id: " + old.toString());
|
||||||
|
scheduleFoodChange();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getDaoFood().createOrUpdate(food);
|
||||||
|
log.debug("FOOD: New record: " + food.toString());
|
||||||
|
scheduleFoodChange();
|
||||||
|
return true;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(Food food) {
|
||||||
|
try {
|
||||||
|
getDaoFood().delete(food);
|
||||||
|
scheduleFoodChange();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scheduleFoodChange() {
|
||||||
|
class PostRunnable implements Runnable {
|
||||||
|
public void run() {
|
||||||
|
log.debug("Firing EventFoodChange");
|
||||||
|
MainApp.bus().post(new EventFoodDatabaseChanged());
|
||||||
|
scheduledFoodEventPost = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// prepare task for execution in 1 sec
|
||||||
|
// cancel waiting task to prevent sending multiple posts
|
||||||
|
if (scheduledFoodEventPost != null)
|
||||||
|
scheduledFoodEventPost.cancel(false);
|
||||||
|
Runnable task = new PostRunnable();
|
||||||
|
final int sec = 1;
|
||||||
|
scheduledFoodEventPost = foodEventWorker.schedule(task, sec, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"_id": "551ee3ad368e06e80856e6a9",
|
||||||
|
"type": "food",
|
||||||
|
"category": "Zakladni",
|
||||||
|
"subcategory": "Napoje",
|
||||||
|
"name": "Mleko",
|
||||||
|
"portion": 250,
|
||||||
|
"carbs": 12,
|
||||||
|
"gi": 1,
|
||||||
|
"created_at": "2015-04-14T06:59:16.500Z",
|
||||||
|
"unit": "ml"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public void createFoodFromJsonIfNotExists(JSONObject trJson) {
|
||||||
|
try {
|
||||||
|
Food food = new Food();
|
||||||
|
if (trJson.has("type") && trJson.getString("type").equals("food")) {
|
||||||
|
if (trJson.has("_id"))
|
||||||
|
food._id = trJson.getString("_id");
|
||||||
|
if (trJson.has("category"))
|
||||||
|
food.category = trJson.getString("category");
|
||||||
|
if (trJson.has("subcategory"))
|
||||||
|
food.subcategory = trJson.getString("subcategory");
|
||||||
|
if (trJson.has("name"))
|
||||||
|
food.name = trJson.getString("name");
|
||||||
|
if (trJson.has("unit"))
|
||||||
|
food.units = trJson.getString("unit");
|
||||||
|
if (trJson.has("portion"))
|
||||||
|
food.portion = trJson.getDouble("portion");
|
||||||
|
if (trJson.has("carbs"))
|
||||||
|
food.carbs = trJson.getInt("carbs");
|
||||||
|
if (trJson.has("gi"))
|
||||||
|
food.gi = trJson.getInt("gi");
|
||||||
|
if (trJson.has("energy"))
|
||||||
|
food.energy = trJson.getInt("energy");
|
||||||
|
if (trJson.has("protein"))
|
||||||
|
food.protein = trJson.getInt("protein");
|
||||||
|
if (trJson.has("fat"))
|
||||||
|
food.fat = trJson.getInt("fat");
|
||||||
|
}
|
||||||
|
createOrUpdate(food);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteFoodById(String _id) {
|
||||||
|
Food stored = findFoodById(_id);
|
||||||
|
if (stored != null) {
|
||||||
|
log.debug("FOOD: Removing Food record from database: " + stored.toString());
|
||||||
|
delete(stored);
|
||||||
|
scheduleFoodChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Food findFoodById(String _id) {
|
||||||
|
try {
|
||||||
|
QueryBuilder<Food, Long> queryBuilder = getDaoFood().queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("_id", _id);
|
||||||
|
PreparedQuery<Food> preparedQuery = queryBuilder.prepare();
|
||||||
|
List<Food> list = getDaoFood().query(preparedQuery);
|
||||||
|
|
||||||
|
if (list.size() == 1) {
|
||||||
|
return list.get(0);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,14 +10,15 @@ import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.interfaces.Interval;
|
import info.nightscout.androidaps.interfaces.Interval;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
|
||||||
|
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
|
||||||
@DatabaseTable(tableName = DatabaseHelper.DATABASE_PROFILESWITCHES)
|
@DatabaseTable(tableName = DatabaseHelper.DATABASE_PROFILESWITCHES)
|
||||||
public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
||||||
|
@ -58,13 +59,27 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
||||||
public Profile getProfileObject() {
|
public Profile getProfileObject() {
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
try {
|
try {
|
||||||
profile = new Profile(new JSONObject(profileJson));
|
profile = new Profile(new JSONObject(profileJson), percentage, timeshift);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCustomizedName() {
|
||||||
|
String name = profileName;
|
||||||
|
if(LocalProfilePlugin.LOCAL_PROFILE.equals(name)){
|
||||||
|
name = DecimalFormatter.to2Decimal(getProfileObject().percentageBasalSum()) + "U ";
|
||||||
|
}
|
||||||
|
if (isCPP) {
|
||||||
|
name += "(" + percentage + "%";
|
||||||
|
if (timeshift != 0)
|
||||||
|
name += "," + timeshift + "h";
|
||||||
|
name += ")";
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEqual(ProfileSwitch other) {
|
public boolean isEqual(ProfileSwitch other) {
|
||||||
if (date != other.date) {
|
if (date != other.date) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -179,7 +194,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return profileName;
|
return getCustomizedName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package info.nightscout.androidaps.events;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
/** Base class for all events posted on the event bus. */
|
||||||
|
public abstract class Event {
|
||||||
|
static {
|
||||||
|
ReflectionToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ReflectionToStringBuilder.toString(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,5 +3,5 @@ package info.nightscout.androidaps.events;
|
||||||
/**
|
/**
|
||||||
* Created by mike on 07.07.2016.
|
* Created by mike on 07.07.2016.
|
||||||
*/
|
*/
|
||||||
public class EventAppExit {
|
public class EventAppExit extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by adrian on 07/02/17.
|
* Created by adrian on 07/02/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventBolusRequested {
|
public class EventBolusRequested extends Event {
|
||||||
private double amount;
|
private double amount;
|
||||||
|
|
||||||
public EventBolusRequested (double amount){
|
public EventBolusRequested (double amount){
|
||||||
|
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 25.05.2017.
|
* Created by mike on 25.05.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventCareportalEventChange {
|
public class EventCareportalEventChange extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 17.02.2017.
|
* Created by mike on 17.02.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventConfigBuilderChange {
|
public class EventConfigBuilderChange extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 15.05.2017.
|
* Created by mike on 15.05.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventExtendedBolusChange {
|
public class EventExtendedBolusChange extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package info.nightscout.androidaps.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 20.09.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class EventFoodDatabaseChanged extends Event {
|
||||||
|
}
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 13.12.2016.
|
* Created by mike on 13.12.2016.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventInitializationChanged {
|
public class EventInitializationChanged extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.events;
|
||||||
|
|
||||||
|
/** Supeclass for all events concerned with input or output into or from the LoopPlugin. */
|
||||||
|
public abstract class EventLoop extends Event {
|
||||||
|
}
|
|
@ -3,5 +3,5 @@ package info.nightscout.androidaps.events;
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.06.2016.
|
* Created by mike on 05.06.2016.
|
||||||
*/
|
*/
|
||||||
public class EventNewBG {
|
public class EventNewBG extends EventLoop {
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,5 @@ package info.nightscout.androidaps.events;
|
||||||
/**
|
/**
|
||||||
* Created by mike on 04.06.2016.
|
* Created by mike on 04.06.2016.
|
||||||
*/
|
*/
|
||||||
public class EventNewBasalProfile {
|
public class EventNewBasalProfile extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
/**
|
/**
|
||||||
* Created by mike on 19.06.2016.
|
* Created by mike on 19.06.2016.
|
||||||
*/
|
*/
|
||||||
public class EventPreferenceChange {
|
public class EventPreferenceChange extends Event {
|
||||||
public String changedKey;
|
public String changedKey;
|
||||||
public EventPreferenceChange(String key) {
|
public EventPreferenceChange(String key) {
|
||||||
changedKey = key;
|
changedKey = key;
|
||||||
|
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 02.06.2017.
|
* Created by mike on 02.06.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventProfileSwitchChange {
|
public class EventProfileSwitchChange extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import info.nightscout.androidaps.R;
|
||||||
* Created by mike on 19.02.2017.
|
* Created by mike on 19.02.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventPumpStatusChanged {
|
public class EventPumpStatusChanged extends Event {
|
||||||
public static final int CONNECTING = 0;
|
public static final int CONNECTING = 0;
|
||||||
public static final int CONNECTED = 1;
|
public static final int CONNECTED = 1;
|
||||||
public static final int PERFORMING = 2;
|
public static final int PERFORMING = 2;
|
||||||
|
@ -18,14 +18,24 @@ public class EventPumpStatusChanged {
|
||||||
public int sSecondsElapsed = 0;
|
public int sSecondsElapsed = 0;
|
||||||
public String sPerfomingAction = "";
|
public String sPerfomingAction = "";
|
||||||
|
|
||||||
|
public static String error = "";
|
||||||
|
|
||||||
public EventPumpStatusChanged(int status) {
|
public EventPumpStatusChanged(int status) {
|
||||||
sStatus = status;
|
sStatus = status;
|
||||||
sSecondsElapsed = 0;
|
sSecondsElapsed = 0;
|
||||||
|
error = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventPumpStatusChanged(int status, int secondsElapsed) {
|
public EventPumpStatusChanged(int status, int secondsElapsed) {
|
||||||
sStatus = status;
|
sStatus = status;
|
||||||
sSecondsElapsed = secondsElapsed;
|
sSecondsElapsed = secondsElapsed;
|
||||||
|
error = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public EventPumpStatusChanged(int status, String error) {
|
||||||
|
sStatus = status;
|
||||||
|
sSecondsElapsed = 0;
|
||||||
|
this.error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventPumpStatusChanged(String action) {
|
public EventPumpStatusChanged(String action) {
|
||||||
|
|
|
@ -3,5 +3,5 @@ package info.nightscout.androidaps.events;
|
||||||
/**
|
/**
|
||||||
* Created by mike on 13.06.2016.
|
* Created by mike on 13.06.2016.
|
||||||
*/
|
*/
|
||||||
public class EventRefreshGui {
|
public class EventRefreshGui extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 16.06.2017.
|
* Created by mike on 16.06.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventRefreshOverview {
|
public class EventRefreshOverview extends Event {
|
||||||
public String from;
|
public String from;
|
||||||
|
|
||||||
public EventRefreshOverview(String from) {
|
public EventRefreshOverview(String from) {
|
||||||
|
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 12.06.2017.
|
* Created by mike on 12.06.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventReloadProfileSwitchData {
|
public class EventReloadProfileSwitchData extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 29.05.2017.
|
* Created by mike on 29.05.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventReloadTempBasalData {
|
public class EventReloadTempBasalData extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,10 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 29.05.2017.
|
* Created by mike on 29.05.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventReloadTreatmentData {
|
public class EventReloadTreatmentData extends Event {
|
||||||
|
public Object next;
|
||||||
|
|
||||||
|
public EventReloadTreatmentData(Object next) {
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,5 @@ package info.nightscout.androidaps.events;
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.06.2016.
|
* Created by mike on 05.06.2016.
|
||||||
*/
|
*/
|
||||||
public class EventTempBasalChange {
|
public class EventTempBasalChange extends EventLoop {
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 13.01.2017.
|
* Created by mike on 13.01.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventTempTargetChange {
|
public class EventTempTargetChange extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,5 @@ package info.nightscout.androidaps.events;
|
||||||
/**
|
/**
|
||||||
* Created by mike on 04.06.2016.
|
* Created by mike on 04.06.2016.
|
||||||
*/
|
*/
|
||||||
public class EventTreatmentChange {
|
public class EventTreatmentChange extends EventLoop {
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.events;
|
||||||
|
|
||||||
|
/** Base class for events to update the UI, mostly a specific tab. */
|
||||||
|
public abstract class EventUpdateGui extends Event {
|
||||||
|
}
|
|
@ -30,4 +30,5 @@ public interface PluginBase {
|
||||||
boolean showInList(int type);
|
boolean showInList(int type);
|
||||||
void setFragmentEnabled(int type, boolean fragmentEnabled);
|
void setFragmentEnabled(int type, boolean fragmentEnabled);
|
||||||
void setFragmentVisible(int type, boolean fragmentVisible);
|
void setFragmentVisible(int type, boolean fragmentVisible);
|
||||||
|
int getPreferencesId();
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ public interface PumpInterface {
|
||||||
|
|
||||||
PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo);
|
PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo);
|
||||||
void stopBolusDelivering();
|
void stopBolusDelivering();
|
||||||
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean force);
|
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew);
|
||||||
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes);
|
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes);
|
||||||
PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes);
|
PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes);
|
||||||
//some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
|
//some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -69,6 +70,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
try {
|
||||||
View view = inflater.inflate(R.layout.actions_fragment, container, false);
|
View view = inflater.inflate(R.layout.actions_fragment, container, false);
|
||||||
|
|
||||||
profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch);
|
profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch);
|
||||||
|
@ -89,6 +91,11 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
|
|
||||||
updateGUI();
|
updateGUI();
|
||||||
return view;
|
return view;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
@ -159,7 +166,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
tempBasal.setVisibility(View.GONE);
|
tempBasal.setVisibility(View.GONE);
|
||||||
tempBasalCancel.setVisibility(View.VISIBLE);
|
tempBasalCancel.setVisibility(View.VISIBLE);
|
||||||
final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
tempBasalCancel.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort());
|
tempBasalCancel.setText(MainApp.instance().getString(R.string.cancel) + " " + activeTemp.toStringShort());
|
||||||
} else {
|
} else {
|
||||||
tempBasal.setVisibility(View.VISIBLE);
|
tempBasal.setVisibility(View.VISIBLE);
|
||||||
tempBasalCancel.setVisibility(View.GONE);
|
tempBasalCancel.setVisibility(View.GONE);
|
||||||
|
@ -187,14 +194,14 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.actions_profileswitch:
|
case R.id.actions_profileswitch:
|
||||||
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
||||||
final OptionsToShow profileswitch = CareportalFragment.profileswitch;
|
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCH;
|
||||||
profileswitch.executeProfileSwitch = true;
|
profileswitch.executeProfileSwitch = true;
|
||||||
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
|
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
|
||||||
newDialog.show(manager, "NewNSTreatmentDialog");
|
newDialog.show(manager, "NewNSTreatmentDialog");
|
||||||
break;
|
break;
|
||||||
case R.id.actions_temptarget:
|
case R.id.actions_temptarget:
|
||||||
NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog();
|
NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog();
|
||||||
final OptionsToShow temptarget = CareportalFragment.temptarget;
|
final OptionsToShow temptarget = CareportalFragment.TEMPTARGET;
|
||||||
temptarget.executeTempTarget = true;
|
temptarget.executeTempTarget = true;
|
||||||
newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget);
|
newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget);
|
||||||
newTTDialog.show(manager, "NewNSTreatmentDialog");
|
newTTDialog.show(manager, "NewNSTreatmentDialog");
|
||||||
|
|
|
@ -10,8 +10,8 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
|
||||||
public class ActionsPlugin implements PluginBase {
|
public class ActionsPlugin implements PluginBase {
|
||||||
|
|
||||||
boolean fragmentEnabled = true;
|
private boolean fragmentEnabled = true;
|
||||||
boolean fragmentVisible = true;
|
private boolean fragmentVisible = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getType() {
|
public int getType() {
|
||||||
|
@ -74,4 +74,9 @@ public class ActionsPlugin implements PluginBase {
|
||||||
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
|
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,9 @@ package info.nightscout.androidaps.plugins.Actions.dialogs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -16,7 +14,6 @@ import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
@ -32,12 +29,11 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.PlusMinusEditText;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
|
@ -45,13 +41,12 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(FillDialog.class);
|
private static Logger log = LoggerFactory.getLogger(FillDialog.class);
|
||||||
|
|
||||||
Button deliverButton;
|
Button deliverButton;
|
||||||
TextView insulin;
|
|
||||||
|
|
||||||
double amount1 = 0d;
|
double amount1 = 0d;
|
||||||
double amount2 = 0d;
|
double amount2 = 0d;
|
||||||
double amount3 = 0d;
|
double amount3 = 0d;
|
||||||
|
|
||||||
PlusMinusEditText editInsulin;
|
NumberPicker editInsulin;
|
||||||
|
|
||||||
Handler mHandler;
|
Handler mHandler;
|
||||||
public static HandlerThread mHandlerThread;
|
public static HandlerThread mHandlerThread;
|
||||||
|
@ -73,10 +68,10 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||||
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||||
|
|
||||||
insulin = (TextView) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
|
||||||
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
|
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
|
||||||
double bolusstep = MainApp.getConfigBuilder().getPumpDescription().bolusStep;
|
double bolusstep = MainApp.getConfigBuilder().getPumpDescription().bolusStep;
|
||||||
editInsulin = new PlusMinusEditText(view, R.id.treatments_newtreatment_insulinamount, R.id.treatments_newtreatment_insulinamount_plus, R.id.treatments_newtreatment_insulinamount_minus, 0d, 0d, maxInsulin, bolusstep, new DecimalFormat("0.00"), false);
|
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
||||||
|
editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, new DecimalFormat("0.00"), false);
|
||||||
|
|
||||||
//setup preset buttons
|
//setup preset buttons
|
||||||
Button button1 = (Button) view.findViewById(R.id.fill_preset_button1);
|
Button button1 = (Button) view.findViewById(R.id.fill_preset_button1);
|
||||||
|
@ -127,7 +122,7 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.treatments_newtreatment_deliverbutton:
|
case R.id.treatments_newtreatment_deliverbutton:
|
||||||
Double insulin = SafeParse.stringToDouble(this.insulin.getText().toString());
|
Double insulin = SafeParse.stringToDouble(editInsulin.getText().toString());
|
||||||
confirmAndDeliver(insulin);
|
confirmAndDeliver(insulin);
|
||||||
break;
|
break;
|
||||||
case R.id.fill_preset_button1:
|
case R.id.fill_preset_button1:
|
||||||
|
|
|
@ -11,9 +11,6 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.RadioButton;
|
|
||||||
|
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
@ -30,14 +27,14 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.utils.PlusMinusEditText;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
public class NewExtendedBolusDialog extends DialogFragment implements View.OnClickListener {
|
public class NewExtendedBolusDialog extends DialogFragment implements View.OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(NewExtendedBolusDialog.class);
|
private static Logger log = LoggerFactory.getLogger(NewExtendedBolusDialog.class);
|
||||||
|
|
||||||
PlusMinusEditText editInsulin;
|
NumberPicker editInsulin;
|
||||||
PlusMinusEditText editDuration;
|
NumberPicker editDuration;
|
||||||
|
|
||||||
Handler mHandler;
|
Handler mHandler;
|
||||||
public static HandlerThread mHandlerThread;
|
public static HandlerThread mHandlerThread;
|
||||||
|
@ -56,11 +53,13 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
||||||
View view = inflater.inflate(R.layout.overview_newextendedbolus_dialog, container, false);
|
View view = inflater.inflate(R.layout.overview_newextendedbolus_dialog, container, false);
|
||||||
|
|
||||||
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
|
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
|
||||||
editInsulin = new PlusMinusEditText(view, R.id.overview_newextendedbolus_insulin, R.id.overview_newextendedbolus_insulin_plus, R.id.overview_newextendedbolus_insulin_minus, 0d, 0d, maxInsulin, 0.1d, new DecimalFormat("0.00"), false);
|
editInsulin = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_insulin);
|
||||||
|
editInsulin.setParams(0d, 0d, maxInsulin, 0.1d, new DecimalFormat("0.00"), false);
|
||||||
|
|
||||||
double extendedDurationStep = MainApp.getConfigBuilder().getPumpDescription().extendedBolusDurationStep;
|
double extendedDurationStep = MainApp.getConfigBuilder().getPumpDescription().extendedBolusDurationStep;
|
||||||
double extendedMaxDuration = MainApp.getConfigBuilder().getPumpDescription().extendedBolusMaxDuration;
|
double extendedMaxDuration = MainApp.getConfigBuilder().getPumpDescription().extendedBolusMaxDuration;
|
||||||
editDuration = new PlusMinusEditText(view, R.id.overview_newextendedbolus_duration, R.id.overview_newextendedbolus_duration_plus, R.id.overview_newextendedbolus_duration_minus, extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, new DecimalFormat("0"), false);
|
editDuration = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_duration);
|
||||||
|
editDuration.setParams(extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, new DecimalFormat("0"), false);
|
||||||
|
|
||||||
view.findViewById(R.id.ok).setOnClickListener(this);
|
view.findViewById(R.id.ok).setOnClickListener(this);
|
||||||
view.findViewById(R.id.cancel).setOnClickListener(this);
|
view.findViewById(R.id.cancel).setOnClickListener(this);
|
||||||
|
|
|
@ -14,7 +14,6 @@ import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
|
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
@ -26,12 +25,11 @@ import java.text.DecimalFormat;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.PlusMinusEditText;
|
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
public class NewTempBasalDialog extends DialogFragment implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
|
public class NewTempBasalDialog extends DialogFragment implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
|
||||||
|
@ -159,7 +157,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
||||||
if (setAsPercent) {
|
if (setAsPercent) {
|
||||||
result = pump.setTempBasalPercent(finalBasalPercent, finalDurationInMinutes);
|
result = pump.setTempBasalPercent(finalBasalPercent, finalDurationInMinutes);
|
||||||
} else {
|
} else {
|
||||||
result = pump.setTempBasalAbsolute(finalBasal, finalDurationInMinutes, false);
|
result = pump.setTempBasalAbsolute(finalBasal, finalDurationInMinutes, true);
|
||||||
}
|
}
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
if (context instanceof Activity) {
|
if (context instanceof Activity) {
|
||||||
|
|
|
@ -3,21 +3,19 @@ package info.nightscout.androidaps.plugins.Careportal;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.text.Layout;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
import info.nightscout.androidaps.BuildConfig;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||||
|
@ -28,8 +26,6 @@ import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
|
||||||
|
|
||||||
public class CareportalFragment extends SubscriberFragment implements View.OnClickListener {
|
public class CareportalFragment extends SubscriberFragment implements View.OnClickListener {
|
||||||
|
|
||||||
static CareportalPlugin careportalPlugin;
|
|
||||||
|
|
||||||
TextView iage;
|
TextView iage;
|
||||||
TextView cage;
|
TextView cage;
|
||||||
TextView sage;
|
TextView sage;
|
||||||
|
@ -39,38 +35,33 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
LinearLayout butonsLayout;
|
LinearLayout butonsLayout;
|
||||||
View noProfileView;
|
View noProfileView;
|
||||||
|
|
||||||
static public CareportalPlugin getPlugin() {
|
// date,bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split,temptarget
|
||||||
if (careportalPlugin == null) {
|
public static final OptionsToShow BGCHECK = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck).date().bg();
|
||||||
careportalPlugin = new CareportalPlugin();
|
public static final OptionsToShow SNACKBOLUS = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus).date().bg().insulin().carbs().prebolus();
|
||||||
}
|
public static final OptionsToShow MEALBOLUS = new OptionsToShow(R.id.careportal_mealbolus, R.string.careportal_mealbolus).date().bg().insulin().carbs().prebolus();
|
||||||
return careportalPlugin;
|
public static final OptionsToShow CORRECTIONBOLUS = new OptionsToShow(R.id.careportal_correctionbolus, R.string.careportal_correctionbolus).date().bg().insulin().carbs().prebolus();
|
||||||
}
|
public static final OptionsToShow CARBCORRECTION = new OptionsToShow(R.id.careportal_carbscorrection, R.string.careportal_carbscorrection).date().bg().carbs();
|
||||||
|
public static final OptionsToShow COMBOBOLUS = new OptionsToShow(R.id.careportal_combobolus, R.string.careportal_combobolus).date().bg().insulin().carbs().prebolus().duration().split();
|
||||||
// bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split,temptarget
|
public static final OptionsToShow ANNOUNCEMENT = new OptionsToShow(R.id.careportal_announcement, R.string.careportal_announcement).date().bg();
|
||||||
public static final OptionsToShow bgcheck = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck, true, true, true, false, false, false, false, false, false, false);
|
public static final OptionsToShow NOTE = new OptionsToShow(R.id.careportal_note, R.string.careportal_note).date().bg().duration();
|
||||||
public static final OptionsToShow snackbolus = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus, true, true, true, true, false, false, false, false, false, false);
|
public static final OptionsToShow QUESTION = new OptionsToShow(R.id.careportal_question, R.string.careportal_question).date().bg();
|
||||||
public static final OptionsToShow mealbolus = new OptionsToShow(R.id.careportal_mealbolus, R.string.careportal_mealbolus, true, true, true, true, false, false, false, false, false, false);
|
public static final OptionsToShow EXERCISE = new OptionsToShow(R.id.careportal_exercise, R.string.careportal_exercise).date().duration();
|
||||||
public static final OptionsToShow correctionbolus = new OptionsToShow(R.id.careportal_correctionbolus, R.string.careportal_correctionbolus, true, true, true, true, false, false, false, false, false, false);
|
public static final OptionsToShow SITECHANGE = new OptionsToShow(R.id.careportal_pumpsitechange, R.string.careportal_pumpsitechange).date().bg();
|
||||||
public static final OptionsToShow carbcorrection = new OptionsToShow(R.id.careportal_carbscorrection, R.string.careportal_carbscorrection, true, false, true, false, false, false, false, false, false, false);
|
public static final OptionsToShow SENSORSTART = new OptionsToShow(R.id.careportal_cgmsensorstart, R.string.careportal_cgmsensorstart).date().bg();
|
||||||
public static final OptionsToShow combobolus = new OptionsToShow(R.id.careportal_combobolus, R.string.careportal_combobolus, true, true, true, true, true, false, false, false, true, false);
|
public static final OptionsToShow SENSORCHANGE = new OptionsToShow(R.id.careportal_cgmsensorinsert, R.string.careportal_cgmsensorinsert).date().bg();
|
||||||
public static final OptionsToShow announcement = new OptionsToShow(R.id.careportal_announcement, R.string.careportal_announcement, true, false, false, false, false, false, false, false, false, false);
|
public static final OptionsToShow INSULINCHANGE = new OptionsToShow(R.id.careportal_insulincartridgechange, R.string.careportal_insulincartridgechange).date().bg();
|
||||||
public static final OptionsToShow note = new OptionsToShow(R.id.careportal_note, R.string.careportal_note, true, false, false, false, true, false, false, false, false, false);
|
public static final OptionsToShow PUMPBATTERYCHANGE = new OptionsToShow(R.id.careportal_pumpbatterychange, R.string.careportal_pumpbatterychange).date().bg();
|
||||||
public static final OptionsToShow question = new OptionsToShow(R.id.careportal_question, R.string.careportal_question, true, false, false, false, false, false, false, false, false, false);
|
public static final OptionsToShow TEMPBASALSTART = new OptionsToShow(R.id.careportal_tempbasalstart, R.string.careportal_tempbasalstart).date().bg().duration().percent().absolute();
|
||||||
public static final OptionsToShow exercise = new OptionsToShow(R.id.careportal_exercise, R.string.careportal_exercise, false, false, false, false, true, false, false, false, false, false);
|
public static final OptionsToShow TEMPBASALEND = new OptionsToShow(R.id.careportal_tempbasalend, R.string.careportal_tempbasalend).date().bg();
|
||||||
public static final OptionsToShow sitechange = new OptionsToShow(R.id.careportal_pumpsitechange, R.string.careportal_pumpsitechange, true, true, false, false, false, false, false, false, false, false);
|
public static final OptionsToShow PROFILESWITCH = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch).date().duration().profile();
|
||||||
public static final OptionsToShow sensorstart = new OptionsToShow(R.id.careportal_cgmsensorstart, R.string.careportal_cgmsensorstart, true, false, false, false, false, false, false, false, false, false);
|
public static final OptionsToShow PROFILESWITCHDIRECT = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch).duration().profile();
|
||||||
public static final OptionsToShow sensorchange = new OptionsToShow(R.id.careportal_cgmsensorinsert, R.string.careportal_cgmsensorinsert, true, false, false, false, false, false, false, false, false, false);
|
public static final OptionsToShow OPENAPSOFFLINE = new OptionsToShow(R.id.careportal_openapsoffline, R.string.careportal_openapsoffline).date().duration();
|
||||||
public static final OptionsToShow insulinchange = new OptionsToShow(R.id.careportal_insulincartridgechange, R.string.careportal_insulincartridgechange, true, false, false, false, false, false, false, false, false, false);
|
public static final OptionsToShow TEMPTARGET = new OptionsToShow(R.id.careportal_temporarytarget, R.string.careportal_temporarytarget).date().duration().tempTarget();
|
||||||
public static final OptionsToShow pumpbatterychange = new OptionsToShow(R.id.careportal_pumpbatterychange, R.string.careportal_pumpbatterychange, true, false, false, false, false, false, false, false, false, false);
|
|
||||||
public static final OptionsToShow tempbasalstart = new OptionsToShow(R.id.careportal_tempbasalstart, R.string.careportal_tempbasalstart, true, false, false, false, true, true, true, false, false, false);
|
|
||||||
public static final OptionsToShow tempbasalend = new OptionsToShow(R.id.careportal_tempbasalend, R.string.careportal_tempbasalend, true, false, false, false, false, false, false, false, false, false);
|
|
||||||
public static final OptionsToShow profileswitch = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch, true, false, false, false, true, false, false, true, false, false);
|
|
||||||
public static final OptionsToShow openapsoffline = new OptionsToShow(R.id.careportal_openapsoffline, R.string.careportal_openapsoffline, false, false, false, false, true, false, false, false, false, false);
|
|
||||||
public static final OptionsToShow temptarget = new OptionsToShow(R.id.careportal_temporarytarget, R.string.careportal_temporarytarget, false, false, false, false, true, false, false, false, false, true);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
try {
|
||||||
View view = inflater.inflate(R.layout.careportal_fragment, container, false);
|
View view = inflater.inflate(R.layout.careportal_fragment, container, false);
|
||||||
|
|
||||||
view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this);
|
view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this);
|
||||||
|
@ -99,9 +90,9 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
|
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
|
||||||
pbage = (TextView) view.findViewById(R.id.careportal_pbage);
|
pbage = (TextView) view.findViewById(R.id.careportal_pbage);
|
||||||
|
|
||||||
statsLayout = (View) view.findViewById(R.id.careportal_stats);
|
statsLayout = view.findViewById(R.id.careportal_stats);
|
||||||
|
|
||||||
noProfileView = (View) view.findViewById(R.id.profileview_noprofile);
|
noProfileView = view.findViewById(R.id.profileview_noprofile);
|
||||||
butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons);
|
butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons);
|
||||||
|
|
||||||
ProfileStore profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile();
|
ProfileStore profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile();
|
||||||
|
@ -118,6 +109,11 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
|
|
||||||
updateGUI();
|
updateGUI();
|
||||||
return view;
|
return view;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -129,66 +125,66 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case R.id.careportal_bgcheck:
|
case R.id.careportal_bgcheck:
|
||||||
newDialog.setOptions(bgcheck, R.string.careportal_bgcheck);
|
newDialog.setOptions(BGCHECK, R.string.careportal_bgcheck);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_announcement:
|
case R.id.careportal_announcement:
|
||||||
newDialog.setOptions(announcement, R.string.careportal_announcement);
|
newDialog.setOptions(ANNOUNCEMENT, R.string.careportal_announcement);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_cgmsensorinsert:
|
case R.id.careportal_cgmsensorinsert:
|
||||||
newDialog.setOptions(sensorchange, R.string.careportal_cgmsensorinsert);
|
newDialog.setOptions(SENSORCHANGE, R.string.careportal_cgmsensorinsert);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_cgmsensorstart:
|
case R.id.careportal_cgmsensorstart:
|
||||||
newDialog.setOptions(sensorstart, R.string.careportal_cgmsensorstart);
|
newDialog.setOptions(SENSORSTART, R.string.careportal_cgmsensorstart);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_combobolus:
|
case R.id.careportal_combobolus:
|
||||||
newDialog.setOptions(combobolus, R.string.careportal_combobolus);
|
newDialog.setOptions(COMBOBOLUS, R.string.careportal_combobolus);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_correctionbolus:
|
case R.id.careportal_correctionbolus:
|
||||||
newDialog.setOptions(correctionbolus, R.string.careportal_correctionbolus);
|
newDialog.setOptions(CORRECTIONBOLUS, R.string.careportal_correctionbolus);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_carbscorrection:
|
case R.id.careportal_carbscorrection:
|
||||||
newDialog.setOptions(carbcorrection, R.string.careportal_carbscorrection);
|
newDialog.setOptions(CARBCORRECTION, R.string.careportal_carbscorrection);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_exercise:
|
case R.id.careportal_exercise:
|
||||||
newDialog.setOptions(exercise, R.string.careportal_exercise);
|
newDialog.setOptions(EXERCISE, R.string.careportal_exercise);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_insulincartridgechange:
|
case R.id.careportal_insulincartridgechange:
|
||||||
newDialog.setOptions(insulinchange, R.string.careportal_insulincartridgechange);
|
newDialog.setOptions(INSULINCHANGE, R.string.careportal_insulincartridgechange);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_pumpbatterychange:
|
case R.id.careportal_pumpbatterychange:
|
||||||
newDialog.setOptions(pumpbatterychange, R.string.careportal_pumpbatterychange);
|
newDialog.setOptions(PUMPBATTERYCHANGE, R.string.careportal_pumpbatterychange);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_mealbolus:
|
case R.id.careportal_mealbolus:
|
||||||
newDialog.setOptions(mealbolus, R.string.careportal_mealbolus);
|
newDialog.setOptions(MEALBOLUS, R.string.careportal_mealbolus);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_note:
|
case R.id.careportal_note:
|
||||||
newDialog.setOptions(note, R.string.careportal_note);
|
newDialog.setOptions(NOTE, R.string.careportal_note);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_profileswitch:
|
case R.id.careportal_profileswitch:
|
||||||
profileswitch.executeProfileSwitch = false;
|
PROFILESWITCH.executeProfileSwitch = false;
|
||||||
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
|
newDialog.setOptions(PROFILESWITCH, R.string.careportal_profileswitch);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_pumpsitechange:
|
case R.id.careportal_pumpsitechange:
|
||||||
newDialog.setOptions(sitechange, R.string.careportal_pumpsitechange);
|
newDialog.setOptions(SITECHANGE, R.string.careportal_pumpsitechange);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_question:
|
case R.id.careportal_question:
|
||||||
newDialog.setOptions(question, R.string.careportal_question);
|
newDialog.setOptions(QUESTION, R.string.careportal_question);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_snackbolus:
|
case R.id.careportal_snackbolus:
|
||||||
newDialog.setOptions(snackbolus, R.string.careportal_snackbolus);
|
newDialog.setOptions(SNACKBOLUS, R.string.careportal_snackbolus);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_tempbasalstart:
|
case R.id.careportal_tempbasalstart:
|
||||||
newDialog.setOptions(tempbasalstart, R.string.careportal_tempbasalstart);
|
newDialog.setOptions(TEMPBASALSTART, R.string.careportal_tempbasalstart);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_tempbasalend:
|
case R.id.careportal_tempbasalend:
|
||||||
newDialog.setOptions(tempbasalend, R.string.careportal_tempbasalend);
|
newDialog.setOptions(TEMPBASALEND, R.string.careportal_tempbasalend);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_openapsoffline:
|
case R.id.careportal_openapsoffline:
|
||||||
newDialog.setOptions(openapsoffline, R.string.careportal_openapsoffline);
|
newDialog.setOptions(OPENAPSOFFLINE, R.string.careportal_openapsoffline);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_temporarytarget:
|
case R.id.careportal_temporarytarget:
|
||||||
temptarget.executeTempTarget = false;
|
TEMPTARGET.executeTempTarget = false;
|
||||||
newDialog.setOptions(temptarget, R.string.careportal_temporarytarget);
|
newDialog.setOptions(TEMPTARGET, R.string.careportal_temporarytarget);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
newDialog = null;
|
newDialog = null;
|
||||||
|
|
|
@ -7,8 +7,17 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
|
||||||
public class CareportalPlugin implements PluginBase {
|
public class CareportalPlugin implements PluginBase {
|
||||||
|
|
||||||
boolean fragmentEnabled = true;
|
private boolean fragmentEnabled = true;
|
||||||
boolean fragmentVisible = true;
|
private boolean fragmentVisible = true;
|
||||||
|
|
||||||
|
static CareportalPlugin careportalPlugin;
|
||||||
|
|
||||||
|
static public CareportalPlugin getPlugin() {
|
||||||
|
if (careportalPlugin == null) {
|
||||||
|
careportalPlugin = new CareportalPlugin();
|
||||||
|
}
|
||||||
|
return careportalPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getType() {
|
public int getType() {
|
||||||
|
@ -71,4 +80,9 @@ public class CareportalPlugin implements PluginBase {
|
||||||
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
|
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return R.xml.pref_careportal;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,9 @@ import android.text.format.DateFormat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
@ -52,7 +54,6 @@ import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin;
|
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
|
@ -73,17 +74,11 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
String units;
|
String units;
|
||||||
|
|
||||||
TextView eventTypeText;
|
TextView eventTypeText;
|
||||||
LinearLayout layoutBg;
|
|
||||||
LinearLayout layoutBgSource;
|
|
||||||
LinearLayout layoutInsulin;
|
|
||||||
LinearLayout layoutCarbs;
|
|
||||||
LinearLayout layoutSplit;
|
|
||||||
LinearLayout layoutDuration;
|
|
||||||
LinearLayout layoutPercent;
|
LinearLayout layoutPercent;
|
||||||
LinearLayout layoutAbsolute;
|
LinearLayout layoutAbsolute;
|
||||||
LinearLayout layoutCarbTime;
|
LinearLayout layoutReuse;
|
||||||
LinearLayout layoutProfile;
|
|
||||||
LinearLayout layoutTempTarget;
|
|
||||||
TextView dateButton;
|
TextView dateButton;
|
||||||
TextView timeButton;
|
TextView timeButton;
|
||||||
|
|
||||||
|
@ -94,6 +89,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
EditText notesEdit;
|
EditText notesEdit;
|
||||||
Spinner profileSpinner;
|
Spinner profileSpinner;
|
||||||
Spinner reasonSpinner;
|
Spinner reasonSpinner;
|
||||||
|
Button reuseButton;
|
||||||
|
|
||||||
NumberPicker editBg;
|
NumberPicker editBg;
|
||||||
NumberPicker editCarbs;
|
NumberPicker editCarbs;
|
||||||
|
@ -104,6 +100,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
NumberPicker editAbsolute;
|
NumberPicker editAbsolute;
|
||||||
NumberPicker editCarbTime;
|
NumberPicker editCarbTime;
|
||||||
NumberPicker editTemptarget;
|
NumberPicker editTemptarget;
|
||||||
|
NumberPicker editPercentage;
|
||||||
|
NumberPicker editTimeshift;
|
||||||
|
|
||||||
Date eventTime;
|
Date eventTime;
|
||||||
|
|
||||||
|
@ -140,21 +138,15 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
if (options==null) return null;
|
||||||
getDialog().setTitle(getString(options.eventName));
|
getDialog().setTitle(getString(options.eventName));
|
||||||
setStyle(DialogFragment.STYLE_NORMAL, getTheme());
|
setStyle(DialogFragment.STYLE_NORMAL, getTheme());
|
||||||
View view = inflater.inflate(R.layout.careportal_newnstreatment_dialog, container, false);
|
View view = inflater.inflate(R.layout.careportal_newnstreatment_dialog, container, false);
|
||||||
|
|
||||||
layoutBg = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_bg_layout);
|
|
||||||
layoutBgSource = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_bgsource_layout);
|
|
||||||
layoutInsulin = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_insulin_layout);
|
|
||||||
layoutCarbs = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_carbs_layout);
|
|
||||||
layoutSplit = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_split_layout);
|
|
||||||
layoutDuration = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_duration_layout);
|
|
||||||
layoutPercent = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_percent_layout);
|
layoutPercent = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_percent_layout);
|
||||||
layoutAbsolute = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_absolute_layout);
|
layoutAbsolute = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_absolute_layout);
|
||||||
layoutCarbTime = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_carbtime_layout);
|
|
||||||
layoutProfile = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_profile_layout);
|
layoutReuse = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_reuse_layout);
|
||||||
layoutTempTarget = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout);
|
|
||||||
|
|
||||||
eventTypeText = (TextView) view.findViewById(R.id.careportal_newnstreatment_eventtype);
|
eventTypeText = (TextView) view.findViewById(R.id.careportal_newnstreatment_eventtype);
|
||||||
eventTypeText.setText(event);
|
eventTypeText.setText(event);
|
||||||
|
@ -164,6 +156,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
otherRadioButton = (RadioButton) view.findViewById(R.id.careportal_newnstreatment_other);
|
otherRadioButton = (RadioButton) view.findViewById(R.id.careportal_newnstreatment_other);
|
||||||
profileSpinner = (Spinner) view.findViewById(R.id.careportal_newnstreatment_profile);
|
profileSpinner = (Spinner) view.findViewById(R.id.careportal_newnstreatment_profile);
|
||||||
|
|
||||||
|
reuseButton = (Button) view.findViewById(R.id.careportal_newnstreatment_reusebutton);
|
||||||
|
|
||||||
notesEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_notes);
|
notesEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_notes);
|
||||||
|
|
||||||
reasonSpinner = (Spinner) view.findViewById(R.id.careportal_newnstreatment_temptarget_reason);
|
reasonSpinner = (Spinner) view.findViewById(R.id.careportal_newnstreatment_temptarget_reason);
|
||||||
|
@ -194,32 +188,57 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
profileSpinner.setSelection(p);
|
profileSpinner.setSelection(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile != null ? profile.getUnits() : Constants.MGDL);
|
||||||
|
|
||||||
// temp target
|
// temp target
|
||||||
ArrayList<CharSequence> reasonList = new ArrayList<CharSequence>();
|
final ArrayList<CharSequence> reasonList = new ArrayList<CharSequence>();
|
||||||
|
reasonList.add(MainApp.sResources.getString(R.string.manual));
|
||||||
reasonList.add(MainApp.sResources.getString(R.string.eatingsoon));
|
reasonList.add(MainApp.sResources.getString(R.string.eatingsoon));
|
||||||
reasonList.add(MainApp.sResources.getString(R.string.activity));
|
reasonList.add(MainApp.sResources.getString(R.string.activity));
|
||||||
reasonList.add(MainApp.sResources.getString(R.string.manual));
|
|
||||||
ArrayAdapter<CharSequence> adapterReason = new ArrayAdapter<CharSequence>(getContext(),
|
ArrayAdapter<CharSequence> adapterReason = new ArrayAdapter<CharSequence>(getContext(),
|
||||||
R.layout.spinner_centered, reasonList);
|
R.layout.spinner_centered, reasonList);
|
||||||
reasonSpinner.setAdapter(adapterReason);
|
reasonSpinner.setAdapter(adapterReason);
|
||||||
|
reasonSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
double defaultDuration = 0;
|
||||||
|
double defaultTarget = 0;
|
||||||
|
if(profile!=null){
|
||||||
|
defaultTarget = bg.doubleValue();
|
||||||
|
}
|
||||||
|
boolean erase = false;
|
||||||
|
|
||||||
|
if(MainApp.sResources.getString(R.string.eatingsoon).equals(reasonList.get(position))){
|
||||||
|
defaultDuration = SP.getDouble(R.string.key_eatingsoon_duration, 0d);
|
||||||
|
defaultTarget = SP.getDouble(R.string.key_eatingsoon_target, 0d);;
|
||||||
|
} else if (MainApp.sResources.getString(R.string.activity).equals(reasonList.get(position))){
|
||||||
|
defaultDuration = SP.getDouble(R.string.key_activity_duration, 0d);;
|
||||||
|
defaultTarget = SP.getDouble(R.string.key_activity_target, 0d);;
|
||||||
|
} else {
|
||||||
|
defaultDuration = 0;
|
||||||
|
erase = true;
|
||||||
|
}
|
||||||
|
if(defaultTarget != 0 || erase){
|
||||||
|
editTemptarget.setValue(defaultTarget);
|
||||||
|
}
|
||||||
|
if(defaultDuration != 0){
|
||||||
|
editDuration.setValue(defaultDuration);
|
||||||
|
} else if (erase){
|
||||||
|
editDuration.setValue(0d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// bg
|
// bg
|
||||||
bgUnitsView.setText(units);
|
bgUnitsView.setText(units);
|
||||||
|
|
||||||
Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile != null ? profile.getUnits() : Constants.MGDL);
|
TextWatcher bgTextWatcher = new TextWatcher() {
|
||||||
editBg = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_bginput);
|
|
||||||
editTemptarget = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_temptarget);
|
|
||||||
if (profile == null) {
|
|
||||||
editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false);
|
|
||||||
editTemptarget.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false);
|
|
||||||
} else if (profile.getUnits().equals(Constants.MMOL)) {
|
|
||||||
editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false);
|
|
||||||
editTemptarget.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false);
|
|
||||||
} else {
|
|
||||||
editBg.setParams(bg, 0d, 500d, 1d, new DecimalFormat("0"), false);
|
|
||||||
editTemptarget.setParams(bg, 0d, 500d, 1d, new DecimalFormat("0"), false);
|
|
||||||
}
|
|
||||||
editBg.addTextChangedListener(new TextWatcher() {
|
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,8 +248,20 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
if (sensorRadioButton.isChecked()) meterRadioButton.setChecked(true);
|
if (sensorRadioButton.isChecked()) meterRadioButton.setChecked(true);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
editBg = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_bginput);
|
||||||
|
editTemptarget = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_temptarget);
|
||||||
|
if (profile == null) {
|
||||||
|
editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, bgTextWatcher);
|
||||||
|
editTemptarget.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false);
|
||||||
|
} else if (profile.getUnits().equals(Constants.MMOL)) {
|
||||||
|
editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, bgTextWatcher);
|
||||||
|
editTemptarget.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false);
|
||||||
|
} else {
|
||||||
|
editBg.setParams(bg, 0d, 500d, 1d, new DecimalFormat("0"), false, bgTextWatcher);
|
||||||
|
editTemptarget.setParams(bg, 0d, 500d, 1d, new DecimalFormat("0"), false);
|
||||||
|
}
|
||||||
sensorRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
sensorRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
@ -252,10 +283,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
editDuration = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_durationinput);
|
editDuration = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_durationinput);
|
||||||
editDuration.setParams(0d, 0d, 24 * 60d, 10d, new DecimalFormat("0"), false);
|
editDuration.setParams(0d, 0d, 24 * 60d, 10d, new DecimalFormat("0"), false);
|
||||||
|
|
||||||
Integer maxPercent = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalPercentOnlyForCheckLimit);
|
TextWatcher percentTextWatcher = new TextWatcher() {
|
||||||
editPercent = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_percentinput);
|
|
||||||
editPercent.setParams(0d, 0d, (double) maxPercent, 5d, new DecimalFormat("0"), true);
|
|
||||||
editPercent.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
}
|
}
|
||||||
|
@ -271,12 +299,13 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
layoutPercent.setVisibility(View.VISIBLE);
|
layoutPercent.setVisibility(View.VISIBLE);
|
||||||
layoutAbsolute.setVisibility(View.GONE);
|
layoutAbsolute.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
Double maxAbsolute = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalAbsoluteOnlyForCheckLimit);
|
Integer maxPercent = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalPercentOnlyForCheckLimit);
|
||||||
editAbsolute = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_absoluteinput);
|
editPercent = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_percentinput);
|
||||||
editAbsolute.setParams(0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true);
|
editPercent.setParams(0d, 0d, (double) maxPercent, 5d, new DecimalFormat("0"), true, percentTextWatcher);
|
||||||
editAbsolute.addTextChangedListener(new TextWatcher() {
|
|
||||||
|
TextWatcher absoluteTextWatcher = new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
}
|
}
|
||||||
|
@ -292,23 +321,50 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
layoutPercent.setVisibility(View.GONE);
|
layoutPercent.setVisibility(View.GONE);
|
||||||
layoutAbsolute.setVisibility(View.VISIBLE);
|
layoutAbsolute.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
Double maxAbsolute = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalAbsoluteOnlyForCheckLimit);
|
||||||
|
editAbsolute = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_absoluteinput);
|
||||||
|
editAbsolute.setParams(0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true, absoluteTextWatcher);
|
||||||
|
|
||||||
editCarbTime = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_carbtimeinput);
|
editCarbTime = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_carbtimeinput);
|
||||||
editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false);
|
editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false);
|
||||||
|
|
||||||
|
editPercentage = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_percentage);
|
||||||
|
editPercentage.setParams(100d, (double) Constants.CPP_MIN_PERCENTAGE, (double) Constants.CPP_MAX_PERCENTAGE, 1d, new DecimalFormat("0"), false);
|
||||||
|
|
||||||
showOrHide(layoutBg, options.bg);
|
editTimeshift = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_timeshift);
|
||||||
showOrHide(layoutBgSource, options.bg);
|
editTimeshift.setParams(0d, (double) Constants.CPP_MIN_TIMESHIFT, (double) Constants.CPP_MAX_TIMESHIFT, 1d, new DecimalFormat("0"), false);
|
||||||
showOrHide(layoutInsulin, options.insulin);
|
|
||||||
showOrHide(layoutCarbs, options.carbs);
|
ProfileSwitch ps = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
showOrHide(layoutSplit, options.split);
|
if(ps!=null && ps.isCPP){
|
||||||
showOrHide(layoutDuration, options.duration);
|
final int percentage = ps.percentage;
|
||||||
|
final int timeshift = ps.timeshift;
|
||||||
|
reuseButton.setText(reuseButton.getText() + " " + percentage + "% " + timeshift +"h");
|
||||||
|
reuseButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
editPercentage.setValue((double)percentage);
|
||||||
|
editTimeshift.setValue((double)timeshift);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_eventtime_layout), options.date);
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_bg_layout), options.bg);
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_bgsource_layout), options.bg);
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_insulin_layout), options.insulin);
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_carbs_layout), options.carbs);
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_split_layout), options.split);
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_duration_layout), options.duration);
|
||||||
showOrHide(layoutPercent, options.percent);
|
showOrHide(layoutPercent, options.percent);
|
||||||
showOrHide(layoutAbsolute, options.absolute);
|
showOrHide(layoutAbsolute, options.absolute);
|
||||||
showOrHide(layoutCarbTime, options.prebolus);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_carbtime_layout), options.prebolus);
|
||||||
showOrHide(layoutProfile, options.profile);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_profile_layout), options.profile);
|
||||||
showOrHide(layoutTempTarget, options.tempTarget);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_percentage_layout), options.profile);
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_timeshift_layout), options.profile);
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps!=null && ps.isCPP);
|
||||||
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -451,7 +507,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
allowZeroDuration = true;
|
allowZeroDuration = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (SafeParse.stringToDouble(editBg.getText()) != 0d) {
|
if (options.bg && SafeParse.stringToDouble(editBg.getText()) != 0d) {
|
||||||
data.put("glucose", SafeParse.stringToDouble(editBg.getText()));
|
data.put("glucose", SafeParse.stringToDouble(editBg.getText()));
|
||||||
if (meterRadioButton.isChecked()) data.put("glucoseType", "Finger");
|
if (meterRadioButton.isChecked()) data.put("glucoseType", "Finger");
|
||||||
if (sensorRadioButton.isChecked()) data.put("glucoseType", "Sensor");
|
if (sensorRadioButton.isChecked()) data.put("glucoseType", "Sensor");
|
||||||
|
@ -469,6 +525,10 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
data.put("absolute", SafeParse.stringToDouble(editAbsolute.getText()));
|
data.put("absolute", SafeParse.stringToDouble(editAbsolute.getText()));
|
||||||
if (options.profile && profileSpinner.getSelectedItem() != null)
|
if (options.profile && profileSpinner.getSelectedItem() != null)
|
||||||
data.put("profile", profileSpinner.getSelectedItem().toString());
|
data.put("profile", profileSpinner.getSelectedItem().toString());
|
||||||
|
if (options.profile)
|
||||||
|
data.put("percentage", SafeParse.stringToInt(editPercentage.getText()));
|
||||||
|
if (options.profile)
|
||||||
|
data.put("timeshift", SafeParse.stringToInt(editTimeshift.getText()));
|
||||||
if (SafeParse.stringToDouble(editCarbTime.getText()) != 0d)
|
if (SafeParse.stringToDouble(editCarbTime.getText()) != 0d)
|
||||||
data.put("preBolus", SafeParse.stringToDouble(editCarbTime.getText()));
|
data.put("preBolus", SafeParse.stringToDouble(editCarbTime.getText()));
|
||||||
if (!notesEdit.getText().toString().equals(""))
|
if (!notesEdit.getText().toString().equals(""))
|
||||||
|
@ -556,6 +616,18 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
ret += data.get("profile");
|
ret += data.get("profile");
|
||||||
ret += "\n";
|
ret += "\n";
|
||||||
}
|
}
|
||||||
|
if (data.has("percentage")) {
|
||||||
|
ret += getString(R.string.careportal_newnstreatment_percentage_label);
|
||||||
|
ret += ": ";
|
||||||
|
ret += data.get("percentage");
|
||||||
|
ret += " %\n";
|
||||||
|
}
|
||||||
|
if (data.has("timeshift")) {
|
||||||
|
ret += getString(R.string.careportal_newnstreatment_timeshift_label);
|
||||||
|
ret += ": ";
|
||||||
|
ret += data.get("timeshift");
|
||||||
|
ret += " h\n";
|
||||||
|
}
|
||||||
if (data.has("targetBottom") && data.has("targetTop")) {
|
if (data.has("targetBottom") && data.has("targetTop")) {
|
||||||
ret += getString(R.string.target_range);
|
ret += getString(R.string.target_range);
|
||||||
ret += " ";
|
ret += " ";
|
||||||
|
@ -594,7 +666,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
if (options.executeProfileSwitch) {
|
if (options.executeProfileSwitch) {
|
||||||
if (data.has("profile")) {
|
if (data.has("profile")) {
|
||||||
try {
|
try {
|
||||||
doProfileSwitch(profileStore, data.getString("profile"), data.getInt("duration"));
|
doProfileSwitch(profileStore, data.getString("profile"), data.getInt("duration"), data.getInt("percentage"), data.getInt("timeshift"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -641,7 +713,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration) {
|
public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) {
|
||||||
sHandler.post(new Runnable() {
|
sHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -652,17 +724,14 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
|
profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
|
||||||
profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
||||||
profileSwitch.durationInMinutes = duration;
|
profileSwitch.durationInMinutes = duration;
|
||||||
if (ConfigBuilderPlugin.getActiveProfileInterface() instanceof CircadianPercentageProfilePlugin) {
|
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
||||||
CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) ConfigBuilderPlugin.getActiveProfileInterface();
|
profileSwitch.timeshift = timeshift;
|
||||||
profileSwitch.isCPP = true;
|
profileSwitch.percentage = percentage;
|
||||||
profileSwitch.timeshift = cpp.timeshift;
|
|
||||||
profileSwitch.percentage = cpp.percentage;
|
|
||||||
}
|
|
||||||
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
PumpInterface pump = MainApp.getConfigBuilder();
|
||||||
if (pump != null) {
|
if (pump != null) {
|
||||||
pump.setNewBasalProfile(profileStore.getSpecificProfile(profileName));
|
pump.setNewBasalProfile(profileSwitch.getProfileObject());
|
||||||
MainApp.bus().post(new EventNewBasalProfile());
|
MainApp.bus().post(new EventNewBasalProfile());
|
||||||
} else {
|
} else {
|
||||||
log.error("No active pump selected");
|
log.error("No active pump selected");
|
||||||
|
@ -672,4 +741,37 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) {
|
||||||
|
sHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
|
if (profileSwitch != null) {
|
||||||
|
profileSwitch = new ProfileSwitch();
|
||||||
|
profileSwitch.date = System.currentTimeMillis();
|
||||||
|
profileSwitch.source = Source.USER;
|
||||||
|
profileSwitch.profileName = MainApp.getConfigBuilder().getProfileName(System.currentTimeMillis(), false);
|
||||||
|
profileSwitch.profileJson = MainApp.getConfigBuilder().getProfile().getData().toString();
|
||||||
|
profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
||||||
|
profileSwitch.durationInMinutes = duration;
|
||||||
|
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
||||||
|
profileSwitch.timeshift = timeshift;
|
||||||
|
profileSwitch.percentage = percentage;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
||||||
|
|
||||||
|
PumpInterface pump = MainApp.getConfigBuilder();
|
||||||
|
if (pump != null) {
|
||||||
|
pump.setNewBasalProfile(profileSwitch.getProfileObject());
|
||||||
|
MainApp.bus().post(new EventNewBasalProfile());
|
||||||
|
} else {
|
||||||
|
log.error("No active pump selected");
|
||||||
|
}
|
||||||
|
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||||
|
} else {
|
||||||
|
log.error("No profile switch existing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ package info.nightscout.androidaps.plugins.Careportal;
|
||||||
public class OptionsToShow {
|
public class OptionsToShow {
|
||||||
public int eventType;
|
public int eventType;
|
||||||
public int eventName;
|
public int eventName;
|
||||||
|
public boolean date;
|
||||||
public boolean bg;
|
public boolean bg;
|
||||||
public boolean insulin;
|
public boolean insulin;
|
||||||
public boolean carbs;
|
public boolean carbs;
|
||||||
|
@ -22,29 +23,63 @@ public class OptionsToShow {
|
||||||
public boolean executeProfileSwitch = false;
|
public boolean executeProfileSwitch = false;
|
||||||
public boolean executeTempTarget = false;
|
public boolean executeTempTarget = false;
|
||||||
|
|
||||||
public OptionsToShow(int eventType,
|
public OptionsToShow(int eventType, int eventName) {
|
||||||
int eventName,
|
|
||||||
boolean bg,
|
|
||||||
boolean insulin,
|
|
||||||
boolean carbs,
|
|
||||||
boolean prebolus,
|
|
||||||
boolean duration,
|
|
||||||
boolean percent,
|
|
||||||
boolean absolute,
|
|
||||||
boolean profile,
|
|
||||||
boolean split,
|
|
||||||
boolean tempTarget) {
|
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
this.eventName = eventName;
|
this.eventName = eventName;
|
||||||
this.bg = bg;
|
}
|
||||||
this.insulin = insulin;
|
|
||||||
this.carbs = carbs;
|
public OptionsToShow date() {
|
||||||
this.prebolus = prebolus;
|
date = true;
|
||||||
this.duration = duration;
|
return this;
|
||||||
this.percent = percent;
|
}
|
||||||
this.absolute = absolute;
|
|
||||||
this.profile = profile;
|
public OptionsToShow bg() {
|
||||||
this.split = split;
|
bg = true;
|
||||||
this.tempTarget = tempTarget;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsToShow insulin() {
|
||||||
|
insulin = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsToShow carbs() {
|
||||||
|
carbs = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsToShow prebolus() {
|
||||||
|
prebolus = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsToShow duration() {
|
||||||
|
duration = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsToShow percent() {
|
||||||
|
percent = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsToShow absolute() {
|
||||||
|
absolute = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsToShow profile() {
|
||||||
|
profile = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsToShow split() {
|
||||||
|
split = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsToShow tempTarget() {
|
||||||
|
tempTarget = true;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.ConfigBuilder;
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -10,17 +11,20 @@ import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.PreferencesActivity;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
|
@ -55,6 +59,8 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
TextView pumpLabel;
|
TextView pumpLabel;
|
||||||
ListView loopListView;
|
ListView loopListView;
|
||||||
TextView loopLabel;
|
TextView loopLabel;
|
||||||
|
ListView treatmentsListView;
|
||||||
|
TextView treatmentsLabel;
|
||||||
ListView profileListView;
|
ListView profileListView;
|
||||||
TextView profileLabel;
|
TextView profileLabel;
|
||||||
ListView apsListView;
|
ListView apsListView;
|
||||||
|
@ -71,6 +77,7 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
PluginCustomAdapter bgsourceDataAdapter = null;
|
PluginCustomAdapter bgsourceDataAdapter = null;
|
||||||
PluginCustomAdapter pumpDataAdapter = null;
|
PluginCustomAdapter pumpDataAdapter = null;
|
||||||
PluginCustomAdapter loopDataAdapter = null;
|
PluginCustomAdapter loopDataAdapter = null;
|
||||||
|
PluginCustomAdapter treatmentDataAdapter = null;
|
||||||
PluginCustomAdapter profileDataAdapter = null;
|
PluginCustomAdapter profileDataAdapter = null;
|
||||||
PluginCustomAdapter apsDataAdapter = null;
|
PluginCustomAdapter apsDataAdapter = null;
|
||||||
PluginCustomAdapter constraintsDataAdapter = null;
|
PluginCustomAdapter constraintsDataAdapter = null;
|
||||||
|
@ -79,6 +86,7 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
try {
|
||||||
View view = inflater.inflate(R.layout.configbuilder_fragment, container, false);
|
View view = inflater.inflate(R.layout.configbuilder_fragment, container, false);
|
||||||
|
|
||||||
insulinListView = (ListView) view.findViewById(R.id.configbuilder_insulinlistview);
|
insulinListView = (ListView) view.findViewById(R.id.configbuilder_insulinlistview);
|
||||||
|
@ -89,6 +97,8 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
pumpLabel = (TextView) view.findViewById(R.id.configbuilder_pumplabel);
|
pumpLabel = (TextView) view.findViewById(R.id.configbuilder_pumplabel);
|
||||||
loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview);
|
loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview);
|
||||||
loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel);
|
loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel);
|
||||||
|
treatmentsListView = (ListView) view.findViewById(R.id.configbuilder_treatmentslistview);
|
||||||
|
treatmentsLabel = (TextView) view.findViewById(R.id.configbuilder_treatmentslabel);
|
||||||
profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview);
|
profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview);
|
||||||
profileLabel = (TextView) view.findViewById(R.id.configbuilder_profilelabel);
|
profileLabel = (TextView) view.findViewById(R.id.configbuilder_profilelabel);
|
||||||
apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview);
|
apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview);
|
||||||
|
@ -120,6 +130,11 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
unlock.setVisibility(View.GONE);
|
unlock.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
return view;
|
return view;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setViews() {
|
void setViews() {
|
||||||
|
@ -141,6 +156,11 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
setListViewHeightBasedOnChildren(loopListView);
|
setListViewHeightBasedOnChildren(loopListView);
|
||||||
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.LOOP).size() == 0)
|
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.LOOP).size() == 0)
|
||||||
loopLabel.setVisibility(View.GONE);
|
loopLabel.setVisibility(View.GONE);
|
||||||
|
treatmentDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.TREATMENT), PluginBase.TREATMENT);
|
||||||
|
treatmentsListView.setAdapter(treatmentDataAdapter);
|
||||||
|
setListViewHeightBasedOnChildren(treatmentsListView);
|
||||||
|
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.TREATMENT).size() == 0)
|
||||||
|
treatmentsLabel.setVisibility(View.GONE);
|
||||||
profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginBase.PROFILE), PluginBase.PROFILE);
|
profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginBase.PROFILE), PluginBase.PROFILE);
|
||||||
profileListView.setAdapter(profileDataAdapter);
|
profileListView.setAdapter(profileDataAdapter);
|
||||||
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.PROFILE).size() == 0)
|
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.PROFILE).size() == 0)
|
||||||
|
@ -177,7 +197,7 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
public PluginCustomAdapter(Context context, int textViewResourceId,
|
public PluginCustomAdapter(Context context, int textViewResourceId,
|
||||||
ArrayList<PluginBase> pluginList, int type) {
|
ArrayList<PluginBase> pluginList, int type) {
|
||||||
super(context, textViewResourceId, pluginList);
|
super(context, textViewResourceId, pluginList);
|
||||||
this.pluginList = new ArrayList<PluginBase>();
|
this.pluginList = new ArrayList<>();
|
||||||
this.pluginList.addAll(pluginList);
|
this.pluginList.addAll(pluginList);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
@ -186,12 +206,14 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
TextView name;
|
TextView name;
|
||||||
CheckBox checkboxEnabled;
|
CheckBox checkboxEnabled;
|
||||||
CheckBox checkboxVisible;
|
CheckBox checkboxVisible;
|
||||||
|
ImageView settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View view, ViewGroup parent) {
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
|
|
||||||
PluginViewHolder holder = null;
|
PluginViewHolder holder = null;
|
||||||
|
PluginBase plugin = pluginList.get(position);
|
||||||
|
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.configbuilder_simpleitem, null);
|
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.configbuilder_simpleitem, null);
|
||||||
|
@ -200,6 +222,13 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
holder.name = (TextView) view.findViewById(R.id.configbuilder_simpleitem_name);
|
holder.name = (TextView) view.findViewById(R.id.configbuilder_simpleitem_name);
|
||||||
holder.checkboxEnabled = (CheckBox) view.findViewById(R.id.configbuilder_simpleitem_checkboxenabled);
|
holder.checkboxEnabled = (CheckBox) view.findViewById(R.id.configbuilder_simpleitem_checkboxenabled);
|
||||||
holder.checkboxVisible = (CheckBox) view.findViewById(R.id.configbuilder_simpleitem_checkboxvisible);
|
holder.checkboxVisible = (CheckBox) view.findViewById(R.id.configbuilder_simpleitem_checkboxvisible);
|
||||||
|
holder.settings = (ImageView) view.findViewById(R.id.configbuilder_simpleitem_settings);
|
||||||
|
|
||||||
|
if (plugin.isEnabled(type) && plugin.getPreferencesId() != -1)
|
||||||
|
holder.settings.setVisibility(View.VISIBLE);
|
||||||
|
else
|
||||||
|
holder.settings.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
view.setTag(holder);
|
view.setTag(holder);
|
||||||
|
|
||||||
holder.checkboxEnabled.setOnClickListener(new View.OnClickListener() {
|
holder.checkboxEnabled.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -227,17 +256,48 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
getPlugin().logPluginStatus();
|
getPlugin().logPluginStatus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
holder.settings.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
final PluginBase plugin = (PluginBase) v.getTag();
|
||||||
|
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Intent i = new Intent(getContext(), PreferencesActivity.class);
|
||||||
|
i.putExtra("id", plugin.getPreferencesId());
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
holder.name.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
final PluginBase plugin = (PluginBase) v.getTag();
|
||||||
|
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Intent i = new Intent(getContext(), PreferencesActivity.class);
|
||||||
|
i.putExtra("id", plugin.getPreferencesId());
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
holder = (PluginViewHolder) view.getTag();
|
holder = (PluginViewHolder) view.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginBase plugin = pluginList.get(position);
|
|
||||||
holder.name.setText(plugin.getName());
|
holder.name.setText(plugin.getName());
|
||||||
holder.checkboxEnabled.setChecked(plugin.isEnabled(type));
|
holder.checkboxEnabled.setChecked(plugin.isEnabled(type));
|
||||||
holder.checkboxVisible.setChecked(plugin.isVisibleInTabs(type));
|
holder.checkboxVisible.setChecked(plugin.isVisibleInTabs(type));
|
||||||
holder.name.setTag(plugin);
|
holder.name.setTag(plugin);
|
||||||
holder.checkboxEnabled.setTag(plugin);
|
holder.checkboxEnabled.setTag(plugin);
|
||||||
holder.checkboxVisible.setTag(plugin);
|
holder.checkboxVisible.setTag(plugin);
|
||||||
|
holder.settings.setTag(plugin);
|
||||||
|
|
||||||
if (!plugin.canBeHidden(type)) {
|
if (!plugin.canBeHidden(type)) {
|
||||||
holder.checkboxEnabled.setEnabled(false);
|
holder.checkboxEnabled.setEnabled(false);
|
||||||
|
|
|
@ -146,6 +146,11 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
// Always visible
|
// Always visible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
pluginList = MainApp.getPluginsList();
|
pluginList = MainApp.getPluginsList();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
@ -301,7 +306,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.PUMP);
|
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.PUMP);
|
||||||
activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PUMP);
|
activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PUMP);
|
||||||
if (activePump == null)
|
if (activePump == null)
|
||||||
activePump = VirtualPumpPlugin.getInstance(); // for NSClient build
|
activePump = VirtualPumpPlugin.getPlugin(); // for NSClient build
|
||||||
if (Config.logConfigBuilder)
|
if (Config.logConfigBuilder)
|
||||||
log.debug("Selected pump interface: " + ((PluginBase) activePump).getName());
|
log.debug("Selected pump interface: " + ((PluginBase) activePump).getName());
|
||||||
for (PluginBase p : pluginsInCategory) {
|
for (PluginBase p : pluginsInCategory) {
|
||||||
|
@ -404,9 +409,14 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isThisProfileSet(Profile profile) {
|
public boolean isThisProfileSet(Profile profile) {
|
||||||
if (activePump != null)
|
if (activePump != null) {
|
||||||
return activePump.isThisProfileSet(profile);
|
boolean result = activePump.isThisProfileSet(profile);
|
||||||
else return true;
|
if (result == false) {
|
||||||
|
log.debug("Current profile: " + getProfile().getData().toString());
|
||||||
|
log.debug("New profile: " + profile.getData().toString());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -559,7 +569,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
|
|
||||||
if (Config.logCongigBuilderActions)
|
if (Config.logCongigBuilderActions)
|
||||||
log.debug("applyAPSRequest: " + request.toString());
|
log.debug("applyAPSRequest: " + request.toString());
|
||||||
if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - getBaseBasalRate()) < 0.05) {
|
if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - getBaseBasalRate()) < getPumpDescription().basalStep) {
|
||||||
if (isTempBasalInProgress()) {
|
if (isTempBasalInProgress()) {
|
||||||
if (Config.logCongigBuilderActions)
|
if (Config.logCongigBuilderActions)
|
||||||
log.debug("applyAPSRequest: cancelTempBasal()");
|
log.debug("applyAPSRequest: cancelTempBasal()");
|
||||||
|
@ -574,7 +584,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
if (Config.logCongigBuilderActions)
|
if (Config.logCongigBuilderActions)
|
||||||
log.debug("applyAPSRequest: Basal set correctly");
|
log.debug("applyAPSRequest: Basal set correctly");
|
||||||
}
|
}
|
||||||
} else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRateHistory()) < 0.05) {
|
} else if (isTempBasalInProgress()
|
||||||
|
&& getTempBasalRemainingMinutesFromHistory() > 5
|
||||||
|
&& Math.abs(request.rate - getTempBasalAbsoluteRateHistory()) < getPumpDescription().basalStep) {
|
||||||
result = new PumpEnactResult();
|
result = new PumpEnactResult();
|
||||||
result.absolute = getTempBasalAbsoluteRateHistory();
|
result.absolute = getTempBasalAbsoluteRateHistory();
|
||||||
result.duration = getTempBasalFromHistory(System.currentTimeMillis()).getPlannedRemainingMinutes();
|
result.duration = getTempBasalFromHistory(System.currentTimeMillis()).getPlannedRemainingMinutes();
|
||||||
|
@ -934,10 +946,14 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProfileName(long time) {
|
public String getProfileName(long time) {
|
||||||
|
return getProfileName(time, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProfileName(long time, boolean customized) {
|
||||||
ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time);
|
ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time);
|
||||||
if (profileSwitch != null) {
|
if (profileSwitch != null) {
|
||||||
if (profileSwitch.profileJson != null) {
|
if (profileSwitch.profileJson != null) {
|
||||||
return profileSwitch.profileName;
|
return customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName;
|
||||||
} else {
|
} else {
|
||||||
Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName);
|
Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName);
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
|
@ -957,7 +973,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProfileUnits() {
|
public String getProfileUnits() {
|
||||||
return activeProfile.getUnits();
|
return getProfile().getUnits();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile getProfile(long time) {
|
public Profile getProfile(long time) {
|
||||||
|
@ -993,7 +1009,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
MainApp.bus().post(new EventNewNotification(nobasal));
|
MainApp.bus().post(new EventNewNotification(nobasal));
|
||||||
Notification notarget = new Notification(Notification.TARGET_MISSING, MainApp.sResources.getString(R.string.targetmissing), Notification.URGENT);
|
Notification notarget = new Notification(Notification.TARGET_MISSING, MainApp.sResources.getString(R.string.targetmissing), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notarget));
|
MainApp.bus().post(new EventNewNotification(notarget));
|
||||||
return new Profile(new JSONObject("{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"20\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"20\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"6\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"8\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}}"));
|
return new Profile(new JSONObject("{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"20\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"20\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"6\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"8\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}}"), 100, 0);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class DetailedBolusInfoStorage {
|
||||||
private static List<DetailedBolusInfo> store = new ArrayList<>();
|
private static List<DetailedBolusInfo> store = new ArrayList<>();
|
||||||
|
|
||||||
public static void add(DetailedBolusInfo detailedBolusInfo) {
|
public static void add(DetailedBolusInfo detailedBolusInfo) {
|
||||||
log.debug("Bolus info stored: " + new Date(detailedBolusInfo.date).toLocaleString());
|
log.debug("Stored bolus info: " + detailedBolusInfo);
|
||||||
store.add(detailedBolusInfo);
|
store.add(detailedBolusInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class DetailedBolusInfoStorage {
|
||||||
DetailedBolusInfo found = null;
|
DetailedBolusInfo found = null;
|
||||||
for (int i = 0; i < store.size(); i++) {
|
for (int i = 0; i < store.size(); i++) {
|
||||||
long infoTime = store.get(i).date;
|
long infoTime = store.get(i).date;
|
||||||
log.debug("Existing info: " + new Date(infoTime).toLocaleString());
|
log.debug("Existing bolus info: " + store.get(i));
|
||||||
if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) {
|
if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) {
|
||||||
found = store.get(i);
|
found = store.get(i);
|
||||||
break;
|
break;
|
||||||
|
@ -42,7 +42,7 @@ public class DetailedBolusInfoStorage {
|
||||||
for (int i = 0; i < store.size(); i++) {
|
for (int i = 0; i < store.size(); i++) {
|
||||||
long infoTime = store.get(i).date;
|
long infoTime = store.get(i).date;
|
||||||
if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) {
|
if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) {
|
||||||
log.debug("Removing info: " + new Date(infoTime).toLocaleString());
|
log.debug("Removing bolus info: " + store.get(i));
|
||||||
store.remove(i);
|
store.remove(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ import android.widget.CheckBox;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -27,15 +29,6 @@ import info.nightscout.androidaps.R;
|
||||||
public class ObjectivesFragment extends Fragment {
|
public class ObjectivesFragment extends Fragment {
|
||||||
private static Logger log = LoggerFactory.getLogger(ObjectivesFragment.class);
|
private static Logger log = LoggerFactory.getLogger(ObjectivesFragment.class);
|
||||||
|
|
||||||
private static ObjectivesPlugin objectivesPlugin;
|
|
||||||
|
|
||||||
public static ObjectivesPlugin getPlugin() {
|
|
||||||
if (objectivesPlugin == null) {
|
|
||||||
objectivesPlugin = new ObjectivesPlugin();
|
|
||||||
}
|
|
||||||
return objectivesPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
RecyclerView recyclerView;
|
RecyclerView recyclerView;
|
||||||
LinearLayoutManager llm;
|
LinearLayoutManager llm;
|
||||||
CheckBox enableFake;
|
CheckBox enableFake;
|
||||||
|
@ -59,7 +52,7 @@ public class ObjectivesFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ObjectiveViewHolder holder, int position) {
|
public void onBindViewHolder(ObjectiveViewHolder holder, int position) {
|
||||||
ObjectivesPlugin.Objective o = objectives.get(position);
|
ObjectivesPlugin.Objective o = objectives.get(position);
|
||||||
ObjectivesPlugin.RequirementResult requirementsMet = getPlugin().requirementsMet(position);
|
ObjectivesPlugin.RequirementResult requirementsMet = ObjectivesPlugin.getPlugin().requirementsMet(position);
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
holder.position.setText(String.valueOf(position + 1));
|
holder.position.setText(String.valueOf(position + 1));
|
||||||
holder.objective.setText(o.objective);
|
holder.objective.setText(o.objective);
|
||||||
|
@ -83,7 +76,7 @@ public class ObjectivesFragment extends Fragment {
|
||||||
holder.verifyButton.setOnClickListener(new View.OnClickListener() {
|
holder.verifyButton.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
ObjectivesPlugin.Objective o = (ObjectivesPlugin.Objective) v.getTag();
|
ObjectivesPlugin.Objective o = (ObjectivesPlugin.Objective) v.getTag();
|
||||||
if (getPlugin().requirementsMet(o.num).done || enableFake.isChecked()) {
|
if (ObjectivesPlugin.getPlugin().requirementsMet(o.num).done || enableFake.isChecked()) {
|
||||||
o.accomplished = new Date();
|
o.accomplished = new Date();
|
||||||
updateGUI();
|
updateGUI();
|
||||||
ObjectivesPlugin.saveProgress();
|
ObjectivesPlugin.saveProgress();
|
||||||
|
@ -173,6 +166,7 @@ public class ObjectivesFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
try {
|
||||||
View view = inflater.inflate(R.layout.objectives_fragment, container, false);
|
View view = inflater.inflate(R.layout.objectives_fragment, container, false);
|
||||||
|
|
||||||
recyclerView = (RecyclerView) view.findViewById(R.id.objectives_recyclerview);
|
recyclerView = (RecyclerView) view.findViewById(R.id.objectives_recyclerview);
|
||||||
|
@ -189,29 +183,34 @@ public class ObjectivesFragment extends Fragment {
|
||||||
});
|
});
|
||||||
reset.setOnClickListener(new View.OnClickListener() {
|
reset.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
getPlugin().initializeData();
|
ObjectivesPlugin.getPlugin().initializeData();
|
||||||
getPlugin().saveProgress();
|
ObjectivesPlugin.saveProgress();
|
||||||
updateGUI();
|
updateGUI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add correct translations to array after app is initialized
|
// Add correct translations to array after app is initialized
|
||||||
getPlugin().objectives.get(0).objective = MainApp.sResources.getString(R.string.objectives_0_objective);
|
ObjectivesPlugin.objectives.get(0).objective = MainApp.sResources.getString(R.string.objectives_0_objective);
|
||||||
getPlugin().objectives.get(1).objective = MainApp.sResources.getString(R.string.objectives_1_objective);
|
ObjectivesPlugin.objectives.get(1).objective = MainApp.sResources.getString(R.string.objectives_1_objective);
|
||||||
getPlugin().objectives.get(2).objective = MainApp.sResources.getString(R.string.objectives_2_objective);
|
ObjectivesPlugin.objectives.get(2).objective = MainApp.sResources.getString(R.string.objectives_2_objective);
|
||||||
getPlugin().objectives.get(3).objective = MainApp.sResources.getString(R.string.objectives_3_objective);
|
ObjectivesPlugin.objectives.get(3).objective = MainApp.sResources.getString(R.string.objectives_3_objective);
|
||||||
getPlugin().objectives.get(4).objective = MainApp.sResources.getString(R.string.objectives_4_objective);
|
ObjectivesPlugin.objectives.get(4).objective = MainApp.sResources.getString(R.string.objectives_4_objective);
|
||||||
getPlugin().objectives.get(5).objective = MainApp.sResources.getString(R.string.objectives_5_objective);
|
ObjectivesPlugin.objectives.get(5).objective = MainApp.sResources.getString(R.string.objectives_5_objective);
|
||||||
getPlugin().objectives.get(6).objective = MainApp.sResources.getString(R.string.objectives_6_objective);
|
ObjectivesPlugin.objectives.get(6).objective = MainApp.sResources.getString(R.string.objectives_6_objective);
|
||||||
getPlugin().objectives.get(0).gate = MainApp.sResources.getString(R.string.objectives_0_gate);
|
ObjectivesPlugin.objectives.get(0).gate = MainApp.sResources.getString(R.string.objectives_0_gate);
|
||||||
getPlugin().objectives.get(1).gate = MainApp.sResources.getString(R.string.objectives_1_gate);
|
ObjectivesPlugin.objectives.get(1).gate = MainApp.sResources.getString(R.string.objectives_1_gate);
|
||||||
getPlugin().objectives.get(2).gate = MainApp.sResources.getString(R.string.objectives_2_gate);
|
ObjectivesPlugin.objectives.get(2).gate = MainApp.sResources.getString(R.string.objectives_2_gate);
|
||||||
getPlugin().objectives.get(3).gate = MainApp.sResources.getString(R.string.objectives_3_gate);
|
ObjectivesPlugin.objectives.get(3).gate = MainApp.sResources.getString(R.string.objectives_3_gate);
|
||||||
getPlugin().objectives.get(4).gate = MainApp.sResources.getString(R.string.objectives_4_gate);
|
ObjectivesPlugin.objectives.get(4).gate = MainApp.sResources.getString(R.string.objectives_4_gate);
|
||||||
getPlugin().objectives.get(5).gate = MainApp.sResources.getString(R.string.objectives_5_gate);
|
ObjectivesPlugin.objectives.get(5).gate = MainApp.sResources.getString(R.string.objectives_5_gate);
|
||||||
updateGUI();
|
updateGUI();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateGUI() {
|
void updateGUI() {
|
||||||
|
|
|
@ -25,11 +25,20 @@ import info.nightscout.utils.SP;
|
||||||
public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
private static Logger log = LoggerFactory.getLogger(ObjectivesPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(ObjectivesPlugin.class);
|
||||||
|
|
||||||
|
private static ObjectivesPlugin objectivesPlugin;
|
||||||
|
|
||||||
|
public static ObjectivesPlugin getPlugin() {
|
||||||
|
if (objectivesPlugin == null) {
|
||||||
|
objectivesPlugin = new ObjectivesPlugin();
|
||||||
|
}
|
||||||
|
return objectivesPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Objective> objectives;
|
public static List<Objective> objectives;
|
||||||
|
|
||||||
boolean fragmentVisible = true;
|
private boolean fragmentVisible = true;
|
||||||
|
|
||||||
public ObjectivesPlugin() {
|
private ObjectivesPlugin() {
|
||||||
initializeData();
|
initializeData();
|
||||||
loadProgress();
|
loadProgress();
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
|
@ -95,7 +104,12 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
if (type == CONSTRAINTS) this.fragmentVisible = fragmentVisible;
|
if (type == CONSTRAINTS) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Objective {
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Objective {
|
||||||
Integer num;
|
Integer num;
|
||||||
String objective;
|
String objective;
|
||||||
String gate;
|
String gate;
|
||||||
|
@ -118,13 +132,13 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
public static boolean pumpStatusIsAvailableInNS = false;
|
public static boolean pumpStatusIsAvailableInNS = false;
|
||||||
// Objective 1
|
// Objective 1
|
||||||
public static Integer manualEnacts = 0;
|
public static Integer manualEnacts = 0;
|
||||||
public static final Integer manualEnactsNeeded = 20;
|
private static final Integer manualEnactsNeeded = 20;
|
||||||
|
|
||||||
public class RequirementResult {
|
class RequirementResult {
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
String comment = "";
|
String comment = "";
|
||||||
|
|
||||||
public RequirementResult(boolean done, String comment) {
|
RequirementResult(boolean done, String comment) {
|
||||||
this.done = done;
|
this.done = done;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +149,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
else return "---";
|
else return "---";
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequirementResult requirementsMet(Integer objNum) {
|
RequirementResult requirementsMet(Integer objNum) {
|
||||||
switch (objNum) {
|
switch (objNum) {
|
||||||
case 0:
|
case 0:
|
||||||
return new RequirementResult(bgIsAvailableInNS && pumpStatusIsAvailableInNS,
|
return new RequirementResult(bgIsAvailableInNS && pumpStatusIsAvailableInNS,
|
||||||
|
@ -152,7 +166,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void initializeData() {
|
void initializeData() {
|
||||||
bgIsAvailableInNS = false;
|
bgIsAvailableInNS = false;
|
||||||
pumpStatusIsAvailableInNS = false;
|
pumpStatusIsAvailableInNS = false;
|
||||||
manualEnacts = 0;
|
manualEnacts = 0;
|
||||||
|
@ -220,7 +234,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadProgress() {
|
private void loadProgress() {
|
||||||
for (int num = 0; num < objectives.size(); num++) {
|
for (int num = 0; num < objectives.size(); num++) {
|
||||||
Objective o = objectives.get(num);
|
Objective o = objectives.get(num);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -86,6 +86,11 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
|
||||||
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return R.xml.pref_safety;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLoopEnabled() {
|
public boolean isLoopEnabled() {
|
||||||
return MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
return MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
||||||
|
|
|
@ -0,0 +1,315 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Food;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.db.Food;
|
||||||
|
import info.nightscout.androidaps.events.EventFoodDatabaseChanged;
|
||||||
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.utils.NSUpload;
|
||||||
|
import info.nightscout.utils.SpinnerHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 16.10.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class FoodFragment extends SubscriberFragment {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(FoodFragment.class);
|
||||||
|
|
||||||
|
EditText filter;
|
||||||
|
ImageView clearFilter;
|
||||||
|
SpinnerHelper category;
|
||||||
|
SpinnerHelper subcategory;
|
||||||
|
RecyclerView recyclerView;
|
||||||
|
|
||||||
|
List<Food> unfiltered;
|
||||||
|
List<Food> filtered;
|
||||||
|
ArrayList<CharSequence> categories;
|
||||||
|
ArrayList<CharSequence> subcategories;
|
||||||
|
|
||||||
|
final String EMPTY = MainApp.sResources.getString(R.string.none);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
try {
|
||||||
|
View view = inflater.inflate(R.layout.food_fragment, container, false);
|
||||||
|
|
||||||
|
filter = (EditText) view.findViewById(R.id.food_filter);
|
||||||
|
clearFilter = (ImageView) view.findViewById(R.id.food_clearfilter);
|
||||||
|
category = new SpinnerHelper(view.findViewById(R.id.food_category));
|
||||||
|
subcategory = new SpinnerHelper(view.findViewById(R.id.food_subcategory));
|
||||||
|
recyclerView = (RecyclerView) view.findViewById(R.id.food_recyclerview);
|
||||||
|
recyclerView.setHasFixedSize(true);
|
||||||
|
LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
|
||||||
|
recyclerView.setLayoutManager(llm);
|
||||||
|
|
||||||
|
clearFilter.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
filter.setText("");
|
||||||
|
category.setSelection(0);
|
||||||
|
subcategory.setSelection(0);
|
||||||
|
filterData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
fillSubcategories();
|
||||||
|
filterData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
|
fillSubcategories();
|
||||||
|
filterData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
subcategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
filterData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
|
filterData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filter.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
filterData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().foodHelper.getFoodData());
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
loadData();
|
||||||
|
fillCategories();
|
||||||
|
fillSubcategories();
|
||||||
|
filterData();
|
||||||
|
return view;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public void onStatusEvent(final EventFoodDatabaseChanged ev) {
|
||||||
|
loadData();
|
||||||
|
filterData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadData() {
|
||||||
|
unfiltered = MainApp.getDbHelper().foodHelper.getFoodData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void fillCategories() {
|
||||||
|
categories = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Food f : unfiltered) {
|
||||||
|
if (f.category != null && !f.category.equals(""))
|
||||||
|
categories.add(f.category);
|
||||||
|
}
|
||||||
|
|
||||||
|
// make it unique
|
||||||
|
categories = new ArrayList<>(new HashSet<>(categories));
|
||||||
|
|
||||||
|
categories.add(0, MainApp.sResources.getString(R.string.none));
|
||||||
|
|
||||||
|
ArrayAdapter<CharSequence> adapterCategories = new ArrayAdapter<>(getContext(),
|
||||||
|
R.layout.spinner_centered, categories);
|
||||||
|
category.setAdapter(adapterCategories);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fillSubcategories() {
|
||||||
|
String categoryFilter = category.getSelectedItem().toString();
|
||||||
|
subcategories = new ArrayList<>();
|
||||||
|
|
||||||
|
if (!categoryFilter.equals(EMPTY)) {
|
||||||
|
for (Food f : unfiltered) {
|
||||||
|
if (f.category != null && f.category.equals(categoryFilter))
|
||||||
|
if (f.subcategory != null && !f.subcategory.equals(""))
|
||||||
|
subcategories.add(f.subcategory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// make it unique
|
||||||
|
subcategories = new ArrayList<>(new HashSet<>(subcategories));
|
||||||
|
|
||||||
|
subcategories.add(0, MainApp.sResources.getString(R.string.none));
|
||||||
|
|
||||||
|
ArrayAdapter<CharSequence> adapterSubcategories = new ArrayAdapter<>(getContext(),
|
||||||
|
R.layout.spinner_centered, subcategories);
|
||||||
|
subcategory.setAdapter(adapterSubcategories);
|
||||||
|
}
|
||||||
|
|
||||||
|
void filterData() {
|
||||||
|
String textFilter = filter.getText().toString();
|
||||||
|
String categoryFilter = category.getSelectedItem().toString();
|
||||||
|
String subcategoryFilter = subcategory.getSelectedItem().toString();
|
||||||
|
|
||||||
|
filtered = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Food f : unfiltered) {
|
||||||
|
if (f.name == null || f.category == null || f.subcategory == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!subcategoryFilter.equals(EMPTY) && !f.subcategory.equals(subcategoryFilter))
|
||||||
|
continue;
|
||||||
|
if (!categoryFilter.equals(EMPTY) && !f.category.equals(categoryFilter))
|
||||||
|
continue;
|
||||||
|
if (!textFilter.equals("") && !f.name.toLowerCase().contains(textFilter.toLowerCase()))
|
||||||
|
continue;
|
||||||
|
filtered.add(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateGUI() {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity != null)
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
recyclerView.swapAdapter(new FoodFragment.RecyclerViewAdapter(filtered), true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.FoodsViewHolder> {
|
||||||
|
|
||||||
|
List<Food> foodList;
|
||||||
|
|
||||||
|
RecyclerViewAdapter(List<Food> foodList) {
|
||||||
|
this.foodList = foodList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FoodsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.food_item, viewGroup, false);
|
||||||
|
return new FoodsViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(FoodsViewHolder holder, int position) {
|
||||||
|
Food food = foodList.get(position);
|
||||||
|
holder.ns.setVisibility(food._id != null ? View.VISIBLE : View.GONE);
|
||||||
|
holder.name.setText(food.name);
|
||||||
|
holder.portion.setText(food.portion + food.units);
|
||||||
|
holder.carbs.setText(food.carbs + MainApp.sResources.getString(R.string.shortgramm));
|
||||||
|
holder.fat.setText(MainApp.sResources.getString(R.string.shortfat) + ": " + food.fat + MainApp.sResources.getString(R.string.shortgramm));
|
||||||
|
if (food.fat == 0)
|
||||||
|
holder.fat.setVisibility(View.INVISIBLE);
|
||||||
|
holder.protein.setText(MainApp.sResources.getString(R.string.shortprotein) + ": " + food.protein + MainApp.sResources.getString(R.string.shortgramm));
|
||||||
|
if (food.protein == 0)
|
||||||
|
holder.protein.setVisibility(View.INVISIBLE);
|
||||||
|
holder.energy.setText(MainApp.sResources.getString(R.string.shortenergy) + ": " + food.energy + MainApp.sResources.getString(R.string.shortkilojoul));
|
||||||
|
if (food.energy == 0)
|
||||||
|
holder.energy.setVisibility(View.INVISIBLE);
|
||||||
|
holder.remove.setTag(food);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return foodList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
class FoodsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
TextView name;
|
||||||
|
TextView portion;
|
||||||
|
TextView carbs;
|
||||||
|
TextView fat;
|
||||||
|
TextView protein;
|
||||||
|
TextView energy;
|
||||||
|
TextView ns;
|
||||||
|
TextView remove;
|
||||||
|
|
||||||
|
FoodsViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
name = (TextView) itemView.findViewById(R.id.food_name);
|
||||||
|
portion = (TextView) itemView.findViewById(R.id.food_portion);
|
||||||
|
carbs = (TextView) itemView.findViewById(R.id.food_carbs);
|
||||||
|
fat = (TextView) itemView.findViewById(R.id.food_fat);
|
||||||
|
protein = (TextView) itemView.findViewById(R.id.food_protein);
|
||||||
|
energy = (TextView) itemView.findViewById(R.id.food_energy);
|
||||||
|
ns = (TextView) itemView.findViewById(R.id.ns_sign);
|
||||||
|
remove = (TextView) itemView.findViewById(R.id.food_remove);
|
||||||
|
remove.setOnClickListener(this);
|
||||||
|
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
final Food food = (Food) v.getTag();
|
||||||
|
switch (v.getId()) {
|
||||||
|
|
||||||
|
case R.id.food_remove:
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
|
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||||
|
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + food.name);
|
||||||
|
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
final String _id = food._id;
|
||||||
|
if (_id != null && !_id.equals("")) {
|
||||||
|
NSUpload.removeFoodFromNS(_id);
|
||||||
|
}
|
||||||
|
MainApp.getDbHelper().foodHelper.delete(food);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null);
|
||||||
|
builder.show();
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Food;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 05.08.2016.
|
||||||
|
*/
|
||||||
|
public class FoodPlugin implements PluginBase {
|
||||||
|
private boolean fragmentEnabled = true;
|
||||||
|
private boolean fragmentVisible = false;
|
||||||
|
|
||||||
|
private static FoodPlugin plugin = null;
|
||||||
|
|
||||||
|
public static FoodPlugin getPlugin() {
|
||||||
|
if (plugin == null)
|
||||||
|
plugin = new FoodPlugin();
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFragmentClass() {
|
||||||
|
return FoodFragment.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getType() {
|
||||||
|
return PluginBase.GENERAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return MainApp.instance().getString(R.string.food);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNameShort() {
|
||||||
|
// use long name as fallback (not visible in tabs)
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled(int type) {
|
||||||
|
return type == GENERAL && fragmentEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisibleInTabs(int type) {
|
||||||
|
return type == GENERAL && fragmentVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeHidden(int type) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasFragment() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean showInList(int type) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||||
|
if (type == GENERAL) this.fragmentEnabled = fragmentEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||||
|
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -14,8 +14,8 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
|
||||||
public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
|
public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
|
||||||
|
|
||||||
private static boolean fragmentEnabled = true;
|
private boolean fragmentEnabled = true;
|
||||||
private static boolean fragmentVisible = false;
|
private boolean fragmentVisible = false;
|
||||||
|
|
||||||
private static InsulinFastactingPlugin plugin = null;
|
private static InsulinFastactingPlugin plugin = null;
|
||||||
|
|
||||||
|
@ -80,6 +80,11 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
|
||||||
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Insulin interface
|
// Insulin interface
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
|
|
@ -14,8 +14,8 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
|
||||||
public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInterface {
|
public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInterface {
|
||||||
|
|
||||||
private static boolean fragmentEnabled = false;
|
private boolean fragmentEnabled = false;
|
||||||
private static boolean fragmentVisible = false;
|
private boolean fragmentVisible = false;
|
||||||
|
|
||||||
private static InsulinFastactingProlongedPlugin plugin = null;
|
private static InsulinFastactingProlongedPlugin plugin = null;
|
||||||
|
|
||||||
|
@ -80,6 +80,11 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte
|
||||||
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Insulin interface
|
// Insulin interface
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
|
|
@ -7,8 +7,11 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 17.04.2017.
|
* Created by mike on 17.04.2017.
|
||||||
|
@ -22,6 +25,7 @@ public class InsulinFragment extends Fragment {
|
||||||
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
try {
|
||||||
View view = inflater.inflate(R.layout.insulin_fragment, container, false);
|
View view = inflater.inflate(R.layout.insulin_fragment, container, false);
|
||||||
|
|
||||||
insulinName = (TextView) view.findViewById(R.id.insulin_name);
|
insulinName = (TextView) view.findViewById(R.id.insulin_name);
|
||||||
|
@ -32,6 +36,11 @@ public class InsulinFragment extends Fragment {
|
||||||
updateGUI();
|
updateGUI();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,10 +50,10 @@ public class InsulinFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGUI() {
|
private void updateGUI() {
|
||||||
insulinName.setText(MainApp.getConfigBuilder().getActiveInsulin().getFriendlyName());
|
insulinName.setText(ConfigBuilderPlugin.getActiveInsulin().getFriendlyName());
|
||||||
insulinComment.setText(MainApp.getConfigBuilder().getActiveInsulin().getComment());
|
insulinComment.setText(ConfigBuilderPlugin.getActiveInsulin().getComment());
|
||||||
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(MainApp.getConfigBuilder().getActiveInsulin().getDia()) + "h");
|
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(ConfigBuilderPlugin.getActiveInsulin().getDia()) + "h");
|
||||||
insulinGraph.show(MainApp.getConfigBuilder().getActiveInsulin());
|
insulinGraph.show(ConfigBuilderPlugin.getActiveInsulin());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getUserDefinedDia() {
|
public double getUserDefinedDia() {
|
||||||
return MainApp.getConfigBuilder().getProfile() != null ? MainApp.getConfigBuilder().getProfile().getDia() : Constants.defaultDIA;
|
return MainApp.getConfigBuilder().getProfile() != null ? MainApp.getConfigBuilder().getProfile().getDia() : MIN_DIA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,8 +10,8 @@ import info.nightscout.utils.SP;
|
||||||
|
|
||||||
public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin {
|
public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin {
|
||||||
|
|
||||||
private static boolean fragmentEnabled = false;
|
private boolean fragmentEnabled = false;
|
||||||
private static boolean fragmentVisible = false;
|
private boolean fragmentVisible = false;
|
||||||
|
|
||||||
private static InsulinOrefFreePeakPlugin plugin = null;
|
private static InsulinOrefFreePeakPlugin plugin = null;
|
||||||
|
|
||||||
|
@ -68,6 +68,11 @@ public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin {
|
||||||
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return R.xml.pref_insulinoreffreepeak;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int getPeak() {
|
int getPeak() {
|
||||||
return SP.getInt(R.string.key_insulin_oref_peak, DEFAULT_PEAK);
|
return SP.getInt(R.string.key_insulin_oref_peak, DEFAULT_PEAK);
|
||||||
|
|
|
@ -9,8 +9,8 @@ import info.nightscout.androidaps.R;
|
||||||
|
|
||||||
public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin {
|
public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin {
|
||||||
|
|
||||||
private static boolean fragmentEnabled = false;
|
private boolean fragmentEnabled = false;
|
||||||
private static boolean fragmentVisible = false;
|
private boolean fragmentVisible = false;
|
||||||
|
|
||||||
private static InsulinOrefRapidActingPlugin plugin = null;
|
private static InsulinOrefRapidActingPlugin plugin = null;
|
||||||
|
|
||||||
|
@ -67,6 +67,11 @@ public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin {
|
||||||
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int getPeak() {
|
int getPeak() {
|
||||||
return PEAK;
|
return PEAK;
|
||||||
|
|
|
@ -9,8 +9,8 @@ import info.nightscout.androidaps.R;
|
||||||
|
|
||||||
public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin {
|
public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin {
|
||||||
|
|
||||||
private static boolean fragmentEnabled = false;
|
private boolean fragmentEnabled = false;
|
||||||
private static boolean fragmentVisible = false;
|
private boolean fragmentVisible = false;
|
||||||
|
|
||||||
private static InsulinOrefUltraRapidActingPlugin plugin = null;
|
private static InsulinOrefUltraRapidActingPlugin plugin = null;
|
||||||
|
|
||||||
|
@ -67,6 +67,11 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin {
|
||||||
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int getPeak() {
|
int getPeak() {
|
||||||
return PEAK;
|
return PEAK;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +33,7 @@ public class AutosensData {
|
||||||
time = t.date;
|
time = t.date;
|
||||||
carbs = t.carbs;
|
carbs = t.carbs;
|
||||||
remaining = t.carbs;
|
remaining = t.carbs;
|
||||||
if (MainApp.getSpecificPlugin(SensitivityAAPSPlugin.class) != null && MainApp.getSpecificPlugin(SensitivityAAPSPlugin.class).isEnabled(PluginBase.SENSITIVITY)) {
|
if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginBase.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginBase.SENSITIVITY)) {
|
||||||
double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, 4d);
|
double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, 4d);
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile(t.date);
|
Profile profile = MainApp.getConfigBuilder().getProfile(t.date);
|
||||||
double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits());
|
double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits());
|
||||||
|
|
|
@ -126,6 +126,11 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
IobCobCalculatorPlugin() {
|
IobCobCalculatorPlugin() {
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
if (sHandlerThread == null) {
|
if (sHandlerThread == null) {
|
||||||
|
@ -366,6 +371,9 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (profile.getIsf(bgTime) == null)
|
||||||
|
return; // profile not set yet
|
||||||
|
|
||||||
double sens = Profile.toMgdl(profile.getIsf(bgTime), profile.getUnits());
|
double sens = Profile.toMgdl(profile.getIsf(bgTime), profile.getUnits());
|
||||||
|
|
||||||
AutosensData autosensData = new AutosensData();
|
AutosensData autosensData = new AutosensData();
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package info.nightscout.androidaps.plugins.IobCobCalculator.events;
|
package info.nightscout.androidaps.plugins.IobCobCalculator.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.EventLoop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 30.04.2017.
|
* Created by mike on 30.04.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventAutosensCalculationFinished {
|
public class EventAutosensCalculationFinished extends EventLoop {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package info.nightscout.androidaps.plugins.IobCobCalculator.events;
|
package info.nightscout.androidaps.plugins.IobCobCalculator.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 26.04.2017.
|
* Created by mike on 26.04.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventNewHistoryData {
|
public class EventNewHistoryData extends Event {
|
||||||
public long time = 0;
|
public long time = 0;
|
||||||
|
|
||||||
public EventNewHistoryData(long time) {
|
public EventNewHistoryData(long time) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -25,15 +26,6 @@ import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
||||||
public class LoopFragment extends SubscriberFragment implements View.OnClickListener {
|
public class LoopFragment extends SubscriberFragment implements View.OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(LoopFragment.class);
|
private static Logger log = LoggerFactory.getLogger(LoopFragment.class);
|
||||||
|
|
||||||
private static LoopPlugin loopPlugin;
|
|
||||||
|
|
||||||
public static LoopPlugin getPlugin() {
|
|
||||||
if (loopPlugin == null){
|
|
||||||
loopPlugin = new LoopPlugin();
|
|
||||||
}
|
|
||||||
return loopPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
Button runNowButton;
|
Button runNowButton;
|
||||||
TextView lastRunView;
|
TextView lastRunView;
|
||||||
TextView lastEnactView;
|
TextView lastEnactView;
|
||||||
|
@ -46,6 +38,7 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
try {
|
||||||
View view = inflater.inflate(R.layout.loop_fragment, container, false);
|
View view = inflater.inflate(R.layout.loop_fragment, container, false);
|
||||||
|
|
||||||
lastRunView = (TextView) view.findViewById(R.id.loop_lastrun);
|
lastRunView = (TextView) view.findViewById(R.id.loop_lastrun);
|
||||||
|
@ -59,6 +52,11 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
|
||||||
|
|
||||||
updateGUI();
|
updateGUI();
|
||||||
return view;
|
return view;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +67,7 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
|
||||||
Thread thread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
getPlugin().invoke("Loop button", true);
|
LoopPlugin.getPlugin().invoke("Loop button", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
thread.start();
|
thread.start();
|
||||||
|
@ -105,13 +103,13 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (getPlugin().lastRun != null) {
|
if (LoopPlugin.lastRun != null) {
|
||||||
requestView.setText(getPlugin().lastRun.request != null ? getPlugin().lastRun.request.toSpanned() : "");
|
requestView.setText(LoopPlugin.lastRun.request != null ? LoopPlugin.lastRun.request.toSpanned() : "");
|
||||||
constraintsProcessedView.setText(getPlugin().lastRun.constraintsProcessed != null ? getPlugin().lastRun.constraintsProcessed.toSpanned() : "");
|
constraintsProcessedView.setText(LoopPlugin.lastRun.constraintsProcessed != null ? LoopPlugin.lastRun.constraintsProcessed.toSpanned() : "");
|
||||||
setByPumpView.setText(getPlugin().lastRun.setByPump != null ? getPlugin().lastRun.setByPump.toSpanned() : "");
|
setByPumpView.setText(LoopPlugin.lastRun.setByPump != null ? LoopPlugin.lastRun.setByPump.toSpanned() : "");
|
||||||
sourceView.setText(getPlugin().lastRun.source != null ? getPlugin().lastRun.source : "");
|
sourceView.setText(LoopPlugin.lastRun.source != null ? LoopPlugin.lastRun.source : "");
|
||||||
lastRunView.setText(getPlugin().lastRun.lastAPSRun != null && getPlugin().lastRun.lastAPSRun.getTime() != 0 ? getPlugin().lastRun.lastAPSRun.toLocaleString() : "");
|
lastRunView.setText(LoopPlugin.lastRun.lastAPSRun != null && LoopPlugin.lastRun.lastAPSRun.getTime() != 0 ? LoopPlugin.lastRun.lastAPSRun.toLocaleString() : "");
|
||||||
lastEnactView.setText(getPlugin().lastRun.lastEnact != null && getPlugin().lastRun.lastEnact.getTime() != 0 ? getPlugin().lastRun.lastEnact.toLocaleString() : "");
|
lastEnactView.setText(LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.toLocaleString() : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -46,6 +46,15 @@ import info.nightscout.utils.SafeParse;
|
||||||
public class LoopPlugin implements PluginBase {
|
public class LoopPlugin implements PluginBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(LoopPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(LoopPlugin.class);
|
||||||
|
|
||||||
|
private static LoopPlugin loopPlugin;
|
||||||
|
|
||||||
|
public static LoopPlugin getPlugin() {
|
||||||
|
if (loopPlugin == null) {
|
||||||
|
loopPlugin = new LoopPlugin();
|
||||||
|
}
|
||||||
|
return loopPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
private static Handler sHandler;
|
private static Handler sHandler;
|
||||||
private static HandlerThread sHandlerThread;
|
private static HandlerThread sHandlerThread;
|
||||||
|
|
||||||
|
@ -139,6 +148,11 @@ public class LoopPlugin implements PluginBase {
|
||||||
if (type == LOOP) this.fragmentVisible = fragmentVisible;
|
if (type == LOOP) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return R.xml.pref_closedmode;
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventTreatmentChange ev) {
|
public void onStatusEvent(final EventTreatmentChange ev) {
|
||||||
invoke("EventTreatmentChange", true);
|
invoke("EventTreatmentChange", true);
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package info.nightscout.androidaps.plugins.Loop.events;
|
package info.nightscout.androidaps.plugins.Loop.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.EventUpdateGui;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class EventLoopSetLastRunGui {
|
public class EventLoopSetLastRunGui extends EventUpdateGui {
|
||||||
public String text = null;
|
public String text = null;
|
||||||
|
|
||||||
public EventLoopSetLastRunGui(String text) {
|
public EventLoopSetLastRunGui(String text) {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package info.nightscout.androidaps.plugins.Loop.events;
|
package info.nightscout.androidaps.plugins.Loop.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.EventUpdateGui;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class EventLoopUpdateGui {
|
public class EventLoopUpdateGui extends EventUpdateGui {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package info.nightscout.androidaps.plugins.Loop.events;
|
package info.nightscout.androidaps.plugins.Loop.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 07.08.2016.
|
* Created by mike on 07.08.2016.
|
||||||
*/
|
*/
|
||||||
public class EventNewOpenLoopNotification {
|
public class EventNewOpenLoopNotification extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import android.widget.CompoundButton;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -37,15 +38,6 @@ import info.nightscout.utils.SP;
|
||||||
public class NSClientInternalFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
public class NSClientInternalFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(NSClientInternalFragment.class);
|
private static Logger log = LoggerFactory.getLogger(NSClientInternalFragment.class);
|
||||||
|
|
||||||
static NSClientInternalPlugin nsClientInternalPlugin;
|
|
||||||
|
|
||||||
static public NSClientInternalPlugin getPlugin() {
|
|
||||||
if (nsClientInternalPlugin == null) {
|
|
||||||
nsClientInternalPlugin = new NSClientInternalPlugin();
|
|
||||||
}
|
|
||||||
return nsClientInternalPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TextView logTextView;
|
private TextView logTextView;
|
||||||
private TextView queueTextView;
|
private TextView queueTextView;
|
||||||
private TextView urlTextView;
|
private TextView urlTextView;
|
||||||
|
@ -62,14 +54,15 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
try {
|
||||||
View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);
|
View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);
|
||||||
|
|
||||||
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
|
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
|
||||||
autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
|
autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
|
||||||
autoscrollCheckbox.setChecked(getPlugin().autoscroll);
|
autoscrollCheckbox.setChecked(NSClientInternalPlugin.getPlugin().autoscroll);
|
||||||
autoscrollCheckbox.setOnCheckedChangeListener(this);
|
autoscrollCheckbox.setOnCheckedChangeListener(this);
|
||||||
pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
|
pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
|
||||||
pausedCheckbox.setChecked(getPlugin().paused);
|
pausedCheckbox.setChecked(NSClientInternalPlugin.getPlugin().paused);
|
||||||
pausedCheckbox.setOnCheckedChangeListener(this);
|
pausedCheckbox.setOnCheckedChangeListener(this);
|
||||||
logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
|
logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
|
||||||
queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue);
|
queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue);
|
||||||
|
@ -94,6 +87,11 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
|
||||||
|
|
||||||
updateGUI();
|
updateGUI();
|
||||||
return view;
|
return view;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,11 +102,11 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
|
||||||
Answers.getInstance().logCustom(new CustomEvent("NSClientRestart"));
|
Answers.getInstance().logCustom(new CustomEvent("NSClientRestart"));
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_delivernow:
|
case R.id.nsclientinternal_delivernow:
|
||||||
getPlugin().resend("GUI");
|
NSClientInternalPlugin.getPlugin().resend("GUI");
|
||||||
Answers.getInstance().logCustom(new CustomEvent("NSClientDeliverNow"));
|
Answers.getInstance().logCustom(new CustomEvent("NSClientDeliverNow"));
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_clearlog:
|
case R.id.nsclientinternal_clearlog:
|
||||||
getPlugin().clearLog();
|
NSClientInternalPlugin.getPlugin().clearLog();
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_clearqueue:
|
case R.id.nsclientinternal_clearqueue:
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
|
@ -127,7 +125,7 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
|
||||||
builder.show();
|
builder.show();
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_showqueue:
|
case R.id.nsclientinternal_showqueue:
|
||||||
MainApp.bus().post(new EventNSClientNewLog("QUEUE", getPlugin().queue().textList()));
|
MainApp.bus().post(new EventNSClientNewLog("QUEUE", NSClientInternalPlugin.getPlugin().queue().textList()));
|
||||||
Answers.getInstance().logCustom(new CustomEvent("NSClientShowQueue"));
|
Answers.getInstance().logCustom(new CustomEvent("NSClientShowQueue"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -138,14 +136,14 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
|
||||||
switch (buttonView.getId()) {
|
switch (buttonView.getId()) {
|
||||||
case R.id.nsclientinternal_paused:
|
case R.id.nsclientinternal_paused:
|
||||||
SP.putBoolean(R.string.key_nsclientinternal_paused, isChecked);
|
SP.putBoolean(R.string.key_nsclientinternal_paused, isChecked);
|
||||||
getPlugin().paused = isChecked;
|
NSClientInternalPlugin.getPlugin().paused = isChecked;
|
||||||
MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
||||||
updateGUI();
|
updateGUI();
|
||||||
Answers.getInstance().logCustom(new CustomEvent("NSClientPause"));
|
Answers.getInstance().logCustom(new CustomEvent("NSClientPause"));
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_autoscroll:
|
case R.id.nsclientinternal_autoscroll:
|
||||||
SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
|
SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
|
||||||
getPlugin().autoscroll = isChecked;
|
NSClientInternalPlugin.getPlugin().autoscroll = isChecked;
|
||||||
updateGUI();
|
updateGUI();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -165,13 +163,13 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
|
||||||
public void run() {
|
public void run() {
|
||||||
NSClientInternalPlugin.updateLog();
|
NSClientInternalPlugin.updateLog();
|
||||||
logTextView.setText(NSClientInternalPlugin.textLog);
|
logTextView.setText(NSClientInternalPlugin.textLog);
|
||||||
if (getPlugin().autoscroll) {
|
if (NSClientInternalPlugin.getPlugin().autoscroll) {
|
||||||
logScrollview.fullScroll(ScrollView.FOCUS_DOWN);
|
logScrollview.fullScroll(ScrollView.FOCUS_DOWN);
|
||||||
}
|
}
|
||||||
urlTextView.setText(getPlugin().url());
|
urlTextView.setText(NSClientInternalPlugin.getPlugin().url());
|
||||||
Spanned queuetext = Html.fromHtml(MainApp.sResources.getString(R.string.queue) + " <b>" + UploadQueue.size() + "</b>");
|
Spanned queuetext = Html.fromHtml(MainApp.sResources.getString(R.string.queue) + " <b>" + UploadQueue.size() + "</b>");
|
||||||
queueTextView.setText(queuetext);
|
queueTextView.setText(queuetext);
|
||||||
statusTextView.setText(getPlugin().status);
|
statusTextView.setText(NSClientInternalPlugin.getPlugin().status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,15 @@ import info.nightscout.utils.ToastUtils;
|
||||||
public class NSClientInternalPlugin implements PluginBase {
|
public class NSClientInternalPlugin implements PluginBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(NSClientInternalPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(NSClientInternalPlugin.class);
|
||||||
|
|
||||||
|
static NSClientInternalPlugin nsClientInternalPlugin;
|
||||||
|
|
||||||
|
static public NSClientInternalPlugin getPlugin() {
|
||||||
|
if (nsClientInternalPlugin == null) {
|
||||||
|
nsClientInternalPlugin = new NSClientInternalPlugin();
|
||||||
|
}
|
||||||
|
return nsClientInternalPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean fragmentEnabled = true;
|
private boolean fragmentEnabled = true;
|
||||||
private boolean fragmentVisible = true;
|
private boolean fragmentVisible = true;
|
||||||
|
|
||||||
|
@ -126,6 +135,11 @@ public class NSClientInternalPlugin implements PluginBase {
|
||||||
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
|
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return R.xml.pref_nsclientinternal;
|
||||||
|
}
|
||||||
|
|
||||||
private ServiceConnection mConnection = new ServiceConnection() {
|
private ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
|
|
|
@ -7,14 +7,14 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
|
|
||||||
import io.socket.client.Ack;
|
import io.socket.client.Ack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 29.12.2015.
|
* Created by mike on 29.12.2015.
|
||||||
*/
|
*/
|
||||||
public class NSAddAck implements Ack {
|
public class NSAddAck extends Event implements Ack {
|
||||||
private static Logger log = LoggerFactory.getLogger(NSAddAck.class);
|
private static Logger log = LoggerFactory.getLogger(NSAddAck.class);
|
||||||
public String _id = null;
|
public String _id = null;
|
||||||
public String nsClientID = null;
|
public String nsClientID = null;
|
||||||
|
|
|
@ -3,13 +3,14 @@ package info.nightscout.androidaps.plugins.NSClientInternal.acks;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
|
||||||
import io.socket.client.Ack;
|
import io.socket.client.Ack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 02.01.2016.
|
* Created by mike on 02.01.2016.
|
||||||
*/
|
*/
|
||||||
public class NSAuthAck implements Ack{
|
public class NSAuthAck extends Event implements Ack{
|
||||||
public boolean read = false;
|
public boolean read = false;
|
||||||
public boolean write = false;
|
public boolean write = false;
|
||||||
public boolean write_treatment = false;
|
public boolean write_treatment = false;
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.NSClientInternal.acks;
|
|
||||||
|
|
||||||
import android.os.SystemClock;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import io.socket.client.Ack;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 29.12.2015.
|
|
||||||
*/
|
|
||||||
public class NSPingAck implements Ack {
|
|
||||||
private static Logger log = LoggerFactory.getLogger(NSPingAck.class);
|
|
||||||
|
|
||||||
public long mills = 0;
|
|
||||||
public boolean received = false;
|
|
||||||
public boolean auth_received = false;
|
|
||||||
public boolean read = false;
|
|
||||||
public boolean write = false;
|
|
||||||
public boolean write_treatment = false;
|
|
||||||
|
|
||||||
public void call(Object...args) {
|
|
||||||
JSONObject response = (JSONObject)args[0];
|
|
||||||
mills = response.optLong("mills");
|
|
||||||
if (response.has("authorization")) {
|
|
||||||
auth_received = true;
|
|
||||||
try {
|
|
||||||
JSONObject authorization = response.getJSONObject("authorization");
|
|
||||||
read = authorization.optBoolean("read");
|
|
||||||
write = authorization.optBoolean("write");
|
|
||||||
write_treatment = authorization.optBoolean("write_treatment");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
received = true;
|
|
||||||
synchronized(this) {
|
|
||||||
this.notify();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,12 +6,13 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
import io.socket.client.Ack;
|
import io.socket.client.Ack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 21.02.2016.
|
* Created by mike on 21.02.2016.
|
||||||
*/
|
*/
|
||||||
public class NSUpdateAck implements Ack {
|
public class NSUpdateAck extends Event implements Ack {
|
||||||
private static Logger log = LoggerFactory.getLogger(NSUpdateAck.class);
|
private static Logger log = LoggerFactory.getLogger(NSUpdateAck.class);
|
||||||
public boolean result = false;
|
public boolean result = false;
|
||||||
public String _id = null;
|
public String _id = null;
|
||||||
|
|
|
@ -67,4 +67,31 @@ public class BroadcastDeviceStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void handleNewFoods(JSONArray foods, Context context, boolean isDelta) {
|
||||||
|
|
||||||
|
List<JSONArray> splitted = BroadcastTreatment.splitArray(foods);
|
||||||
|
for (JSONArray part: splitted) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("foods", part.toString());
|
||||||
|
bundle.putBoolean("delta", isDelta);
|
||||||
|
Intent intent = new Intent(Intents.ACTION_NEW_FOOD);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
|
||||||
|
splitted = BroadcastTreatment.splitArray(foods);
|
||||||
|
for (JSONArray part : splitted) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("foods", part.toString());
|
||||||
|
bundle.putBoolean("delta", isDelta);
|
||||||
|
Intent intent = new Intent(Intents.ACTION_NEW_FOOD);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.Services.Intents;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 20.02.2016.
|
||||||
|
*/
|
||||||
|
public class BroadcastFood {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(BroadcastFood.class);
|
||||||
|
|
||||||
|
public static void handleNewFood(JSONArray foods, Context context, boolean isDelta) {
|
||||||
|
|
||||||
|
List<JSONArray> splitted = BroadcastTreatment.splitArray(foods);
|
||||||
|
for (JSONArray part : splitted) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("foods", part.toString());
|
||||||
|
bundle.putBoolean("delta", isDelta);
|
||||||
|
Intent intent = new Intent(Intents.ACTION_NEW_FOOD);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
|
||||||
|
for (JSONArray part : splitted) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("foods", part.toString());
|
||||||
|
bundle.putBoolean("delta", isDelta);
|
||||||
|
Intent intent = new Intent(Intents.ACTION_NEW_FOOD);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handleChangedFood(JSONArray foods, Context context, boolean isDelta) {
|
||||||
|
|
||||||
|
List<JSONArray> splitted = BroadcastTreatment.splitArray(foods);
|
||||||
|
for (JSONArray part : splitted) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("foods", part.toString());
|
||||||
|
bundle.putBoolean("delta", isDelta);
|
||||||
|
Intent intent = new Intent(Intents.ACTION_CHANGED_FOOD);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
|
||||||
|
for (JSONArray part : splitted) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("foods", part.toString());
|
||||||
|
bundle.putBoolean("delta", isDelta);
|
||||||
|
Intent intent = new Intent(Intents.ACTION_CHANGED_FOOD);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handleRemovedFood(JSONArray foods, Context context, boolean isDelta) {
|
||||||
|
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("foods", foods.toString());
|
||||||
|
bundle.putBoolean("delta", isDelta);
|
||||||
|
Intent intent = new Intent(Intents.ACTION_REMOVED_FOOD);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
|
||||||
|
|
||||||
|
|
||||||
|
if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
|
||||||
|
bundle = new Bundle();
|
||||||
|
bundle.putString("foods", foods.toString());
|
||||||
|
bundle.putBoolean("delta", isDelta);
|
||||||
|
intent = new Intent(Intents.ACTION_REMOVED_FOOD);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -46,23 +46,29 @@ public class BroadcastSgvs {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) {
|
public static void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) {
|
||||||
|
|
||||||
|
List<JSONArray> splitted = BroadcastTreatment.splitArray(sgvs);
|
||||||
|
for (JSONArray part : splitted) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("sgvs", sgvs.toString());
|
bundle.putString("sgvs", part.toString());
|
||||||
bundle.putBoolean("delta", isDelta);
|
bundle.putBoolean("delta", isDelta);
|
||||||
Intent intent = new Intent(Intents.ACTION_NEW_SGV);
|
Intent intent = new Intent(Intents.ACTION_NEW_SGV);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
|
||||||
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
|
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
|
||||||
bundle = new Bundle();
|
for (JSONArray part : splitted) {
|
||||||
bundle.putString("sgvs", sgvs.toString());
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("sgvs", part.toString());
|
||||||
bundle.putBoolean("delta", isDelta);
|
bundle.putBoolean("delta", isDelta);
|
||||||
intent = new Intent(Intents.ACTION_NEW_SGV);
|
Intent intent = new Intent(Intents.ACTION_NEW_SGV);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
context.sendBroadcast(intent);
|
context.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class BroadcastTreatment {
|
||||||
ret.add(newarr);
|
ret.add(newarr);
|
||||||
}
|
}
|
||||||
newarr = new JSONArray();
|
newarr = new JSONArray();
|
||||||
count = 50;
|
count = 20;
|
||||||
}
|
}
|
||||||
newarr.put(array.get(i));
|
newarr.put(array.get(i));
|
||||||
--count;
|
--count;
|
||||||
|
|
|
@ -254,7 +254,7 @@ public class NSDeviceStatus {
|
||||||
long clockEnacted = 0L;
|
long clockEnacted = 0L;
|
||||||
|
|
||||||
JSONObject suggested = null;
|
JSONObject suggested = null;
|
||||||
JSONObject enacted = null;
|
public JSONObject enacted = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateOpenApsData(JSONObject object) {
|
public void updateOpenApsData(JSONObject object) {
|
||||||
|
@ -336,7 +336,9 @@ public class NSDeviceStatus {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
long clock = 0L;
|
long clock = 0L;
|
||||||
if (object.has("created_at"))
|
if (object.has("mills"))
|
||||||
|
clock = object.getLong("mills");
|
||||||
|
else if (object.has("created_at"))
|
||||||
clock = DateUtil.fromISODateString(object.getString("created_at")).getTime();
|
clock = DateUtil.fromISODateString(object.getString("created_at")).getTime();
|
||||||
String device = getDevice();
|
String device = getDevice();
|
||||||
Integer battery = null;
|
Integer battery = null;
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
package info.nightscout.androidaps.plugins.NSClientInternal.events;
|
package info.nightscout.androidaps.plugins.NSClientInternal.events;
|
||||||
|
|
||||||
import android.text.Html;
|
|
||||||
import android.text.Spanned;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 15.02.2017.
|
* Created by mike on 15.02.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventNSClientNewLog {
|
public class EventNSClientNewLog extends Event {
|
||||||
public Date date = new Date();
|
public Date date = new Date();
|
||||||
public String action;
|
public String action;
|
||||||
public String logText;
|
public String logText;
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package info.nightscout.androidaps.plugins.NSClientInternal.events;
|
package info.nightscout.androidaps.plugins.NSClientInternal.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 15.02.2017.
|
* Created by mike on 15.02.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventNSClientRestart {
|
public class EventNSClientRestart extends Event {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package info.nightscout.androidaps.plugins.NSClientInternal.events;
|
package info.nightscout.androidaps.plugins.NSClientInternal.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 02.01.2016.
|
* Created by mike on 02.01.2016.
|
||||||
*/
|
*/
|
||||||
public class EventNSClientStatus {
|
public class EventNSClientStatus extends Event {
|
||||||
public String status = "";
|
public String status = "";
|
||||||
|
|
||||||
public EventNSClientStatus(String status) {
|
public EventNSClientStatus(String status) {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package info.nightscout.androidaps.plugins.NSClientInternal.events;
|
package info.nightscout.androidaps.plugins.NSClientInternal.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.EventUpdateGui;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 17.02.2017.
|
* Created by mike on 17.02.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventNSClientUpdateGUI {
|
public class EventNSClientUpdateGUI extends EventUpdateGui {
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.os.HandlerThread;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.hash.Hashing;
|
import com.google.common.hash.Hashing;
|
||||||
import com.j256.ormlite.dao.CloseableIterator;
|
import com.j256.ormlite.dao.CloseableIterator;
|
||||||
|
@ -43,6 +44,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastA
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastCals;
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastCals;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastClearAlarm;
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastClearAlarm;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastDeviceStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastDeviceStatus;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastFood;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastMbgs;
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastMbgs;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastProfile;
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastProfile;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastSgvs;
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastSgvs;
|
||||||
|
@ -321,12 +323,18 @@ public class NSClientService extends Service {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void call(final Object... args) {
|
public void call(final Object... args) {
|
||||||
JSONObject data = (JSONObject) args[0];
|
JSONObject data;
|
||||||
|
try {
|
||||||
|
data = (JSONObject) args[0];
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.log("Wrong Announcement from NS: " + args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Config.detailedLog)
|
if (Config.detailedLog)
|
||||||
try {
|
try {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ANNOUNCEMENT", data.has("message") ? data.getString("message") : "received"));
|
MainApp.bus().post(new EventNSClientNewLog("ANNOUNCEMENT", data.has("message") ? data.getString("message") : "received"));
|
||||||
} catch (JSONException e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
BroadcastAnnouncement.handleAnnouncement(data, getApplicationContext());
|
BroadcastAnnouncement.handleAnnouncement(data, getApplicationContext());
|
||||||
log.debug(data.toString());
|
log.debug(data.toString());
|
||||||
|
@ -351,7 +359,13 @@ public class NSClientService extends Service {
|
||||||
public void call(final Object... args) {
|
public void call(final Object... args) {
|
||||||
if (Config.detailedLog)
|
if (Config.detailedLog)
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ALARM", "received"));
|
MainApp.bus().post(new EventNSClientNewLog("ALARM", "received"));
|
||||||
JSONObject data = (JSONObject) args[0];
|
JSONObject data;
|
||||||
|
try {
|
||||||
|
data = (JSONObject) args[0];
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.log("Wrong alarm from NS: " + args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
BroadcastAlarm.handleAlarm(data, getApplicationContext());
|
BroadcastAlarm.handleAlarm(data, getApplicationContext());
|
||||||
log.debug(data.toString());
|
log.debug(data.toString());
|
||||||
}
|
}
|
||||||
|
@ -373,7 +387,13 @@ public class NSClientService extends Service {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void call(final Object... args) {
|
public void call(final Object... args) {
|
||||||
JSONObject data = (JSONObject) args[0];
|
JSONObject data;
|
||||||
|
try {
|
||||||
|
data = (JSONObject) args[0];
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.log("Wrong Urgent alarm from NS: " + args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Config.detailedLog)
|
if (Config.detailedLog)
|
||||||
MainApp.bus().post(new EventNSClientNewLog("URGENTALARM", "received"));
|
MainApp.bus().post(new EventNSClientNewLog("URGENTALARM", "received"));
|
||||||
BroadcastUrgentAlarm.handleUrgentAlarm(data, getApplicationContext());
|
BroadcastUrgentAlarm.handleUrgentAlarm(data, getApplicationContext());
|
||||||
|
@ -392,9 +412,15 @@ public class NSClientService extends Service {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void call(final Object... args) {
|
public void call(final Object... args) {
|
||||||
|
JSONObject data;
|
||||||
|
try {
|
||||||
|
data = (JSONObject) args[0];
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.log("Wrong Urgent alarm from NS: " + args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Config.detailedLog)
|
if (Config.detailedLog)
|
||||||
MainApp.bus().post(new EventNSClientNewLog("CLEARALARM", "received"));
|
MainApp.bus().post(new EventNSClientNewLog("CLEARALARM", "received"));
|
||||||
JSONObject data = (JSONObject) args[0];
|
|
||||||
BroadcastClearAlarm.handleClearAlarm(data, getApplicationContext());
|
BroadcastClearAlarm.handleClearAlarm(data, getApplicationContext());
|
||||||
log.debug(data.toString());
|
log.debug(data.toString());
|
||||||
}
|
}
|
||||||
|
@ -519,6 +545,55 @@ public class NSClientService extends Service {
|
||||||
BroadcastDeviceStatus.handleNewDeviceStatus(devicestatuses, MainApp.instance().getApplicationContext(), isDelta);
|
BroadcastDeviceStatus.handleNewDeviceStatus(devicestatuses, MainApp.instance().getApplicationContext(), isDelta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (data.has("food")) {
|
||||||
|
JSONArray foods = data.getJSONArray("food");
|
||||||
|
JSONArray removedFoods = new JSONArray();
|
||||||
|
JSONArray updatedFoods = new JSONArray();
|
||||||
|
JSONArray addedFoods = new JSONArray();
|
||||||
|
if (foods.length() > 0)
|
||||||
|
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + foods.length() + " foods"));
|
||||||
|
for (Integer index = 0; index < foods.length(); index++) {
|
||||||
|
JSONObject jsonFood = foods.getJSONObject(index);
|
||||||
|
NSTreatment treatment = new NSTreatment(jsonFood);
|
||||||
|
|
||||||
|
// remove from upload queue if Ack is failing
|
||||||
|
UploadQueue.removeID(jsonFood);
|
||||||
|
//Find latest date in treatment
|
||||||
|
if (treatment.getMills() != null && treatment.getMills() < System.currentTimeMillis())
|
||||||
|
if (treatment.getMills() > latestDateInReceivedData)
|
||||||
|
latestDateInReceivedData = treatment.getMills();
|
||||||
|
|
||||||
|
if (treatment.getAction() == null) {
|
||||||
|
addedFoods.put(jsonFood);
|
||||||
|
} else if (treatment.getAction().equals("update")) {
|
||||||
|
updatedFoods.put(jsonFood);
|
||||||
|
} else if (treatment.getAction().equals("remove")) {
|
||||||
|
if (treatment.getMills() != null && treatment.getMills() > System.currentTimeMillis() - 24 * 60 * 60 * 1000L) // handle 1 day old deletions only
|
||||||
|
removedFoods.put(jsonFood);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removedFoods.length() > 0) {
|
||||||
|
BroadcastFood.handleRemovedFood(removedFoods, MainApp.instance().getApplicationContext(), isDelta);
|
||||||
|
}
|
||||||
|
if (updatedFoods.length() > 0) {
|
||||||
|
BroadcastFood.handleChangedFood(updatedFoods, MainApp.instance().getApplicationContext(), isDelta);
|
||||||
|
}
|
||||||
|
if (addedFoods.length() > 0) {
|
||||||
|
BroadcastFood.handleNewFood(addedFoods, MainApp.instance().getApplicationContext(), isDelta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (data.has("")) {
|
||||||
|
JSONArray foods = data.getJSONArray("food");
|
||||||
|
if (foods.length() > 0) {
|
||||||
|
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + foods.length() + " foods"));
|
||||||
|
for (Integer index = 0; index < foods.length(); index++) {
|
||||||
|
JSONObject jsonFood = foods.getJSONObject(index);
|
||||||
|
// remove from upload queue if Ack is failing
|
||||||
|
UploadQueue.removeID(jsonFood);
|
||||||
|
}
|
||||||
|
BroadcastDeviceStatus.handleNewFoods(foods, MainApp.instance().getApplicationContext(), isDelta);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (data.has("mbgs")) {
|
if (data.has("mbgs")) {
|
||||||
JSONArray mbgs = data.getJSONArray("mbgs");
|
JSONArray mbgs = data.getJSONArray("mbgs");
|
||||||
if (mbgs.length() > 0)
|
if (mbgs.length() > 0)
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
package info.nightscout.androidaps.plugins.OpenAPSAMA;
|
package info.nightscout.androidaps.plugins.OpenAPSAMA;
|
||||||
|
|
||||||
import com.eclipsesource.v8.JavaVoidCallback;
|
import org.json.JSONArray;
|
||||||
import com.eclipsesource.v8.V8;
|
|
||||||
import com.eclipsesource.v8.V8Array;
|
|
||||||
import com.eclipsesource.v8.V8Object;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.mozilla.javascript.Callable;
|
||||||
|
import org.mozilla.javascript.Context;
|
||||||
|
import org.mozilla.javascript.Function;
|
||||||
|
import org.mozilla.javascript.NativeJSON;
|
||||||
|
import org.mozilla.javascript.NativeObject;
|
||||||
|
import org.mozilla.javascript.RhinoException;
|
||||||
|
import org.mozilla.javascript.Scriptable;
|
||||||
|
import org.mozilla.javascript.ScriptableObject;
|
||||||
|
import org.mozilla.javascript.Undefined;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
|
@ -24,6 +30,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
public class DetermineBasalAdapterAMAJS {
|
public class DetermineBasalAdapterAMAJS {
|
||||||
|
@ -31,20 +38,13 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
|
|
||||||
|
|
||||||
private ScriptReader mScriptReader = null;
|
private ScriptReader mScriptReader = null;
|
||||||
V8 mV8rt;
|
|
||||||
private V8Object mProfile;
|
|
||||||
private V8Object mGlucoseStatus;
|
|
||||||
private V8Array mIobData;
|
|
||||||
private V8Object mMealData;
|
|
||||||
private V8Object mCurrentTemp;
|
|
||||||
private V8Object mAutosensData = null;
|
|
||||||
|
|
||||||
private final String PARAM_currentTemp = "currentTemp";
|
private JSONObject mProfile;
|
||||||
private final String PARAM_iobData = "iobData";
|
private JSONObject mGlucoseStatus;
|
||||||
private final String PARAM_glucoseStatus = "glucose_status";
|
private JSONArray mIobData;
|
||||||
private final String PARAM_profile = "profile";
|
private JSONObject mMealData;
|
||||||
private final String PARAM_meal_data = "meal_data";
|
private JSONObject mCurrentTemp;
|
||||||
private final String PARAM_autosens_data = "autosens_data";
|
private JSONObject mAutosensData = null;
|
||||||
|
|
||||||
private String storedCurrentTemp = null;
|
private String storedCurrentTemp = null;
|
||||||
private String storedIobData = null;
|
private String storedIobData = null;
|
||||||
|
@ -55,58 +55,101 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
|
|
||||||
private String scriptDebug = "";
|
private String scriptDebug = "";
|
||||||
|
|
||||||
/**
|
|
||||||
* Main code
|
|
||||||
*/
|
|
||||||
|
|
||||||
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader) throws IOException {
|
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader) throws IOException {
|
||||||
mV8rt = V8.createV8Runtime();
|
|
||||||
mScriptReader = scriptReader;
|
mScriptReader = scriptReader;
|
||||||
|
|
||||||
initLogCallback();
|
|
||||||
initProcessExitCallback();
|
|
||||||
initModuleParent();
|
|
||||||
loadScript();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DetermineBasalResultAMA invoke() {
|
public DetermineBasalResultAMA invoke() {
|
||||||
|
|
||||||
|
|
||||||
log.debug(">>> Invoking detemine_basal <<<");
|
log.debug(">>> Invoking detemine_basal <<<");
|
||||||
log.debug("Glucose status: " + (storedGlucoseStatus = mV8rt.executeStringScript("JSON.stringify(" + PARAM_glucoseStatus + ");")));
|
log.debug("Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
|
||||||
log.debug("IOB data: " + (storedIobData = mV8rt.executeStringScript("JSON.stringify(" + PARAM_iobData + ");")));
|
log.debug("IOB data: " + (storedIobData = mIobData.toString()));
|
||||||
log.debug("Current temp: " + (storedCurrentTemp = mV8rt.executeStringScript("JSON.stringify(" + PARAM_currentTemp + ");")));
|
log.debug("Current temp: " + (storedCurrentTemp = mCurrentTemp.toString()));
|
||||||
log.debug("Profile: " + (storedProfile = mV8rt.executeStringScript("JSON.stringify(" + PARAM_profile + ");")));
|
log.debug("Profile: " + (storedProfile = mProfile.toString()));
|
||||||
log.debug("Meal data: " + (storedMeal_data = mV8rt.executeStringScript("JSON.stringify(" + PARAM_meal_data + ");")));
|
log.debug("Meal data: " + (storedMeal_data = mMealData.toString()));
|
||||||
if (mAutosensData != null)
|
if (mAutosensData != null)
|
||||||
log.debug("Autosens data: " + (storedAutosens_data = mV8rt.executeStringScript("JSON.stringify(" + PARAM_autosens_data + ");")));
|
log.debug("Autosens data: " + (storedAutosens_data = mAutosensData.toString()));
|
||||||
else
|
else
|
||||||
log.debug("Autosens data: " + (storedAutosens_data = "undefined"));
|
log.debug("Autosens data: " + (storedAutosens_data = "undefined"));
|
||||||
|
|
||||||
mV8rt.executeVoidScript(
|
DetermineBasalResultAMA determineBasalResultAMA = null;
|
||||||
"var rT = determine_basal(" +
|
|
||||||
PARAM_glucoseStatus + ", " +
|
|
||||||
PARAM_currentTemp + ", " +
|
|
||||||
PARAM_iobData + ", " +
|
|
||||||
PARAM_profile + ", " +
|
|
||||||
PARAM_autosens_data + ", " +
|
|
||||||
PARAM_meal_data + ", " +
|
|
||||||
"tempBasalFunctions" +
|
|
||||||
");");
|
|
||||||
|
|
||||||
|
Context rhino = Context.enter();
|
||||||
|
Scriptable scope = rhino.initStandardObjects();
|
||||||
|
// Turn off optimization to make Rhino Android compatible
|
||||||
|
rhino.setOptimizationLevel(-1);
|
||||||
|
|
||||||
String ret = mV8rt.executeStringScript("JSON.stringify(rT);");
|
|
||||||
log.debug("Result: " + ret);
|
|
||||||
|
|
||||||
V8Object v8ObjectReuslt = mV8rt.getObject("rT");
|
|
||||||
|
|
||||||
DetermineBasalResultAMA result = null;
|
|
||||||
try {
|
try {
|
||||||
result = new DetermineBasalResultAMA(v8ObjectReuslt, new JSONObject(ret));
|
|
||||||
|
//register logger callback for console.log and console.error
|
||||||
|
ScriptableObject.defineClass(scope, LoggerCallback.class);
|
||||||
|
Scriptable myLogger = rhino.newObject(scope, "LoggerCallback", null);
|
||||||
|
scope.put("console2", scope, myLogger);
|
||||||
|
rhino.evaluateString(scope, readFile("OpenAPSAMA/loggerhelper.js"), "JavaScript", 0, null);
|
||||||
|
|
||||||
|
//set module parent
|
||||||
|
rhino.evaluateString(scope, "var module = {\"parent\":Boolean(1)};", "JavaScript", 0, null);
|
||||||
|
rhino.evaluateString(scope, "var round_basal = function round_basal(basal, profile) { return basal; };", "JavaScript", 0, null);
|
||||||
|
rhino.evaluateString(scope, "require = function() {return round_basal;};", "JavaScript", 0, null);
|
||||||
|
|
||||||
|
//generate functions "determine_basal" and "setTempBasal"
|
||||||
|
rhino.evaluateString(scope, readFile("OpenAPSAMA/determine-basal.js"), "JavaScript", 0, null);
|
||||||
|
rhino.evaluateString(scope, readFile("OpenAPSAMA/basal-set-temp.js"), "setTempBasal.js", 0, null);
|
||||||
|
Object determineBasalObj = scope.get("determine_basal", scope);
|
||||||
|
Object setTempBasalFunctionsObj = scope.get("tempBasalFunctions", scope);
|
||||||
|
|
||||||
|
//call determine-basal
|
||||||
|
if (determineBasalObj instanceof Function && setTempBasalFunctionsObj instanceof NativeObject) {
|
||||||
|
Function determineBasalJS = (Function) determineBasalObj;
|
||||||
|
|
||||||
|
//prepare parameters
|
||||||
|
Object[] params = new Object[]{
|
||||||
|
makeParam(mGlucoseStatus, rhino, scope),
|
||||||
|
makeParam(mCurrentTemp, rhino, scope),
|
||||||
|
makeParamArray(mIobData, rhino, scope),
|
||||||
|
makeParam(mProfile, rhino, scope),
|
||||||
|
makeParam(mAutosensData, rhino, scope),
|
||||||
|
makeParam(mMealData, rhino, scope),
|
||||||
|
setTempBasalFunctionsObj};
|
||||||
|
|
||||||
|
NativeObject jsResult = (NativeObject) determineBasalJS.call(rhino, scope, scope, params);
|
||||||
|
scriptDebug = LoggerCallback.getScriptDebug();
|
||||||
|
|
||||||
|
// Parse the jsResult object to a JSON-String
|
||||||
|
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
||||||
|
if (Config.logAPSResult)
|
||||||
|
log.debug("Result: " + result);
|
||||||
|
try {
|
||||||
|
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("Problem loading JS Functions");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.debug("IOException");
|
||||||
|
} catch (RhinoException e) {
|
||||||
|
log.error("RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
log.error(e.toString());
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
log.error(e.toString());
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
log.error(e.toString());
|
||||||
|
} finally {
|
||||||
|
Context.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
storedGlucoseStatus = mGlucoseStatus.toString();
|
||||||
|
storedIobData = mIobData.toString();
|
||||||
|
storedCurrentTemp = mCurrentTemp.toString();
|
||||||
|
storedProfile = mProfile.toString();
|
||||||
|
storedMeal_data = mMealData.toString();
|
||||||
|
|
||||||
|
return determineBasalResultAMA;
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getGlucoseStatusParam() {
|
String getGlucoseStatusParam() {
|
||||||
|
@ -137,60 +180,6 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
return scriptDebug;
|
return scriptDebug;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadScript() throws IOException {
|
|
||||||
mV8rt.executeVoidScript("var round_basal = function round_basal(basal, profile) { return basal; };");
|
|
||||||
mV8rt.executeVoidScript("require = function() {return round_basal;};");
|
|
||||||
|
|
||||||
mV8rt.executeVoidScript(readFile("OpenAPSAMA/basal-set-temp.js"), "OpenAPSAMA/basal-set-temp.js ", 0);
|
|
||||||
mV8rt.executeVoidScript("var tempBasalFunctions = module.exports;");
|
|
||||||
|
|
||||||
mV8rt.executeVoidScript(
|
|
||||||
readFile("OpenAPSAMA/determine-basal.js"),
|
|
||||||
"OpenAPSAMA/determine-basal.js",
|
|
||||||
0);
|
|
||||||
mV8rt.executeVoidScript("var determine_basal = module.exports;");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initModuleParent() {
|
|
||||||
mV8rt.executeVoidScript("var module = {\"parent\":Boolean(1)};");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initProcessExitCallback() {
|
|
||||||
JavaVoidCallback callbackProccessExit = new JavaVoidCallback() {
|
|
||||||
@Override
|
|
||||||
public void invoke(V8Object arg0, V8Array parameters) {
|
|
||||||
if (parameters.length() > 0) {
|
|
||||||
Object arg1 = parameters.get(0);
|
|
||||||
log.error("ProccessExit " + arg1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mV8rt.registerJavaMethod(callbackProccessExit, "proccessExit");
|
|
||||||
mV8rt.executeVoidScript("var process = {\"exit\": function () { proccessExit(); } };");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initLogCallback() {
|
|
||||||
JavaVoidCallback callbackLog = new JavaVoidCallback() {
|
|
||||||
@Override
|
|
||||||
public void invoke(V8Object arg0, V8Array parameters) {
|
|
||||||
int i = 0;
|
|
||||||
String s = "";
|
|
||||||
while (i < parameters.length()) {
|
|
||||||
Object arg = parameters.get(i);
|
|
||||||
s += arg + " ";
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (!s.equals("") && Config.logAPSResult) {
|
|
||||||
log.debug("Script debug: " + s);
|
|
||||||
scriptDebug += s + "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mV8rt.registerJavaMethod(callbackLog, "log");
|
|
||||||
mV8rt.executeVoidScript("var console = {\"log\":log, \"error\":log};");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setData(Profile profile,
|
public void setData(Profile profile,
|
||||||
double maxIob,
|
double maxIob,
|
||||||
double maxBasal,
|
double maxBasal,
|
||||||
|
@ -203,89 +192,94 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
MealData mealData,
|
MealData mealData,
|
||||||
double autosensDataRatio,
|
double autosensDataRatio,
|
||||||
boolean tempTargetSet,
|
boolean tempTargetSet,
|
||||||
double min_5m_carbimpact) {
|
double min_5m_carbimpact) throws JSONException {
|
||||||
|
|
||||||
String units = profile.getUnits();
|
String units = profile.getUnits();
|
||||||
|
|
||||||
mProfile = new V8Object(mV8rt);
|
mProfile = new JSONObject();
|
||||||
mProfile.add("max_iob", maxIob);
|
mProfile.put("max_iob", maxIob);
|
||||||
mProfile.add("dia", Math.min(profile.getDia(), 3d));
|
mProfile.put("dia", Math.min(profile.getDia(), 3d));
|
||||||
mProfile.add("type", "current");
|
mProfile.put("type", "current");
|
||||||
mProfile.add("max_daily_basal", profile.getMaxDailyBasal());
|
mProfile.put("max_daily_basal", profile.getMaxDailyBasal());
|
||||||
mProfile.add("max_basal", maxBasal);
|
mProfile.put("max_basal", maxBasal);
|
||||||
mProfile.add("min_bg", minBg);
|
mProfile.put("min_bg", minBg);
|
||||||
mProfile.add("max_bg", maxBg);
|
mProfile.put("max_bg", maxBg);
|
||||||
mProfile.add("target_bg", targetBg);
|
mProfile.put("target_bg", targetBg);
|
||||||
mProfile.add("carb_ratio", profile.getIc());
|
mProfile.put("carb_ratio", profile.getIc());
|
||||||
mProfile.add("sens", Profile.toMgdl(profile.getIsf().doubleValue(), units));
|
mProfile.put("sens", Profile.toMgdl(profile.getIsf().doubleValue(), units));
|
||||||
mProfile.add("max_daily_safety_multiplier", SP.getInt("openapsama_max_daily_safety_multiplier", 3));
|
mProfile.put("max_daily_safety_multiplier", SP.getInt("openapsama_max_daily_safety_multiplier", 3));
|
||||||
mProfile.add("current_basal_safety_multiplier", SP.getInt("openapsama_current_basal_safety_multiplier", 4));
|
mProfile.put("current_basal_safety_multiplier", SP.getInt("openapsama_current_basal_safety_multiplier", 4));
|
||||||
mProfile.add("skip_neutral_temps", true);
|
mProfile.put("skip_neutral_temps", true);
|
||||||
mProfile.add("current_basal", pump.getBaseBasalRate());
|
mProfile.put("current_basal", pump.getBaseBasalRate());
|
||||||
mProfile.add("temptargetSet", tempTargetSet);
|
mProfile.put("temptargetSet", tempTargetSet);
|
||||||
mProfile.add("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true));
|
mProfile.put("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true));
|
||||||
mProfile.add("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d));
|
mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d));
|
||||||
|
|
||||||
if (units.equals(Constants.MMOL)) {
|
if (units.equals(Constants.MMOL)) {
|
||||||
mProfile.add("out_units", "mmol/L");
|
mProfile.put("out_units", "mmol/L");
|
||||||
}
|
}
|
||||||
|
|
||||||
mV8rt.add(PARAM_profile, mProfile);
|
|
||||||
|
|
||||||
mCurrentTemp = new V8Object(mV8rt);
|
mCurrentTemp = new JSONObject();
|
||||||
mCurrentTemp.add("temp", "absolute");
|
mCurrentTemp.put("temp", "absolute");
|
||||||
mCurrentTemp.add("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
|
mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
|
||||||
mCurrentTemp.add("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
|
mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
|
||||||
|
|
||||||
// as we have non default temps longer than 30 mintues
|
// as we have non default temps longer than 30 mintues
|
||||||
TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (tempBasal != null) {
|
if (tempBasal != null) {
|
||||||
mCurrentTemp.add("minutesrunning", tempBasal.getRealDuration());
|
mCurrentTemp.put("minutesrunning", tempBasal.getRealDuration());
|
||||||
}
|
}
|
||||||
|
|
||||||
mV8rt.add(PARAM_currentTemp, mCurrentTemp);
|
mIobData = IobCobCalculatorPlugin.convertToJSONArray(iobArray);
|
||||||
|
|
||||||
mIobData = mV8rt.executeArrayScript(IobCobCalculatorPlugin.convertToJSONArray(iobArray).toString());
|
mGlucoseStatus = new JSONObject();
|
||||||
mV8rt.add(PARAM_iobData, mIobData);
|
mGlucoseStatus.put("glucose", glucoseStatus.glucose);
|
||||||
|
|
||||||
mGlucoseStatus = new V8Object(mV8rt);
|
|
||||||
mGlucoseStatus.add("glucose", glucoseStatus.glucose);
|
|
||||||
|
|
||||||
if (SP.getBoolean("always_use_shortavg", false)) {
|
if (SP.getBoolean("always_use_shortavg", false)) {
|
||||||
mGlucoseStatus.add("delta", glucoseStatus.short_avgdelta);
|
mGlucoseStatus.put("delta", glucoseStatus.short_avgdelta);
|
||||||
} else {
|
} else {
|
||||||
mGlucoseStatus.add("delta", glucoseStatus.delta);
|
mGlucoseStatus.put("delta", glucoseStatus.delta);
|
||||||
}
|
}
|
||||||
mGlucoseStatus.add("short_avgdelta", glucoseStatus.short_avgdelta);
|
mGlucoseStatus.put("short_avgdelta", glucoseStatus.short_avgdelta);
|
||||||
mGlucoseStatus.add("long_avgdelta", glucoseStatus.long_avgdelta);
|
mGlucoseStatus.put("long_avgdelta", glucoseStatus.long_avgdelta);
|
||||||
mV8rt.add(PARAM_glucoseStatus, mGlucoseStatus);
|
|
||||||
|
|
||||||
mMealData = new V8Object(mV8rt);
|
mMealData = new JSONObject();
|
||||||
mMealData.add("carbs", mealData.carbs);
|
mMealData.put("carbs", mealData.carbs);
|
||||||
mMealData.add("boluses", mealData.boluses);
|
mMealData.put("boluses", mealData.boluses);
|
||||||
mMealData.add("mealCOB", mealData.mealCOB);
|
mMealData.put("mealCOB", mealData.mealCOB);
|
||||||
mV8rt.add(PARAM_meal_data, mMealData);
|
|
||||||
|
|
||||||
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
||||||
mAutosensData = new V8Object(mV8rt);
|
mAutosensData = new JSONObject();
|
||||||
mAutosensData.add("ratio", autosensDataRatio);
|
mAutosensData.put("ratio", autosensDataRatio);
|
||||||
mV8rt.add(PARAM_autosens_data, mAutosensData);
|
|
||||||
} else {
|
} else {
|
||||||
mV8rt.addUndefined(PARAM_autosens_data);
|
mAutosensData = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void release() {
|
public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
|
||||||
mProfile.release();
|
|
||||||
mCurrentTemp.release();
|
if(jsonObject == null) return Undefined.instance;
|
||||||
mIobData.release();
|
|
||||||
mMealData.release();
|
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() {
|
||||||
mGlucoseStatus.release();
|
@Override
|
||||||
if (mAutosensData != null) {
|
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
|
||||||
mAutosensData.release();
|
return objects[1];
|
||||||
}
|
}
|
||||||
mV8rt.release();
|
});
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object makeParamArray(JSONArray jsonArray, Context rhino, Scriptable scope) {
|
||||||
|
//Object param = NativeJSON.parse(rhino, scope, "{myarray: " + jsonArray.toString() + " }", new Callable() {
|
||||||
|
Object param = NativeJSON.parse(rhino, scope, jsonArray.toString(), new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
|
||||||
|
return objects[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return param;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readFile(String filename) throws IOException {
|
public String readFile(String filename) throws IOException {
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package info.nightscout.androidaps.plugins.OpenAPSAMA;
|
package info.nightscout.androidaps.plugins.OpenAPSAMA;
|
||||||
|
|
||||||
import com.eclipsesource.v8.V8Object;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.mozilla.javascript.NativeObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -25,35 +24,34 @@ public class DetermineBasalResultAMA extends APSResult {
|
||||||
public double snoozeBG;
|
public double snoozeBG;
|
||||||
public IobTotal iob;
|
public IobTotal iob;
|
||||||
|
|
||||||
public DetermineBasalResultAMA(V8Object result, JSONObject j) {
|
public DetermineBasalResultAMA(NativeObject result, JSONObject j) {
|
||||||
date = new Date();
|
date = new Date();
|
||||||
json = j;
|
json = j;
|
||||||
if (result.contains("error")) {
|
if (result.containsKey("error")) {
|
||||||
reason = result.getString("error");
|
reason = result.get("error").toString();
|
||||||
changeRequested = false;
|
changeRequested = false;
|
||||||
rate = -1;
|
rate = -1;
|
||||||
duration = -1;
|
duration = -1;
|
||||||
} else {
|
} else {
|
||||||
reason = result.getString("reason");
|
reason = result.get("reason").toString();
|
||||||
if (result.contains("eventualBG")) eventualBG = result.getDouble("eventualBG");
|
if (result.containsKey("eventualBG")) eventualBG = (Double) result.get("eventualBG");
|
||||||
if (result.contains("snoozeBG")) snoozeBG = result.getDouble("snoozeBG");
|
if (result.containsKey("snoozeBG")) snoozeBG = (Double) result.get("snoozeBG");
|
||||||
if (result.contains("rate")) {
|
if (result.containsKey("rate")) {
|
||||||
rate = result.getDouble("rate");
|
rate = (Double) result.get("rate");
|
||||||
if (rate < 0d) rate = 0d;
|
if (rate < 0d) rate = 0d;
|
||||||
changeRequested = true;
|
changeRequested = true;
|
||||||
} else {
|
} else {
|
||||||
rate = -1;
|
rate = -1;
|
||||||
changeRequested = false;
|
changeRequested = false;
|
||||||
}
|
}
|
||||||
if (result.contains("duration")) {
|
if (result.containsKey("duration")) {
|
||||||
duration = result.getInteger("duration");
|
duration = ((Double)result.get("duration")).intValue();
|
||||||
//changeRequested as above
|
//changeRequested as above
|
||||||
} else {
|
} else {
|
||||||
duration = -1;
|
duration = -1;
|
||||||
changeRequested = false;
|
changeRequested = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DetermineBasalResultAMA() {
|
public DetermineBasalResultAMA() {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -28,15 +29,6 @@ import info.nightscout.utils.JSONFormatter;
|
||||||
public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnClickListener {
|
public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(OpenAPSAMAFragment.class);
|
private static Logger log = LoggerFactory.getLogger(OpenAPSAMAFragment.class);
|
||||||
|
|
||||||
private static OpenAPSAMAPlugin openAPSAMAPlugin;
|
|
||||||
|
|
||||||
public static OpenAPSAMAPlugin getPlugin() {
|
|
||||||
if(openAPSAMAPlugin ==null){
|
|
||||||
openAPSAMAPlugin = new OpenAPSAMAPlugin();
|
|
||||||
}
|
|
||||||
return openAPSAMAPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
Button run;
|
Button run;
|
||||||
TextView lastRunView;
|
TextView lastRunView;
|
||||||
TextView glucoseStatusView;
|
TextView glucoseStatusView;
|
||||||
|
@ -52,6 +44,7 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
try {
|
||||||
View view = inflater.inflate(R.layout.openapsama_fragment, container, false);
|
View view = inflater.inflate(R.layout.openapsama_fragment, container, false);
|
||||||
|
|
||||||
run = (Button) view.findViewById(R.id.openapsma_run);
|
run = (Button) view.findViewById(R.id.openapsma_run);
|
||||||
|
@ -69,13 +62,18 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
||||||
|
|
||||||
updateGUI();
|
updateGUI();
|
||||||
return view;
|
return view;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.openapsma_run:
|
case R.id.openapsma_run:
|
||||||
getPlugin().invoke("OpenAPSAMA button");
|
OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button");
|
||||||
Answers.getInstance().logCustom(new CustomEvent("OpenAPS_AMA_Run"));
|
Answers.getInstance().logCustom(new CustomEvent("OpenAPS_AMA_Run"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -99,12 +97,12 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DetermineBasalResultAMA lastAPSResult = getPlugin().lastAPSResult;
|
DetermineBasalResultAMA lastAPSResult = OpenAPSAMAPlugin.getPlugin().lastAPSResult;
|
||||||
if (lastAPSResult != null) {
|
if (lastAPSResult != null) {
|
||||||
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
||||||
requestView.setText(lastAPSResult.toSpanned());
|
requestView.setText(lastAPSResult.toSpanned());
|
||||||
}
|
}
|
||||||
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS = getPlugin().lastDetermineBasalAdapterAMAJS;
|
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS = OpenAPSAMAPlugin.getPlugin().lastDetermineBasalAdapterAMAJS;
|
||||||
if (determineBasalAdapterAMAJS != null) {
|
if (determineBasalAdapterAMAJS != null) {
|
||||||
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getGlucoseStatusParam()));
|
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getGlucoseStatusParam()));
|
||||||
currentTempView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getCurrentTempParam()));
|
currentTempView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getCurrentTempParam()));
|
||||||
|
@ -119,11 +117,11 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
||||||
mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam()));
|
mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam()));
|
||||||
scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug());
|
scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug());
|
||||||
}
|
}
|
||||||
if (getPlugin().lastAPSRun != null) {
|
if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != null) {
|
||||||
lastRunView.setText(getPlugin().lastAPSRun.toLocaleString());
|
lastRunView.setText(OpenAPSAMAPlugin.getPlugin().lastAPSRun.toLocaleString());
|
||||||
}
|
}
|
||||||
if (getPlugin().lastAutosensResult != null) {
|
if (OpenAPSAMAPlugin.getPlugin().lastAutosensResult != null) {
|
||||||
autosensDataView.setText(JSONFormatter.format(getPlugin().lastAutosensResult.json()));
|
autosensDataView.setText(JSONFormatter.format(OpenAPSAMAPlugin.getPlugin().lastAutosensResult.json()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,14 +39,23 @@ import info.nightscout.utils.ToastUtils;
|
||||||
public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
private static Logger log = LoggerFactory.getLogger(OpenAPSAMAPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(OpenAPSAMAPlugin.class);
|
||||||
|
|
||||||
|
private static OpenAPSAMAPlugin openAPSAMAPlugin;
|
||||||
|
|
||||||
|
public static OpenAPSAMAPlugin getPlugin() {
|
||||||
|
if (openAPSAMAPlugin == null) {
|
||||||
|
openAPSAMAPlugin = new OpenAPSAMAPlugin();
|
||||||
|
}
|
||||||
|
return openAPSAMAPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
// last values
|
// last values
|
||||||
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
|
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
|
||||||
Date lastAPSRun = null;
|
Date lastAPSRun = null;
|
||||||
DetermineBasalResultAMA lastAPSResult = null;
|
DetermineBasalResultAMA lastAPSResult = null;
|
||||||
AutosensResult lastAutosensResult = null;
|
AutosensResult lastAutosensResult = null;
|
||||||
|
|
||||||
boolean fragmentEnabled = false;
|
private boolean fragmentEnabled = false;
|
||||||
boolean fragmentVisible = true;
|
private boolean fragmentVisible = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -94,6 +103,11 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
if (type == APS) this.fragmentVisible = fragmentVisible;
|
if (type == APS) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return R.xml.pref_openapsama;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||||
if (type == APS) this.fragmentEnabled = fragmentEnabled;
|
if (type == APS) this.fragmentEnabled = fragmentEnabled;
|
||||||
|
@ -196,9 +210,9 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
maxBasal = verifyHardLimits(maxBasal, "max_basal", 0.1, 10);
|
maxBasal = verifyHardLimits(maxBasal, "max_basal", 0.1, 10);
|
||||||
|
|
||||||
if (!checkOnlyHardLimits(profile.getDia(), "dia", 2, 7)) return;
|
if (!checkOnlyHardLimits(profile.getDia(), "dia", 2, 7)) return;
|
||||||
if (!checkOnlyHardLimits(profile.getIc(profile.secondsFromMidnight()), "carbratio", 2, 100))
|
if (!checkOnlyHardLimits(profile.getIc(Profile.secondsFromMidnight()), "carbratio", 2, 100))
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", 2, 900))
|
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", 2, 900))
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
||||||
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
||||||
|
@ -213,11 +227,16 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
Profiler.log(log, "AMA data gathering", start);
|
Profiler.log(log, "AMA data gathering", start);
|
||||||
|
|
||||||
start = new Date();
|
start = new Date();
|
||||||
|
|
||||||
|
try {
|
||||||
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData,
|
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData,
|
||||||
lastAutosensResult.ratio, //autosensDataRatio
|
lastAutosensResult.ratio, //autosensDataRatio
|
||||||
isTempTarget,
|
isTempTarget,
|
||||||
SafeParse.stringToDouble(SP.getString("openapsama_min_5m_carbimpact", "3.0"))//min_5m_carbimpact
|
SafeParse.stringToDouble(SP.getString("openapsama_min_5m_carbimpact", "3.0"))//min_5m_carbimpact
|
||||||
);
|
);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.error("Unable to set data: " + e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DetermineBasalResultAMA determineBasalResultAMA = determineBasalAdapterAMAJS.invoke();
|
DetermineBasalResultAMA determineBasalResultAMA = determineBasalAdapterAMAJS.invoke();
|
||||||
|
@ -235,8 +254,6 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
determineBasalResultAMA.iob = iobArray[0];
|
determineBasalResultAMA.iob = iobArray[0];
|
||||||
|
|
||||||
determineBasalAdapterAMAJS.release();
|
|
||||||
|
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
package info.nightscout.androidaps.plugins.OpenAPSMA;
|
package info.nightscout.androidaps.plugins.OpenAPSMA;
|
||||||
|
|
||||||
import com.eclipsesource.v8.JavaVoidCallback;
|
|
||||||
import com.eclipsesource.v8.V8;
|
|
||||||
import com.eclipsesource.v8.V8Array;
|
|
||||||
import com.eclipsesource.v8.V8Object;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.mozilla.javascript.Callable;
|
||||||
|
import org.mozilla.javascript.Context;
|
||||||
|
import org.mozilla.javascript.Function;
|
||||||
|
import org.mozilla.javascript.NativeJSON;
|
||||||
|
import org.mozilla.javascript.NativeObject;
|
||||||
|
import org.mozilla.javascript.RhinoException;
|
||||||
|
import org.mozilla.javascript.Scriptable;
|
||||||
|
import org.mozilla.javascript.ScriptableObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
|
@ -26,20 +30,12 @@ import info.nightscout.utils.SP;
|
||||||
public class DetermineBasalAdapterMAJS {
|
public class DetermineBasalAdapterMAJS {
|
||||||
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterMAJS.class);
|
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterMAJS.class);
|
||||||
|
|
||||||
|
|
||||||
private ScriptReader mScriptReader = null;
|
private ScriptReader mScriptReader = null;
|
||||||
V8 mV8rt;
|
private JSONObject mProfile;
|
||||||
private V8Object mProfile;
|
private JSONObject mGlucoseStatus;
|
||||||
private V8Object mGlucoseStatus;
|
private JSONObject mIobData;
|
||||||
private V8Object mIobData;
|
private JSONObject mMealData;
|
||||||
private V8Object mMealData;
|
private JSONObject mCurrentTemp;
|
||||||
private V8Object mCurrentTemp;
|
|
||||||
|
|
||||||
private final String PARAM_currentTemp = "currentTemp";
|
|
||||||
private final String PARAM_iobData = "iobData";
|
|
||||||
private final String PARAM_glucoseStatus = "glucose_status";
|
|
||||||
private final String PARAM_profile = "profile";
|
|
||||||
private final String PARAM_meal_data = "meal_data";
|
|
||||||
|
|
||||||
private String storedCurrentTemp = null;
|
private String storedCurrentTemp = null;
|
||||||
public String storedIobData = null;
|
public String storedIobData = null;
|
||||||
|
@ -47,104 +43,90 @@ public class DetermineBasalAdapterMAJS {
|
||||||
private String storedProfile = null;
|
private String storedProfile = null;
|
||||||
private String storedMeal_data = null;
|
private String storedMeal_data = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Main code
|
|
||||||
*/
|
|
||||||
|
|
||||||
public DetermineBasalAdapterMAJS(ScriptReader scriptReader) throws IOException {
|
public DetermineBasalAdapterMAJS(ScriptReader scriptReader) throws IOException {
|
||||||
mV8rt = V8.createV8Runtime();
|
|
||||||
mScriptReader = scriptReader;
|
mScriptReader = scriptReader;
|
||||||
|
|
||||||
init();
|
|
||||||
initLogCallback();
|
|
||||||
initProcessExitCallback();
|
|
||||||
initModuleParent();
|
|
||||||
loadScript();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init() {
|
|
||||||
// Profile
|
|
||||||
mProfile = new V8Object(mV8rt);
|
|
||||||
mProfile.add("max_iob", 0);
|
|
||||||
mProfile.add("dia", 0);
|
|
||||||
mProfile.add("type", "current");
|
|
||||||
mProfile.add("max_daily_basal", 0);
|
|
||||||
mProfile.add("max_basal", 0);
|
|
||||||
mProfile.add("max_bg", 0);
|
|
||||||
mProfile.add("min_bg", 0);
|
|
||||||
mProfile.add("carb_ratio", 0);
|
|
||||||
mProfile.add("sens", 0);
|
|
||||||
mProfile.add("current_basal", 0);
|
|
||||||
mV8rt.add(PARAM_profile, mProfile);
|
|
||||||
// Current temp
|
|
||||||
mCurrentTemp = new V8Object(mV8rt);
|
|
||||||
mCurrentTemp.add("temp", "absolute");
|
|
||||||
mCurrentTemp.add("duration", 0);
|
|
||||||
mCurrentTemp.add("rate", 0);
|
|
||||||
mV8rt.add(PARAM_currentTemp, mCurrentTemp);
|
|
||||||
// IOB data
|
|
||||||
mIobData = new V8Object(mV8rt);
|
|
||||||
mIobData.add("iob", 0); //netIob
|
|
||||||
mIobData.add("activity", 0); //netActivity
|
|
||||||
mIobData.add("bolussnooze", 0); //bolusIob
|
|
||||||
mIobData.add("basaliob", 0);
|
|
||||||
mIobData.add("netbasalinsulin", 0);
|
|
||||||
mIobData.add("hightempinsulin", 0);
|
|
||||||
mV8rt.add(PARAM_iobData, mIobData);
|
|
||||||
// Glucose status
|
|
||||||
mGlucoseStatus = new V8Object(mV8rt);
|
|
||||||
mGlucoseStatus.add("glucose", 0);
|
|
||||||
mGlucoseStatus.add("delta", 0);
|
|
||||||
mGlucoseStatus.add("avgdelta", 0);
|
|
||||||
mV8rt.add(PARAM_glucoseStatus, mGlucoseStatus);
|
|
||||||
// Meal data
|
|
||||||
mMealData = new V8Object(mV8rt);
|
|
||||||
mMealData.add("carbs", 0);
|
|
||||||
mMealData.add("boluses", 0);
|
|
||||||
mV8rt.add(PARAM_meal_data, mMealData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DetermineBasalResultMA invoke() {
|
public DetermineBasalResultMA invoke() {
|
||||||
mV8rt.executeVoidScript(
|
DetermineBasalResultMA determineBasalResultMA = null;
|
||||||
"console.error(\"determine_basal(\"+\n" +
|
|
||||||
"JSON.stringify(" + PARAM_glucoseStatus + ")+ \", \" +\n" +
|
|
||||||
"JSON.stringify(" + PARAM_currentTemp + ")+ \", \" +\n" +
|
|
||||||
"JSON.stringify(" + PARAM_iobData + ")+ \", \" +\n" +
|
|
||||||
"JSON.stringify(" + PARAM_profile + ")+ \", \" +\n" +
|
|
||||||
"JSON.stringify(" + PARAM_meal_data + ")+ \") \");"
|
|
||||||
);
|
|
||||||
mV8rt.executeVoidScript(
|
|
||||||
"var rT = determine_basal(" +
|
|
||||||
PARAM_glucoseStatus + ", " +
|
|
||||||
PARAM_currentTemp + ", " +
|
|
||||||
PARAM_iobData + ", " +
|
|
||||||
PARAM_profile + ", " +
|
|
||||||
"undefined, " +
|
|
||||||
PARAM_meal_data + ", " +
|
|
||||||
"setTempBasal" +
|
|
||||||
");");
|
|
||||||
|
|
||||||
|
Context rhino = Context.enter();
|
||||||
|
Scriptable scope = rhino.initStandardObjects();
|
||||||
|
// Turn off optimization to make Rhino Android compatible
|
||||||
|
rhino.setOptimizationLevel(-1);
|
||||||
|
|
||||||
String ret = mV8rt.executeStringScript("JSON.stringify(rT);");
|
|
||||||
if (Config.logAPSResult)
|
|
||||||
log.debug("Result: " + ret);
|
|
||||||
|
|
||||||
V8Object v8ObjectReuslt = mV8rt.getObject("rT");
|
|
||||||
|
|
||||||
DetermineBasalResultMA result = null;
|
|
||||||
try {
|
try {
|
||||||
result = new DetermineBasalResultMA(v8ObjectReuslt, new JSONObject(ret));
|
|
||||||
|
//register logger callback for console.log and console.error
|
||||||
|
ScriptableObject.defineClass(scope, LoggerCallback.class);
|
||||||
|
Scriptable myLogger = rhino.newObject(scope, "LoggerCallback", null);
|
||||||
|
scope.put("console", scope, myLogger);
|
||||||
|
|
||||||
|
//set module parent
|
||||||
|
rhino.evaluateString(scope, "var module = {\"parent\":Boolean(1)};", "JavaScript", 0, null);
|
||||||
|
|
||||||
|
//generate functions "determine_basal" and "setTempBasal"
|
||||||
|
rhino.evaluateString(scope, readFile("OpenAPSMA/determine-basal.js"), "JavaScript", 0, null);
|
||||||
|
|
||||||
|
String setTempBasalCode = "var setTempBasal = function (rate, duration, profile, rT, offline) {" +
|
||||||
|
"rT.duration = duration;\n" +
|
||||||
|
" rT.rate = rate;" +
|
||||||
|
"return rT;" +
|
||||||
|
"};";
|
||||||
|
rhino.evaluateString(scope, setTempBasalCode, "setTempBasal.js", 0, null);
|
||||||
|
Object determineBasalObj = scope.get("determine_basal", scope);
|
||||||
|
Object setTempBasalObj = scope.get("setTempBasal", scope);
|
||||||
|
|
||||||
|
//call determine-basal
|
||||||
|
if (determineBasalObj instanceof Function && setTempBasalObj instanceof Function) {
|
||||||
|
Function determineBasalJS = (Function) determineBasalObj;
|
||||||
|
Function setTempBasalJS = (Function) setTempBasalObj;
|
||||||
|
|
||||||
|
//prepare parameters
|
||||||
|
Object[] params = new Object[]{
|
||||||
|
makeParam(mGlucoseStatus, rhino, scope),
|
||||||
|
makeParam(mCurrentTemp, rhino, scope),
|
||||||
|
makeParam(mIobData, rhino, scope),
|
||||||
|
makeParam(mProfile, rhino, scope),
|
||||||
|
"undefined",
|
||||||
|
makeParam(mMealData, rhino, scope),
|
||||||
|
setTempBasalJS};
|
||||||
|
|
||||||
|
NativeObject jsResult = (NativeObject) determineBasalJS.call(rhino, scope, scope, params);
|
||||||
|
|
||||||
|
// Parse the jsResult object to a JSON-String
|
||||||
|
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
||||||
|
if (Config.logAPSResult)
|
||||||
|
log.debug("Result: " + result);
|
||||||
|
try {
|
||||||
|
determineBasalResultMA = new DetermineBasalResultMA(jsResult, new JSONObject(result));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("Problem loading JS Functions");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.debug("IOException");
|
||||||
|
} catch (RhinoException e) {
|
||||||
|
log.error("RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
log.error(e.toString());
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
log.error(e.toString());
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
log.error(e.toString());
|
||||||
|
} finally {
|
||||||
|
Context.exit();
|
||||||
|
}
|
||||||
|
|
||||||
storedGlucoseStatus = mV8rt.executeStringScript("JSON.stringify(" + PARAM_glucoseStatus + ");");
|
storedGlucoseStatus = mGlucoseStatus.toString();
|
||||||
storedIobData = mV8rt.executeStringScript("JSON.stringify(" + PARAM_iobData + ");");
|
storedIobData = mIobData.toString();
|
||||||
storedCurrentTemp = mV8rt.executeStringScript("JSON.stringify(" + PARAM_currentTemp + ");");
|
storedCurrentTemp = mCurrentTemp.toString();
|
||||||
storedProfile = mV8rt.executeStringScript("JSON.stringify(" + PARAM_profile + ");");
|
storedProfile = mProfile.toString();
|
||||||
storedMeal_data = mV8rt.executeStringScript("JSON.stringify(" + PARAM_meal_data + ");");
|
storedMeal_data = mMealData.toString();
|
||||||
|
|
||||||
return result;
|
return determineBasalResultMA;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getGlucoseStatusParam() {
|
String getGlucoseStatusParam() {
|
||||||
|
@ -167,57 +149,6 @@ public class DetermineBasalAdapterMAJS {
|
||||||
return storedMeal_data;
|
return storedMeal_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadScript() throws IOException {
|
|
||||||
mV8rt.executeVoidScript(
|
|
||||||
readFile("OpenAPSMA/determine-basal.js"),
|
|
||||||
"OpenAPSMA/bin/oref0-determine-basal.js",
|
|
||||||
0);
|
|
||||||
mV8rt.executeVoidScript("var determine_basal = module.exports;");
|
|
||||||
mV8rt.executeVoidScript(
|
|
||||||
"var setTempBasal = function (rate, duration, profile, rT, offline) {" +
|
|
||||||
"rT.duration = duration;\n" +
|
|
||||||
" rT.rate = rate;" +
|
|
||||||
"return rT;" +
|
|
||||||
"};",
|
|
||||||
"setTempBasal.js",
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initModuleParent() {
|
|
||||||
mV8rt.executeVoidScript("var module = {\"parent\":Boolean(1)};");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initProcessExitCallback() {
|
|
||||||
JavaVoidCallback callbackProccessExit = new JavaVoidCallback() {
|
|
||||||
@Override
|
|
||||||
public void invoke(V8Object arg0, V8Array parameters) {
|
|
||||||
if (parameters.length() > 0) {
|
|
||||||
Object arg1 = parameters.get(0);
|
|
||||||
log.error("ProccessExit " + arg1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mV8rt.registerJavaMethod(callbackProccessExit, "proccessExit");
|
|
||||||
mV8rt.executeVoidScript("var process = {\"exit\": function () { proccessExit(); } };");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initLogCallback() {
|
|
||||||
JavaVoidCallback callbackLog = new JavaVoidCallback() {
|
|
||||||
@Override
|
|
||||||
public void invoke(V8Object arg0, V8Array parameters) {
|
|
||||||
if (parameters.length() > 0) {
|
|
||||||
Object arg1 = parameters.get(0);
|
|
||||||
if (Config.logAPSResult)
|
|
||||||
log.debug("Input params: " + arg1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mV8rt.registerJavaMethod(callbackLog, "log");
|
|
||||||
mV8rt.executeVoidScript("var console = {\"log\":log, \"error\":log};");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setData(Profile profile,
|
public void setData(Profile profile,
|
||||||
double maxIob,
|
double maxIob,
|
||||||
double maxBasal,
|
double maxBasal,
|
||||||
|
@ -227,57 +158,52 @@ public class DetermineBasalAdapterMAJS {
|
||||||
PumpInterface pump,
|
PumpInterface pump,
|
||||||
IobTotal iobData,
|
IobTotal iobData,
|
||||||
GlucoseStatus glucoseStatus,
|
GlucoseStatus glucoseStatus,
|
||||||
MealData mealData) {
|
MealData mealData) throws JSONException {
|
||||||
|
|
||||||
String units = profile.getUnits();
|
String units = profile.getUnits();
|
||||||
|
|
||||||
mProfile.add("max_iob", maxIob);
|
mProfile = new JSONObject();
|
||||||
mProfile.add("dia", Math.min(profile.getDia(), 3d));
|
mProfile.put("max_iob", maxIob);
|
||||||
mProfile.add("type", "current");
|
mProfile.put("dia", Math.min(profile.getDia(), 3d));
|
||||||
mProfile.add("max_daily_basal", profile.getMaxDailyBasal());
|
mProfile.put("type", "current");
|
||||||
mProfile.add("max_basal", maxBasal);
|
mProfile.put("max_daily_basal", profile.getMaxDailyBasal());
|
||||||
mProfile.add("min_bg", minBg);
|
mProfile.put("max_basal", maxBasal);
|
||||||
mProfile.add("max_bg", maxBg);
|
mProfile.put("min_bg", minBg);
|
||||||
mProfile.add("target_bg", targetBg);
|
mProfile.put("max_bg", maxBg);
|
||||||
mProfile.add("carb_ratio", profile.getIc());
|
mProfile.put("target_bg", targetBg);
|
||||||
mProfile.add("sens", Profile.toMgdl(profile.getIsf().doubleValue(), units));
|
mProfile.put("carb_ratio", profile.getIc());
|
||||||
|
mProfile.put("sens", Profile.toMgdl(profile.getIsf().doubleValue(), units));
|
||||||
|
|
||||||
mProfile.add("current_basal", pump.getBaseBasalRate());
|
mProfile.put("current_basal", pump.getBaseBasalRate());
|
||||||
|
|
||||||
if (units.equals(Constants.MMOL)) {
|
if (units.equals(Constants.MMOL)) {
|
||||||
mProfile.add("out_units", "mmol/L");
|
mProfile.put("out_units", "mmol/L");
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrentTemp.add("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
|
mCurrentTemp = new JSONObject();
|
||||||
mCurrentTemp.add("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
|
mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
|
||||||
|
mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
|
||||||
|
|
||||||
mIobData.add("iob", iobData.iob); //netIob
|
mIobData = new JSONObject();
|
||||||
mIobData.add("activity", iobData.activity); //netActivity
|
mIobData.put("iob", iobData.iob); //netIob
|
||||||
mIobData.add("bolussnooze", iobData.bolussnooze); //bolusIob
|
mIobData.put("activity", iobData.activity); //netActivity
|
||||||
mIobData.add("basaliob", iobData.basaliob);
|
mIobData.put("bolussnooze", iobData.bolussnooze); //bolusIob
|
||||||
mIobData.add("netbasalinsulin", iobData.netbasalinsulin);
|
mIobData.put("basaliob", iobData.basaliob);
|
||||||
mIobData.add("hightempinsulin", iobData.hightempinsulin);
|
mIobData.put("netbasalinsulin", iobData.netbasalinsulin);
|
||||||
|
mIobData.put("hightempinsulin", iobData.hightempinsulin);
|
||||||
|
|
||||||
mGlucoseStatus.add("glucose", glucoseStatus.glucose);
|
mGlucoseStatus = new JSONObject();
|
||||||
|
mGlucoseStatus.put("glucose", glucoseStatus.glucose);
|
||||||
if (SP.getBoolean("always_use_shortavg", false)) {
|
if (SP.getBoolean("always_use_shortavg", false)) {
|
||||||
mGlucoseStatus.add("delta", glucoseStatus.short_avgdelta);
|
mGlucoseStatus.put("delta", glucoseStatus.short_avgdelta);
|
||||||
} else {
|
} else {
|
||||||
mGlucoseStatus.add("delta", glucoseStatus.delta);
|
mGlucoseStatus.put("delta", glucoseStatus.delta);
|
||||||
}
|
}
|
||||||
mGlucoseStatus.add("avgdelta", glucoseStatus.avgdelta);
|
mGlucoseStatus.put("avgdelta", glucoseStatus.avgdelta);
|
||||||
|
|
||||||
mMealData.add("carbs", mealData.carbs);
|
mMealData = new JSONObject();
|
||||||
mMealData.add("boluses", mealData.boluses);
|
mMealData.put("carbs", mealData.carbs);
|
||||||
}
|
mMealData.put("boluses", mealData.boluses);
|
||||||
|
|
||||||
|
|
||||||
public void release() {
|
|
||||||
mProfile.release();
|
|
||||||
mCurrentTemp.release();
|
|
||||||
mIobData.release();
|
|
||||||
mMealData.release();
|
|
||||||
mGlucoseStatus.release();
|
|
||||||
mV8rt.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readFile(String filename) throws IOException {
|
public String readFile(String filename) throws IOException {
|
||||||
|
@ -289,4 +215,14 @@ public class DetermineBasalAdapterMAJS {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
|
||||||
|
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
|
||||||
|
return objects[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
package info.nightscout.androidaps.plugins.OpenAPSMA;
|
package info.nightscout.androidaps.plugins.OpenAPSMA;
|
||||||
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
|
|
||||||
import com.eclipsesource.v8.V8Object;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.mozilla.javascript.NativeObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -22,38 +18,37 @@ public class DetermineBasalResultMA extends APSResult {
|
||||||
public String mealAssist;
|
public String mealAssist;
|
||||||
public IobTotal iob;
|
public IobTotal iob;
|
||||||
|
|
||||||
public DetermineBasalResultMA(V8Object result, JSONObject j) {
|
public DetermineBasalResultMA(NativeObject result, JSONObject j) {
|
||||||
json = j;
|
json = j;
|
||||||
if (result.contains("error")) {
|
if (result.containsKey("error")) {
|
||||||
reason = result.getString("error");
|
reason = (String) result.get("error");
|
||||||
changeRequested = false;
|
changeRequested = false;
|
||||||
rate = -1;
|
rate = -1;
|
||||||
duration = -1;
|
duration = -1;
|
||||||
mealAssist = "";
|
mealAssist = "";
|
||||||
} else {
|
} else {
|
||||||
reason = result.getString("reason");
|
reason = result.get("reason").toString();
|
||||||
eventualBG = result.getDouble("eventualBG");
|
eventualBG = (Double) result.get("eventualBG");
|
||||||
snoozeBG = result.getDouble("snoozeBG");
|
snoozeBG = (Double) result.get("snoozeBG");
|
||||||
if (result.contains("rate")) {
|
if (result.containsKey("rate")) {
|
||||||
rate = result.getDouble("rate");
|
rate = (Double) result.get("rate");
|
||||||
if (rate < 0d) rate = 0d;
|
if (rate < 0d) rate = 0d;
|
||||||
changeRequested = true;
|
changeRequested = true;
|
||||||
} else {
|
} else {
|
||||||
rate = -1;
|
rate = -1;
|
||||||
changeRequested = false;
|
changeRequested = false;
|
||||||
}
|
}
|
||||||
if (result.contains("duration")) {
|
if (result.containsKey("duration")) {
|
||||||
duration = result.getInteger("duration");
|
duration = ((Double) result.get("duration")).intValue();
|
||||||
//changeRequested as above
|
//changeRequested as above
|
||||||
} else {
|
} else {
|
||||||
duration = -1;
|
duration = -1;
|
||||||
changeRequested = false;
|
changeRequested = false;
|
||||||
}
|
}
|
||||||
if (result.contains("mealAssist")) {
|
if (result.containsKey("mealAssist")) {
|
||||||
mealAssist = result.getString("mealAssist");
|
mealAssist = result.get("mealAssist").toString();
|
||||||
} else mealAssist = "";
|
} else mealAssist = "";
|
||||||
}
|
}
|
||||||
result.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DetermineBasalResultMA() {
|
public DetermineBasalResultMA() {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue