commit
8c4ccf8b49
273 changed files with 8640 additions and 2959 deletions
|
@ -7,7 +7,7 @@ android:
|
||||||
components:
|
components:
|
||||||
- platform-tools
|
- platform-tools
|
||||||
- tools
|
- tools
|
||||||
- build-tools-25.0.2
|
- build-tools-26.0.2
|
||||||
- android-23
|
- android-23
|
||||||
- extra-google-m2repository
|
- extra-google-m2repository
|
||||||
- extra-android-m2repository
|
- extra-android-m2repository
|
||||||
|
|
|
@ -37,7 +37,7 @@ def generateGitBuild = { ->
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 23
|
compileSdkVersion 23
|
||||||
buildToolsVersion "25.0.2"
|
buildToolsVersion "26.0.2"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "info.nightscout.androidaps"
|
applicationId "info.nightscout.androidaps"
|
||||||
|
@ -45,12 +45,11 @@ android {
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
versionCode 1500
|
versionCode 1500
|
||||||
version "1.54-dev"
|
version "1.56-dev"
|
||||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||||
buildConfigField "String", "BUILDVERSION", generateGitBuild()
|
buildConfigField "String", "BUILDVERSION", generateGitBuild()
|
||||||
|
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
|
|
||||||
moduleName "BleCommandUtil"
|
moduleName "BleCommandUtil"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +75,7 @@ android {
|
||||||
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
||||||
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
||||||
buildConfigField "boolean", "CLOSEDLOOP", "true"
|
buildConfigField "boolean", "CLOSEDLOOP", "true"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "false"
|
||||||
}
|
}
|
||||||
openloop {
|
openloop {
|
||||||
dimension "standard"
|
dimension "standard"
|
||||||
|
@ -88,6 +88,7 @@ android {
|
||||||
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
||||||
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
||||||
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "false"
|
||||||
}
|
}
|
||||||
pumpcontrol {
|
pumpcontrol {
|
||||||
dimension "standard"
|
dimension "standard"
|
||||||
|
@ -100,6 +101,7 @@ android {
|
||||||
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
||||||
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
||||||
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "false"
|
||||||
}
|
}
|
||||||
nsclient {
|
nsclient {
|
||||||
dimension "standard"
|
dimension "standard"
|
||||||
|
@ -112,6 +114,20 @@ android {
|
||||||
buildConfigField "boolean", "PUMPDRIVERS", "false"
|
buildConfigField "boolean", "PUMPDRIVERS", "false"
|
||||||
buildConfigField "boolean", "NSCLIENTOLNY", "true"
|
buildConfigField "boolean", "NSCLIENTOLNY", "true"
|
||||||
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "false"
|
||||||
|
}
|
||||||
|
g5uploader {
|
||||||
|
dimension "standard"
|
||||||
|
resValue "string", "app_name", "NSClient"
|
||||||
|
versionName version + "-nsclient"
|
||||||
|
manifestPlaceholders = [
|
||||||
|
appIcon: "@mipmap/yellowowl"
|
||||||
|
]
|
||||||
|
buildConfigField "boolean", "APS", "false"
|
||||||
|
buildConfigField "boolean", "PUMPDRIVERS", "false"
|
||||||
|
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
||||||
|
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,9 +166,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'
|
||||||
|
@ -162,7 +178,7 @@ dependencies {
|
||||||
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
|
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
|
||||||
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
|
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
|
||||||
compile(name: 'android-edittext-validator-v1.3.4-mod', ext: 'aar')
|
compile(name: 'android-edittext-validator-v1.3.4-mod', ext: 'aar')
|
||||||
compile ('com.google.android:flexbox:0.3.0') {
|
compile('com.google.android:flexbox:0.3.0') {
|
||||||
exclude group: 'com.android.support'
|
exclude group: 'com.android.support'
|
||||||
}
|
}
|
||||||
compile('io.socket:socket.io-client:0.8.3') {
|
compile('io.socket:socket.io-client:0.8.3') {
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
<activity
|
<activity
|
||||||
android:name=".plugins.Overview.Dialogs.BolusProgressHelperActivity"
|
android:name=".plugins.Overview.Dialogs.BolusProgressHelperActivity"
|
||||||
android:theme="@style/Theme.AppCompat.Translucent" />
|
android:theme="@style/Theme.AppCompat.Translucent" />
|
||||||
|
<activity
|
||||||
|
android:name=".plugins.Overview.Dialogs.ErrorHelperActivity"
|
||||||
|
android:theme="@style/Theme.AppCompat.Translucent" />
|
||||||
<activity android:name=".AgreementActivity" />
|
<activity android:name=".AgreementActivity" />
|
||||||
<activity android:name=".plugins.PumpDanaR.activities.DanaRHistoryActivity" />
|
<activity android:name=".plugins.PumpDanaR.activities.DanaRHistoryActivity" />
|
||||||
<activity android:name=".plugins.PumpDanaR.activities.DanaRStatsActivity" />
|
<activity android:name=".plugins.PumpDanaR.activities.DanaRStatsActivity" />
|
||||||
|
@ -72,6 +75,8 @@
|
||||||
<action android:name="com.eveningoutpost.dexdrip.NS_EMULATOR" />
|
<action android:name="com.eveningoutpost.dexdrip.NS_EMULATOR" />
|
||||||
<!-- Receiver from glimp -->
|
<!-- Receiver from glimp -->
|
||||||
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
|
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
|
||||||
|
<!-- Receiver from DexcomG5 -->
|
||||||
|
<action android:name="com.dexcom.cgm.DATA" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<!-- Receiver keepalive, scheduled every 30 min -->
|
<!-- Receiver keepalive, scheduled every 30 min -->
|
||||||
|
@ -140,6 +145,9 @@
|
||||||
android:name=".Services.AlarmSoundService"
|
android:name=".Services.AlarmSoundService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
<service
|
||||||
|
android:name=".plugins.Overview.notifications.DismissNotificationService"
|
||||||
|
android:exported="false"></service>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="io.fabric.ApiKey"
|
android:name="io.fabric.ApiKey"
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<maxHistory>120</maxHistory>
|
<maxHistory>120</maxHistory>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level [%file:%line]: %msg%n</pattern>
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level [%class:%line]: %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
<pattern>%logger{0}</pattern>
|
<pattern>%logger{0}</pattern>
|
||||||
</tagEncoder>
|
</tagEncoder>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>[%thread] %-5level [%file:%line]: %msg%n</pattern>
|
<pattern>[%thread] %-5level [%class:%line]: %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
|
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,30 +4,25 @@ package info.nightscout.androidaps;
|
||||||
* Created by mike on 07.06.2016.
|
* Created by mike on 07.06.2016.
|
||||||
*/
|
*/
|
||||||
public class Config {
|
public class Config {
|
||||||
public static int SUPPORTEDNSVERSION = 1000; // 0.10.00
|
public static int SUPPORTEDNSVERSION = 1002; // 0.10.00
|
||||||
|
|
||||||
// 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 NSCLIENT = BuildConfig.NSCLIENTOLNY;
|
public static final boolean NSCLIENT = BuildConfig.NSCLIENTOLNY;
|
||||||
|
public static final boolean G5UPLOADER = BuildConfig.G5UPLOADER;
|
||||||
|
|
||||||
public static final boolean DANAR = true && BuildConfig.PUMPDRIVERS;
|
public static final boolean DANAR = BuildConfig.PUMPDRIVERS;
|
||||||
public static final boolean DANARv2 = true && BuildConfig.PUMPDRIVERS;
|
|
||||||
|
|
||||||
public static final boolean ACTION = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean ACTION = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
public static final boolean VIRTUALPUMP = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean VIRTUALPUMP = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
public static final boolean MDI = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean MDI = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
public static final boolean OTHERPROFILES = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean OTHERPROFILES = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
public static final boolean SAFETY = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean SAFETY = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
|
|
||||||
public static final boolean SMSCOMMUNICATORENABLED = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean SMSCOMMUNICATORENABLED = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
|
|
||||||
|
|
||||||
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,6 +35,7 @@ public class Config {
|
||||||
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 = false;
|
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;
|
||||||
|
|
|
@ -54,8 +54,12 @@ public class Constants {
|
||||||
|
|
||||||
//Screen: Threshold for width/height to go into small width/height layout
|
//Screen: Threshold for width/height to go into small width/height layout
|
||||||
public static final int SMALL_WIDTH = 320;
|
public static final int SMALL_WIDTH = 320;
|
||||||
public static final int SMALL_HEIGHT = 320;
|
public static final int SMALL_HEIGHT = 480;
|
||||||
|
|
||||||
//Autosens
|
//Autosens
|
||||||
public static final double DEVIATION_TO_BE_EQUAL = 2.0;
|
public static final double DEVIATION_TO_BE_EQUAL = 2.0;
|
||||||
|
|
||||||
|
// Pump
|
||||||
|
public static final int PUMP_MAX_CONNECTION_TIME_IN_SECONDS = 120 - 1;
|
||||||
|
public static final int MIN_WATCHDOG_INTERVAL_IN_SECONDS = 12 * 60;
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,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);
|
||||||
|
@ -368,7 +369,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
case R.id.nav_about:
|
case R.id.nav_about:
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
|
||||||
builder.setTitle(getString(R.string.app_name) + " " + BuildConfig.VERSION);
|
builder.setTitle(getString(R.string.app_name) + " " + BuildConfig.VERSION);
|
||||||
if (Config.NSCLIENT)
|
if (Config.NSCLIENT|| Config.G5UPLOADER)
|
||||||
builder.setIcon(R.mipmap.yellowowl);
|
builder.setIcon(R.mipmap.yellowowl);
|
||||||
else
|
else
|
||||||
builder.setIcon(R.mipmap.blueowl);
|
builder.setIcon(R.mipmap.blueowl);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package info.nightscout.androidaps;
|
package info.nightscout.androidaps;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
@ -13,6 +12,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;
|
||||||
|
@ -24,13 +24,13 @@ import info.nightscout.androidaps.Services.Intents;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
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.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.ObjectivesPlugin;
|
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;
|
||||||
|
@ -49,25 +49,22 @@ import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin;
|
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.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
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.PumpMDI.MDIPlugin;
|
import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin;
|
||||||
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.SmsCommunicator.SmsCommunicatorPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin;
|
||||||
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.TreatmentsPlugin;
|
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;
|
||||||
|
@ -103,7 +100,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();
|
||||||
|
|
||||||
|
@ -127,12 +125,12 @@ public class MainApp extends Application {
|
||||||
if (Config.DANAR) pluginsList.add(DanaRKoreanPlugin.getPlugin());
|
if (Config.DANAR) pluginsList.add(DanaRKoreanPlugin.getPlugin());
|
||||||
if (Config.DANAR) pluginsList.add(DanaRv2Plugin.getPlugin());
|
if (Config.DANAR) pluginsList.add(DanaRv2Plugin.getPlugin());
|
||||||
if (Config.DANAR) pluginsList.add(DanaRSPlugin.getPlugin());
|
if (Config.DANAR) pluginsList.add(DanaRSPlugin.getPlugin());
|
||||||
pluginsList.add(CareportalFragment.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(LoopPlugin.getPlugin());
|
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
|
||||||
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAPlugin.getPlugin());
|
if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin());
|
||||||
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
||||||
pluginsList.add(NSProfilePlugin.getPlugin());
|
pluginsList.add(NSProfilePlugin.getPlugin());
|
||||||
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin());
|
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin());
|
||||||
if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin());
|
if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin());
|
||||||
|
@ -141,17 +139,21 @@ public class MainApp extends Application {
|
||||||
pluginsList.add(TreatmentsPlugin.getPlugin());
|
pluginsList.add(TreatmentsPlugin.getPlugin());
|
||||||
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
||||||
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT)
|
if (!Config.NSCLIENT && !Config.G5UPLOADER)
|
||||||
pluginsList.add(SourceXdripPlugin.getPlugin());
|
pluginsList.add(SourceXdripPlugin.getPlugin());
|
||||||
|
if (!Config.G5UPLOADER)
|
||||||
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT)
|
if (!Config.NSCLIENT && !Config.G5UPLOADER)
|
||||||
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT)
|
if (!Config.NSCLIENT && !Config.G5UPLOADER)
|
||||||
pluginsList.add(SourceGlimpPlugin.getPlugin());
|
pluginsList.add(SourceGlimpPlugin.getPlugin());
|
||||||
|
if (!Config.NSCLIENT)
|
||||||
|
pluginsList.add(SourceDexcomG5Plugin.getPlugin());
|
||||||
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
|
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
|
||||||
|
pluginsList.add(FoodPlugin.getPlugin());
|
||||||
|
|
||||||
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(NSClientInternalPlugin.getPlugin());
|
pluginsList.add(NSClientInternalPlugin.getPlugin());
|
||||||
|
|
||||||
|
@ -165,19 +167,14 @@ public class MainApp extends Application {
|
||||||
else
|
else
|
||||||
Answers.getInstance().logCustom(new CustomEvent("AppStart"));
|
Answers.getInstance().logCustom(new CustomEvent("AppStart"));
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
startKeepAliveService();
|
|
||||||
|
|
||||||
Thread t = new Thread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SystemClock.sleep(5000);
|
SystemClock.sleep(5000);
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().readStatus("Initialization", null);
|
||||||
if (pump != null)
|
startKeepAliveService();
|
||||||
pump.refreshDataFromPump("Initialization");
|
|
||||||
}
|
}
|
||||||
});
|
}).start();
|
||||||
t.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,6 +183,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));
|
||||||
|
@ -206,12 +206,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));
|
|
||||||
startService(new Intent(this, DanaRSService.class));
|
|
||||||
}
|
|
||||||
keepAliveReceiver.setAlarm(this);
|
keepAliveReceiver.setAlarm(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,18 +15,23 @@ 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.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.SourceDexcomG5.SourceDexcomG5Plugin;
|
||||||
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;
|
||||||
|
@ -40,6 +45,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);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +71,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());
|
||||||
}
|
}
|
||||||
|
@ -72,19 +80,14 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
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))) {
|
} else if (pref.getKey().equals(MainApp.sResources.getString(R.string.key_danars_name))) {
|
||||||
pref.setSummary(SP.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) {
|
||||||
|
@ -99,90 +102,98 @@ 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 && !Config.G5UPLOADER) {
|
||||||
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 && !Config.G5UPLOADER) {
|
||||||
addPreferencesFromResource(R.xml.pref_quickwizard);
|
addPreferencesFromResource(R.xml.pref_quickwizard);
|
||||||
}
|
}
|
||||||
addPreferencesFromResource(R.xml.pref_careportal);
|
addPreferencesFromResourceIfEnabled(SourceDexcomG5Plugin.getPlugin(), PluginBase.BGSOURCE);
|
||||||
if (Config.ALLPREFERENCES) {
|
addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
addPreferencesFromResource(R.xml.pref_treatments);
|
addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginBase.CONSTRAINTS);
|
||||||
|
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 && !Config.G5UPLOADER) {
|
||||||
}
|
|
||||||
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);
|
||||||
DanaRSPlugin danaRSPlugin = MainApp.getSpecificPlugin(DanaRSPlugin.class);
|
addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginBase.PUMP);
|
||||||
if (danaRPlugin.isEnabled(PluginBase.PUMP)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_danar);
|
if (DanaRPlugin.getPlugin().isEnabled(PluginBase.PROFILE)
|
||||||
}
|
|| DanaRKoreanPlugin.getPlugin().isEnabled(PluginBase.PROFILE)
|
||||||
if (danaRKoreanPlugin.isEnabled(PluginBase.PUMP)) {
|
|| DanaRv2Plugin.getPlugin().isEnabled(PluginBase.PROFILE)
|
||||||
addPreferencesFromResource(R.xml.pref_danarkorean);
|
|| DanaRSPlugin.getPlugin().isEnabled(PluginBase.PROFILE)) {
|
||||||
}
|
|
||||||
if (danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PUMP)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_danarv2);
|
|
||||||
}
|
|
||||||
if (danaRSPlugin != null && danaRSPlugin.isEnabled(PluginBase.PUMP)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_danars);
|
|
||||||
}
|
|
||||||
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)) {
|
if (!Config.NSCLIENT && !Config.G5UPLOADER) {
|
||||||
addPreferencesFromResource(R.xml.pref_virtualpump);
|
addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginBase.PUMP);
|
||||||
}
|
|
||||||
InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin = MainApp.getSpecificPlugin(InsulinOrefFreePeakPlugin.class);
|
|
||||||
if (insulinOrefFreePeakPlugin.isEnabled(PluginBase.INSULIN)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_insulinoreffreepeak);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NSClientInternalPlugin nsClientInternalPlugin = MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
|
addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginBase.INSULIN);
|
||||||
if (nsClientInternalPlugin != null && nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_nsclientinternal);
|
addPreferencesFromResourceIfEnabled(NSClientInternalPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
}
|
addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
if (Config.SMSCOMMUNICATORENABLED)
|
|
||||||
addPreferencesFromResource(R.xml.pref_smscommunicator);
|
if (!Config.NSCLIENT && !Config.G5UPLOADER) {
|
||||||
if (Config.ALLPREFERENCES) {
|
|
||||||
addPreferencesFromResource(R.xml.pref_others);
|
addPreferencesFromResource(R.xml.pref_others);
|
||||||
}
|
}
|
||||||
addPreferencesFromResource(R.xml.pref_advanced);
|
addPreferencesFromResource(R.xml.pref_advanced);
|
||||||
|
|
||||||
WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class);
|
addPreferencesFromResourceIfEnabled(WearPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
if (wearPlugin != null && wearPlugin.isEnabled(PluginBase.GENERAL)) {
|
addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,14 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||||
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.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
|
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
|
||||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
||||||
|
import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin;
|
||||||
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;
|
||||||
|
@ -38,6 +39,7 @@ import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||||
import info.nightscout.androidaps.receivers.DataReceiver;
|
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
||||||
import info.nightscout.utils.BundleLogger;
|
import info.nightscout.utils.BundleLogger;
|
||||||
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +50,7 @@ public class DataService extends IntentService {
|
||||||
boolean nsClientEnabled = true;
|
boolean nsClientEnabled = true;
|
||||||
boolean mm640gEnabled = false;
|
boolean mm640gEnabled = false;
|
||||||
boolean glimpEnabled = false;
|
boolean glimpEnabled = false;
|
||||||
|
boolean dexcomG5Enabled = false;
|
||||||
|
|
||||||
public DataService() {
|
public DataService() {
|
||||||
super("DataService");
|
super("DataService");
|
||||||
|
@ -64,21 +67,31 @@ public class DataService extends IntentService {
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
glimpEnabled = false;
|
glimpEnabled = false;
|
||||||
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
|
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = true;
|
nsClientEnabled = true;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
glimpEnabled = false;
|
glimpEnabled = false;
|
||||||
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
|
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = true;
|
mm640gEnabled = true;
|
||||||
glimpEnabled = false;
|
glimpEnabled = false;
|
||||||
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) {
|
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
glimpEnabled = true;
|
glimpEnabled = true;
|
||||||
|
dexcomG5Enabled = false;
|
||||||
|
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceDexcomG5Plugin.class)) {
|
||||||
|
xDripEnabled = false;
|
||||||
|
nsClientEnabled = false;
|
||||||
|
mm640gEnabled = false;
|
||||||
|
glimpEnabled = false;
|
||||||
|
dexcomG5Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isNSProfile = ConfigBuilderPlugin.getActiveProfileInterface().getClass().equals(NSProfilePlugin.class);
|
boolean isNSProfile = ConfigBuilderPlugin.getActiveProfileInterface().getClass().equals(NSProfilePlugin.class);
|
||||||
|
@ -99,6 +112,10 @@ public class DataService extends IntentService {
|
||||||
if (glimpEnabled) {
|
if (glimpEnabled) {
|
||||||
handleNewDataFromGlimp(intent);
|
handleNewDataFromGlimp(intent);
|
||||||
}
|
}
|
||||||
|
} else if (Intents.DEXCOMG5_BG.equals(action)) {
|
||||||
|
if (dexcomG5Enabled) {
|
||||||
|
handleNewDataFromDexcomG5(intent);
|
||||||
|
}
|
||||||
} else if (Intents.ACTION_NEW_SGV.equals(action)) {
|
} else if (Intents.ACTION_NEW_SGV.equals(action)) {
|
||||||
// always handle SGV if NS-Client is the source
|
// always handle SGV if NS-Client is the source
|
||||||
if (nsClientEnabled) {
|
if (nsClientEnabled) {
|
||||||
|
@ -116,6 +133,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))
|
||||||
) {
|
) {
|
||||||
|
@ -184,6 +204,40 @@ public class DataService extends IntentService {
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP");
|
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleNewDataFromDexcomG5(Intent intent) {
|
||||||
|
// onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle
|
||||||
|
|
||||||
|
Bundle bundle = intent.getExtras();
|
||||||
|
if (bundle == null) return;
|
||||||
|
|
||||||
|
BgReading bgReading = new BgReading();
|
||||||
|
|
||||||
|
String data = bundle.getString("data");
|
||||||
|
log.debug("Received Dexcom Data", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(data);
|
||||||
|
log.debug("Received Dexcom Data size:" + jsonArray.length());
|
||||||
|
for(int i = 0; i < jsonArray.length(); i++) {
|
||||||
|
JSONObject json = jsonArray.getJSONObject(i);
|
||||||
|
bgReading.value = json.getInt("m_value");
|
||||||
|
bgReading.direction = json.getString("m_trend");
|
||||||
|
bgReading.date = json.getLong("m_time") * 1000L;
|
||||||
|
bgReading.raw = 0;
|
||||||
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
|
||||||
|
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||||
|
NSUpload.uploadBg(bgReading);
|
||||||
|
}
|
||||||
|
if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||||
|
NSUpload.sendToXdrip(bgReading);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleNewDataFromMM640g(Intent intent) {
|
private void handleNewDataFromMM640g(Intent intent) {
|
||||||
Bundle bundle = intent.getExtras();
|
Bundle bundle = intent.getExtras();
|
||||||
if (bundle == null) return;
|
if (bundle == null) return;
|
||||||
|
@ -413,6 +467,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) {
|
||||||
|
|
|
@ -45,4 +45,6 @@ public interface Intents {
|
||||||
String ACTION_REMOTE_CALIBRATION = "com.eveningoutpost.dexdrip.NewCalibration";
|
String ACTION_REMOTE_CALIBRATION = "com.eveningoutpost.dexdrip.NewCalibration";
|
||||||
|
|
||||||
String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED";
|
String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED";
|
||||||
|
|
||||||
|
String DEXCOMG5_BG = "com.dexcom.cgm.DATA";
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,17 +12,15 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
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.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.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 {
|
||||||
|
@ -30,21 +28,21 @@ 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;
|
||||||
private LongSparseArray<Double> targetLow_v = null; // oldest at index 0
|
private LongSparseArray<Double> targetLow_v = null; // oldest at index 0
|
||||||
JSONArray targetHigh;
|
private JSONArray targetHigh;
|
||||||
private LongSparseArray<Double> targetHigh_v = null; // oldest at index 0
|
private LongSparseArray<Double> targetHigh_v = null; // oldest at index 0
|
||||||
|
|
||||||
int percentage = 100;
|
private int percentage = 100;
|
||||||
int timeshift = 0;
|
private int timeshift = 0;
|
||||||
|
|
||||||
public Profile(JSONObject json, String units) {
|
public Profile(JSONObject json, String units) {
|
||||||
this(json, 100, 0);
|
this(json, 100, 0);
|
||||||
|
@ -161,12 +159,16 @@ public class Profile {
|
||||||
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);
|
final JSONObject o = array.getJSONObject(index);
|
||||||
long tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds"));
|
long tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds"));
|
||||||
Double value = o.getDouble("value") * multiplier;
|
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);
|
||||||
|
try {
|
||||||
|
log.error(array.getJSONObject(index).toString());
|
||||||
|
} catch (JSONException e1) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +208,7 @@ public class Profile {
|
||||||
return shiftedTime;
|
return shiftedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getMultiplier(LongSparseArray<Double> array) {
|
private double getMultiplier(LongSparseArray<Double> array) {
|
||||||
double multiplier = 1d;
|
double multiplier = 1d;
|
||||||
|
|
||||||
if (array == isf_v)
|
if (array == isf_v)
|
||||||
|
@ -220,7 +222,7 @@ public class Profile {
|
||||||
return multiplier;
|
return multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getMultiplier(JSONArray array) {
|
private double getMultiplier(JSONArray array) {
|
||||||
double multiplier = 1d;
|
double multiplier = 1d;
|
||||||
|
|
||||||
if (array == isf)
|
if (array == isf)
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,9 @@ public class BgReading implements DataPointWithLabelInterface {
|
||||||
direction.compareTo("NOT COMPUTABLE") == 0 ||
|
direction.compareTo("NOT COMPUTABLE") == 0 ||
|
||||||
direction.compareTo("OUT_OF_RANGE") == 0 ||
|
direction.compareTo("OUT_OF_RANGE") == 0 ||
|
||||||
direction.compareTo("OUT OF RANGE") == 0 ||
|
direction.compareTo("OUT OF RANGE") == 0 ||
|
||||||
direction.compareTo("NONE") == 0) {
|
direction.compareTo("NONE") == 0 ||
|
||||||
|
direction.compareTo("NotComputable") == 0
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -343,7 +343,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
// ------------------- BgReading handling -----------------------
|
// ------------------- BgReading handling -----------------------
|
||||||
|
|
||||||
public void createIfNotExists(BgReading bgReading, String from) {
|
public boolean createIfNotExists(BgReading bgReading, String from) {
|
||||||
try {
|
try {
|
||||||
bgReading.date = roundDateToSec(bgReading.date);
|
bgReading.date = roundDateToSec(bgReading.date);
|
||||||
BgReading old = getDaoBgReadings().queryForId(bgReading.date);
|
BgReading old = getDaoBgReadings().queryForId(bgReading.date);
|
||||||
|
@ -351,18 +351,20 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
getDaoBgReadings().create(bgReading);
|
getDaoBgReadings().create(bgReading);
|
||||||
log.debug("BG: New record from: " + from + " " + bgReading.toString());
|
log.debug("BG: New record from: " + from + " " + bgReading.toString());
|
||||||
scheduleBgChange();
|
scheduleBgChange();
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
if (!old.isEqual(bgReading)) {
|
if (!old.isEqual(bgReading)) {
|
||||||
|
log.debug("BG: Similiar found: " + old.toString());
|
||||||
old.copyFrom(bgReading);
|
old.copyFrom(bgReading);
|
||||||
getDaoBgReadings().update(old);
|
getDaoBgReadings().update(old);
|
||||||
log.debug("BG: Updating record from: " + from + " " + old.toString());
|
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
|
||||||
scheduleBgChange();
|
scheduleBgChange();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scheduleBgChange() {
|
private static void scheduleBgChange() {
|
||||||
|
@ -1351,7 +1353,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
extendedBolus.date = trJson.getLong("mills");
|
extendedBolus.date = trJson.getLong("mills");
|
||||||
extendedBolus.durationInMinutes = trJson.getInt("duration");
|
extendedBolus.durationInMinutes = trJson.has("duration") ? trJson.getInt("duration") : 0;
|
||||||
extendedBolus.insulin = trJson.getDouble("relative");
|
extendedBolus.insulin = trJson.getDouble("relative");
|
||||||
extendedBolus._id = trJson.getString("_id");
|
extendedBolus._id = trJson.getString("_id");
|
||||||
createOrUpdate(extendedBolus);
|
createOrUpdate(extendedBolus);
|
||||||
|
|
|
@ -87,6 +87,8 @@ public class FoodHelper {
|
||||||
log.debug("FOOD: Updating record by _id: " + old.toString());
|
log.debug("FOOD: Updating record by _id: " + old.toString());
|
||||||
scheduleFoodChange();
|
scheduleFoodChange();
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,10 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
||||||
name = DecimalFormatter.to2Decimal(getProfileObject().percentageBasalSum()) + "U ";
|
name = DecimalFormatter.to2Decimal(getProfileObject().percentageBasalSum()) + "U ";
|
||||||
}
|
}
|
||||||
if (isCPP) {
|
if (isCPP) {
|
||||||
name += "(" + percentage + "%," + timeshift + "h)";
|
name += "(" + percentage + "%";
|
||||||
|
if (timeshift != 0)
|
||||||
|
name += "," + timeshift + "h";
|
||||||
|
name += ")";
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 20.09.2017.
|
* Created by mike on 20.09.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventFoodDatabaseChanged {
|
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;
|
||||||
|
|
|
@ -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,7 +4,7 @@ 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 Object next;
|
||||||
|
|
||||||
public EventReloadTreatmentData(Object next) {
|
public EventReloadTreatmentData(Object 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 {
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
package info.nightscout.androidaps.interfaces;
|
package info.nightscout.androidaps.interfaces;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 12.06.2017.
|
* Created by mike on 12.06.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface DanaRInterface {
|
public interface DanaRInterface {
|
||||||
boolean loadHistory(byte type);
|
PumpEnactResult loadHistory(byte type); // for history browser
|
||||||
|
PumpEnactResult loadEvents(); // events history to build treatments from
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
|
@ -16,16 +16,20 @@ public interface PumpInterface {
|
||||||
boolean isInitialized();
|
boolean isInitialized();
|
||||||
boolean isSuspended();
|
boolean isSuspended();
|
||||||
boolean isBusy();
|
boolean isBusy();
|
||||||
|
boolean isConnected();
|
||||||
|
boolean isConnecting();
|
||||||
|
|
||||||
|
void connect(String reason);
|
||||||
|
void disconnect(String reason);
|
||||||
|
void stopConnecting();
|
||||||
|
|
||||||
|
void getPumpStatus();
|
||||||
|
|
||||||
// Upload to pump new basal profile
|
// Upload to pump new basal profile
|
||||||
int SUCCESS = 0;
|
PumpEnactResult setNewBasalProfile(Profile profile);
|
||||||
int FAILED = 1;
|
|
||||||
int NOT_NEEDED = 2;
|
|
||||||
int setNewBasalProfile(Profile profile);
|
|
||||||
boolean isThisProfileSet(Profile profile);
|
boolean isThisProfileSet(Profile profile);
|
||||||
|
|
||||||
Date lastDataTime();
|
Date lastDataTime();
|
||||||
void refreshDataFromPump(String reason);
|
|
||||||
|
|
||||||
double getBaseBasalRate(); // base basal rate, not temp basal
|
double getBaseBasalRate(); // base basal rate, not temp basal
|
||||||
|
|
||||||
|
@ -36,7 +40,7 @@ public interface PumpInterface {
|
||||||
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
|
||||||
//when the cancel request is requested by the user (forced), the pump should always do a real cancel
|
//when the cancel request is requested by the user (forced), the pump should always do a real cancel
|
||||||
PumpEnactResult cancelTempBasal(boolean force);
|
PumpEnactResult cancelTempBasal(boolean enforceNew);
|
||||||
PumpEnactResult cancelExtendedBolus();
|
PumpEnactResult cancelExtendedBolus();
|
||||||
|
|
||||||
// Status to be passed to NS
|
// Status to be passed to NS
|
||||||
|
|
|
@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.Actions;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -34,6 +32,7 @@ import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
|
@ -54,16 +53,8 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
Button tempBasalCancel;
|
Button tempBasalCancel;
|
||||||
Button fill;
|
Button fill;
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
public ActionsFragment() {
|
public ActionsFragment() {
|
||||||
super();
|
super();
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(ActionsFragment.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,14 +126,15 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
fill.setVisibility(View.GONE);
|
fill.setVisibility(View.GONE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
boolean allowProfileSwitch = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getProfileList().size() > 1;
|
boolean allowProfileSwitch = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getProfileList().size() > 1;
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !allowProfileSwitch)
|
if (!pump.getPumpDescription().isSetBasalProfileCapable || !pump.isInitialized() || pump.isSuspended() || !allowProfileSwitch)
|
||||||
profileSwitch.setVisibility(View.GONE);
|
profileSwitch.setVisibility(View.GONE);
|
||||||
else
|
else
|
||||||
profileSwitch.setVisibility(View.VISIBLE);
|
profileSwitch.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
|
if (!pump.getPumpDescription().isExtendedBolusCapable || !pump.isInitialized() || pump.isSuspended() || pump.isFakingTempsByExtendedBoluses()) {
|
||||||
extendedBolus.setVisibility(View.GONE);
|
extendedBolus.setVisibility(View.GONE);
|
||||||
extendedBolusCancel.setVisibility(View.GONE);
|
extendedBolusCancel.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,7 +150,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) {
|
if (!pump.getPumpDescription().isTempBasalCapable || !pump.isInitialized() || pump.isSuspended()) {
|
||||||
tempBasal.setVisibility(View.GONE);
|
tempBasal.setVisibility(View.GONE);
|
||||||
tempBasalCancel.setVisibility(View.GONE);
|
tempBasalCancel.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -166,14 +158,14 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended())
|
if (!pump.getPumpDescription().isRefillingCapable || !pump.isInitialized() || pump.isSuspended())
|
||||||
fill.setVisibility(View.GONE);
|
fill.setVisibility(View.GONE);
|
||||||
else
|
else
|
||||||
fill.setVisibility(View.VISIBLE);
|
fill.setVisibility(View.VISIBLE);
|
||||||
|
@ -190,7 +182,6 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
FragmentManager manager = getFragmentManager();
|
FragmentManager manager = getFragmentManager();
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.actions_profileswitch:
|
case R.id.actions_profileswitch:
|
||||||
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
||||||
|
@ -212,25 +203,15 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
break;
|
break;
|
||||||
case R.id.actions_extendedbolus_cancel:
|
case R.id.actions_extendedbolus_cancel:
|
||||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelExtended(null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
pump.cancelExtendedBolus();
|
|
||||||
Answers.getInstance().logCustom(new CustomEvent("CancelExtended"));
|
Answers.getInstance().logCustom(new CustomEvent("CancelExtended"));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case R.id.actions_canceltempbasal:
|
case R.id.actions_canceltempbasal:
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
pump.cancelTempBasal(true);
|
|
||||||
Answers.getInstance().logCustom(new CustomEvent("CancelTemp"));
|
Answers.getInstance().logCustom(new CustomEvent("CancelTemp"));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case R.id.actions_settempbasal:
|
case R.id.actions_settempbasal:
|
||||||
NewTempBasalDialog newTempDialog = new NewTempBasalDialog();
|
NewTempBasalDialog newTempDialog = new NewTempBasalDialog();
|
||||||
|
|
|
@ -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,9 +2,8 @@ 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.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
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;
|
||||||
|
@ -27,11 +26,10 @@ import info.nightscout.androidaps.Constants;
|
||||||
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.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
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.Dialogs.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -48,13 +46,7 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
|
|
||||||
NumberPicker editInsulin;
|
NumberPicker editInsulin;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
public static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
public FillDialog() {
|
public FillDialog() {
|
||||||
mHandlerThread = new HandlerThread(FillDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +61,7 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||||
|
|
||||||
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
|
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
|
||||||
double bolusstep = MainApp.getConfigBuilder().getPumpDescription().bolusStep;
|
double bolusstep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep;
|
||||||
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
||||||
editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, new DecimalFormat("0.00"), false);
|
editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, new DecimalFormat("0.00"), false);
|
||||||
|
|
||||||
|
@ -158,28 +150,21 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
builder.setPositiveButton(getString(R.string.primefill), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.primefill), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
if (finalInsulinAfterConstraints > 0) {
|
if (finalInsulinAfterConstraints > 0) {
|
||||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||||
detailedBolusInfo.context = context;
|
detailedBolusInfo.context = context;
|
||||||
detailedBolusInfo.source = Source.USER;
|
detailedBolusInfo.source = Source.USER;
|
||||||
detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history)
|
detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history)
|
||||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
try {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
i.putExtra("status", result.comment);
|
||||||
builder.setMessage(result.comment);
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
builder.show();
|
MainApp.instance().startActivity(i);
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
|
||||||
// window has been destroyed
|
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,15 +2,13 @@ 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.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
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;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
|
||||||
|
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
@ -23,10 +21,9 @@ import java.text.DecimalFormat;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
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.PumpEnactResult;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
|
@ -36,13 +33,7 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
||||||
NumberPicker editInsulin;
|
NumberPicker editInsulin;
|
||||||
NumberPicker editDuration;
|
NumberPicker editDuration;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
public static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
public NewExtendedBolusDialog() {
|
public NewExtendedBolusDialog() {
|
||||||
mHandlerThread = new HandlerThread(NewExtendedBolusDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,8 +47,8 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
||||||
editInsulin = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_insulin);
|
editInsulin = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_insulin);
|
||||||
editInsulin.setParams(0d, 0d, maxInsulin, 0.1d, new DecimalFormat("0.00"), false);
|
editInsulin.setParams(0d, 0d, maxInsulin, 0.1d, new DecimalFormat("0.00"), false);
|
||||||
|
|
||||||
double extendedDurationStep = MainApp.getConfigBuilder().getPumpDescription().extendedBolusDurationStep;
|
double extendedDurationStep = ConfigBuilderPlugin.getActivePump().getPumpDescription().extendedBolusDurationStep;
|
||||||
double extendedMaxDuration = MainApp.getConfigBuilder().getPumpDescription().extendedBolusMaxDuration;
|
double extendedMaxDuration = ConfigBuilderPlugin.getActivePump().getPumpDescription().extendedBolusMaxDuration;
|
||||||
editDuration = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_duration);
|
editDuration = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_duration);
|
||||||
editDuration.setParams(extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, new DecimalFormat("0"), false);
|
editDuration.setParams(extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, new DecimalFormat("0"), false);
|
||||||
|
|
||||||
|
@ -99,23 +90,16 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
||||||
builder.setMessage(confirmMessage);
|
builder.setMessage(confirmMessage);
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().extendedBolus(finalInsulin, finalDurationInMinutes, new Callback() {
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = pump.setExtendedBolus(finalInsulin, finalDurationInMinutes);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
try {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
builder.setTitle(context.getString(R.string.treatmentdeliveryerror));
|
i.putExtra("status", result.comment);
|
||||||
builder.setMessage(result.comment);
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
builder.setPositiveButton(context.getString(R.string.ok), null);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
builder.show();
|
MainApp.instance().startActivity(i);
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
|
||||||
// window has been destroyed
|
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package info.nightscout.androidaps.plugins.Actions.dialogs;
|
package info.nightscout.androidaps.plugins.Actions.dialogs;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
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;
|
||||||
|
@ -26,9 +24,10 @@ 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.Profile;
|
||||||
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.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
|
@ -47,13 +46,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
||||||
NumberPicker basalAbsolute;
|
NumberPicker basalAbsolute;
|
||||||
NumberPicker duration;
|
NumberPicker duration;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
public static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
public NewTempBasalDialog() {
|
public NewTempBasalDialog() {
|
||||||
mHandlerThread = new HandlerThread(NewTempBasalDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,7 +63,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
||||||
absoluteRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_absolute_radio);
|
absoluteRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_absolute_radio);
|
||||||
typeSelectorLayout = (LinearLayout) view.findViewById(R.id.overview_newtempbasal_typeselector_layout);
|
typeSelectorLayout = (LinearLayout) view.findViewById(R.id.overview_newtempbasal_typeselector_layout);
|
||||||
|
|
||||||
PumpDescription pumpDescription = MainApp.getConfigBuilder().getPumpDescription();
|
PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription();
|
||||||
|
|
||||||
basalPercent = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_basalpercentinput);
|
basalPercent = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_basalpercentinput);
|
||||||
double maxTempPercent = pumpDescription.maxTempPercent;
|
double maxTempPercent = pumpDescription.maxTempPercent;
|
||||||
|
@ -143,37 +136,29 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
||||||
final Double finalBasal = absolute;
|
final Double finalBasal = absolute;
|
||||||
final int finalDurationInMinutes = durationInMinutes;
|
final int finalDurationInMinutes = durationInMinutes;
|
||||||
|
|
||||||
final Context context = getContext();
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
||||||
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
||||||
builder.setMessage(confirmMessage);
|
builder.setMessage(confirmMessage);
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
Callback callback = new Callback() {
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result;
|
|
||||||
if (setAsPercent) {
|
|
||||||
result = pump.setTempBasalPercent(finalBasalPercent, finalDurationInMinutes);
|
|
||||||
} else {
|
|
||||||
result = pump.setTempBasalAbsolute(finalBasal, finalDurationInMinutes, true);
|
|
||||||
}
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
if (context instanceof Activity) {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
Activity activity = (Activity) context;
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
if (activity.isFinishing()) {
|
i.putExtra("status", result.comment);
|
||||||
return;
|
i.putExtra("title", MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
MainApp.instance().startActivity(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
};
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
if (setAsPercent) {
|
||||||
builder.setMessage(result.comment);
|
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(finalBasalPercent, finalDurationInMinutes, callback);
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
} else {
|
||||||
builder.show();
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(finalBasal, finalDurationInMinutes, true, callback);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
Answers.getInstance().logCustom(new CustomEvent("TempBasal"));
|
Answers.getInstance().logCustom(new CustomEvent("TempBasal"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,7 @@ 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.Config;
|
||||||
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.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
|
@ -26,8 +27,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;
|
||||||
|
@ -37,13 +36,6 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
LinearLayout butonsLayout;
|
LinearLayout butonsLayout;
|
||||||
View noProfileView;
|
View noProfileView;
|
||||||
|
|
||||||
static public CareportalPlugin getPlugin() {
|
|
||||||
if (careportalPlugin == null) {
|
|
||||||
careportalPlugin = new CareportalPlugin();
|
|
||||||
}
|
|
||||||
return careportalPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
// date,bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split,temptarget
|
// date,bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split,temptarget
|
||||||
public static final OptionsToShow BGCHECK = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck).date().bg();
|
public static final OptionsToShow BGCHECK = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck).date().bg();
|
||||||
public static final OptionsToShow SNACKBOLUS = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus).date().bg().insulin().carbs().prebolus();
|
public static final OptionsToShow SNACKBOLUS = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus).date().bg().insulin().carbs().prebolus();
|
||||||
|
@ -113,7 +105,7 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
butonsLayout.setVisibility(View.VISIBLE);
|
butonsLayout.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BuildConfig.NSCLIENTOLNY)
|
if (Config.NSCLIENT || Config.G5UPLOADER)
|
||||||
statsLayout.setVisibility(View.GONE); // visible on overview
|
statsLayout.setVisibility(View.GONE); // visible on overview
|
||||||
|
|
||||||
updateGUI();
|
updateGUI();
|
||||||
|
|
|
@ -10,6 +10,15 @@ public class CareportalPlugin implements PluginBase {
|
||||||
private boolean fragmentEnabled = true;
|
private boolean fragmentEnabled = true;
|
||||||
private 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() {
|
||||||
return PluginBase.GENERAL;
|
return PluginBase.GENERAL;
|
||||||
|
@ -58,7 +67,7 @@ public class CareportalPlugin implements PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean showInList(int type) {
|
public boolean showInList(int type) {
|
||||||
return !Config.NSCLIENT;
|
return !Config.NSCLIENT && !Config.G5UPLOADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,8 @@ package info.nightscout.androidaps.plugins.Careportal.Dialogs;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
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.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -51,9 +50,10 @@ import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||||
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.Overview.Dialogs.ErrorHelperActivity;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
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;
|
||||||
|
@ -105,10 +105,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
|
|
||||||
Date eventTime;
|
Date eventTime;
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
|
|
||||||
public void setOptions(OptionsToShow options, int event) {
|
public void setOptions(OptionsToShow options, int event) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.event = MainApp.sResources.getString(event);
|
this.event = MainApp.sResources.getString(event);
|
||||||
|
@ -116,11 +112,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
|
|
||||||
public NewNSTreatmentDialog() {
|
public NewNSTreatmentDialog() {
|
||||||
super();
|
super();
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(NewNSTreatmentDialog.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -138,6 +129,7 @@ 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);
|
||||||
|
@ -202,27 +194,30 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
double defaultDuration = 0;
|
double defaultDuration = 0;
|
||||||
double defaultTarget = 0;
|
double defaultTarget = 0;
|
||||||
if(profile!=null){
|
if (profile != null) {
|
||||||
defaultTarget = bg.doubleValue();
|
defaultTarget = bg.doubleValue();
|
||||||
}
|
}
|
||||||
boolean erase = false;
|
boolean erase = false;
|
||||||
|
|
||||||
if(MainApp.sResources.getString(R.string.eatingsoon).equals(reasonList.get(position))){
|
if (MainApp.sResources.getString(R.string.eatingsoon).equals(reasonList.get(position))) {
|
||||||
defaultDuration = SP.getDouble(R.string.key_eatingsoon_duration, 0d);
|
defaultDuration = SP.getDouble(R.string.key_eatingsoon_duration, 0d);
|
||||||
defaultTarget = SP.getDouble(R.string.key_eatingsoon_target, 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);;
|
} else if (MainApp.sResources.getString(R.string.activity).equals(reasonList.get(position))) {
|
||||||
defaultTarget = SP.getDouble(R.string.key_activity_target, 0d);;
|
defaultDuration = SP.getDouble(R.string.key_activity_duration, 0d);
|
||||||
|
;
|
||||||
|
defaultTarget = SP.getDouble(R.string.key_activity_target, 0d);
|
||||||
|
;
|
||||||
} else {
|
} else {
|
||||||
defaultDuration = 0;
|
defaultDuration = 0;
|
||||||
erase = true;
|
erase = true;
|
||||||
}
|
}
|
||||||
if(defaultTarget != 0 || erase){
|
if (defaultTarget != 0 || erase) {
|
||||||
editTemptarget.setValue(defaultTarget);
|
editTemptarget.setValue(defaultTarget);
|
||||||
}
|
}
|
||||||
if(defaultDuration != 0){
|
if (defaultDuration != 0) {
|
||||||
editDuration.setValue(defaultDuration);
|
editDuration.setValue(defaultDuration);
|
||||||
} else if (erase){
|
} else if (erase) {
|
||||||
editDuration.setValue(0d);
|
editDuration.setValue(0d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,15 +331,15 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
editTimeshift.setParams(0d, (double) Constants.CPP_MIN_TIMESHIFT, (double) Constants.CPP_MAX_TIMESHIFT, 1d, new DecimalFormat("0"), false);
|
editTimeshift.setParams(0d, (double) Constants.CPP_MIN_TIMESHIFT, (double) Constants.CPP_MAX_TIMESHIFT, 1d, new DecimalFormat("0"), false);
|
||||||
|
|
||||||
ProfileSwitch ps = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
ProfileSwitch ps = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
if(ps!=null && ps.isCPP){
|
if (ps != null && ps.isCPP) {
|
||||||
final int percentage = ps.percentage;
|
final int percentage = ps.percentage;
|
||||||
final int timeshift = ps.timeshift;
|
final int timeshift = ps.timeshift;
|
||||||
reuseButton.setText(reuseButton.getText() + " " + percentage + "% " + timeshift +"h");
|
reuseButton.setText(reuseButton.getText() + " " + percentage + "% " + timeshift + "h");
|
||||||
reuseButton.setOnClickListener(new View.OnClickListener() {
|
reuseButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
editPercentage.setValue((double)percentage);
|
editPercentage.setValue((double) percentage);
|
||||||
editTimeshift.setValue((double)timeshift);
|
editTimeshift.setValue((double) timeshift);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -362,7 +357,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_profile_layout), options.profile);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_profile_layout), options.profile);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_percentage_layout), options.profile);
|
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_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_reuse_layout), options.profile && ps != null && ps.isCPP);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
@ -673,10 +668,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
} else if (options.executeTempTarget) {
|
} else if (options.executeTempTarget) {
|
||||||
try {
|
try {
|
||||||
if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration") && data.getInt("duration") == 0)) {
|
if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration") && data.getInt("duration") == 0)) {
|
||||||
sHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
TempTarget tempTarget = new TempTarget();
|
TempTarget tempTarget = new TempTarget();
|
||||||
tempTarget.date = eventTime.getTime();
|
tempTarget.date = eventTime.getTime();
|
||||||
tempTarget.durationInMinutes = data.getInt("duration");
|
tempTarget.durationInMinutes = data.getInt("duration");
|
||||||
|
@ -693,11 +684,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
||||||
NSUpload.uploadCareportalEntryToNS(data);
|
NSUpload.uploadCareportalEntryToNS(data);
|
||||||
Answers.getInstance().logCustom(new CustomEvent("TempTarget"));
|
Answers.getInstance().logCustom(new CustomEvent("TempTarget"));
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
@ -713,9 +699,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) {
|
public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) {
|
||||||
sHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ProfileSwitch profileSwitch = new ProfileSwitch();
|
ProfileSwitch profileSwitch = new ProfileSwitch();
|
||||||
profileSwitch.date = System.currentTimeMillis();
|
profileSwitch.date = System.currentTimeMillis();
|
||||||
profileSwitch.source = Source.USER;
|
profileSwitch.source = Source.USER;
|
||||||
|
@ -728,22 +711,24 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
profileSwitch.percentage = percentage;
|
profileSwitch.percentage = percentage;
|
||||||
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().setProfile(profileSwitch.getProfileObject(), new Callback() {
|
||||||
if (pump != null) {
|
@Override
|
||||||
pump.setNewBasalProfile(profileSwitch.getProfileObject());
|
public void run() {
|
||||||
MainApp.bus().post(new EventNewBasalProfile());
|
if (!result.success) {
|
||||||
} else {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
log.error("No active pump selected");
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
|
i.putExtra("status", result.comment);
|
||||||
|
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
MainApp.instance().startActivity(i);
|
||||||
}
|
}
|
||||||
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
MainApp.bus().post(new EventNewBasalProfile());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) {
|
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());
|
ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
if (profileSwitch != null) {
|
if (profileSwitch != null) {
|
||||||
profileSwitch = new ProfileSwitch();
|
profileSwitch = new ProfileSwitch();
|
||||||
|
@ -758,19 +743,24 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
profileSwitch.percentage = percentage;
|
profileSwitch.percentage = percentage;
|
||||||
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().setProfile(profileSwitch.getProfileObject(), new Callback() {
|
||||||
if (pump != null) {
|
@Override
|
||||||
pump.setNewBasalProfile(profileSwitch.getProfileObject());
|
public void run() {
|
||||||
MainApp.bus().post(new EventNewBasalProfile());
|
if (!result.success) {
|
||||||
} else {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
log.error("No active pump selected");
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
|
i.putExtra("status", result.comment);
|
||||||
|
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
MainApp.instance().startActivity(i);
|
||||||
}
|
}
|
||||||
|
MainApp.bus().post(new EventNewBasalProfile());
|
||||||
|
}
|
||||||
|
});
|
||||||
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||||
} else {
|
} else {
|
||||||
log.error("No profile switch existing");
|
log.error("No profile switch existing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,6 +11,7 @@ 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;
|
||||||
|
@ -22,6 +24,7 @@ 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;
|
||||||
|
@ -194,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;
|
||||||
}
|
}
|
||||||
|
@ -203,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);
|
||||||
|
@ -217,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() {
|
||||||
|
@ -244,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);
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
package info.nightscout.androidaps.plugins.ConfigBuilder;
|
package info.nightscout.androidaps.plugins.ConfigBuilder;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -14,7 +10,6 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
|
@ -32,33 +27,29 @@ import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventBolusRequested;
|
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressHelperActivity;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
|
||||||
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.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
import info.nightscout.androidaps.queue.CommandQueue;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class ConfigBuilderPlugin implements PluginBase, PumpInterface, ConstraintsInterface, TreatmentsInterface {
|
public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, TreatmentsInterface {
|
||||||
private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class);
|
||||||
|
|
||||||
private static BgSourceInterface activeBgSource;
|
private static BgSourceInterface activeBgSource;
|
||||||
|
@ -77,12 +68,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
|
|
||||||
private static ArrayList<PluginBase> pluginList;
|
private static ArrayList<PluginBase> pluginList;
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
private static CommandQueue commandQueue = new CommandQueue();
|
||||||
|
|
||||||
public ConfigBuilderPlugin() {
|
public ConfigBuilderPlugin() {
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "ConfigBuilderPlugin");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -146,6 +135,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();
|
||||||
|
@ -192,6 +186,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
verifySelectionInCategories();
|
verifySelectionInCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CommandQueue getCommandQueue() {
|
||||||
|
return commandQueue;
|
||||||
|
}
|
||||||
|
|
||||||
public static BgSourceInterface getActiveBgSource() {
|
public static BgSourceInterface getActiveBgSource() {
|
||||||
return activeBgSource;
|
return activeBgSource;
|
||||||
}
|
}
|
||||||
|
@ -301,7 +299,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) {
|
||||||
|
@ -353,259 +351,77 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pump interface
|
* Ex Pump interface
|
||||||
*
|
*
|
||||||
* Config builder return itself as a pump and check constraints before it passes command to pump driver
|
* Config builder return itself as a pump and check constraints before it passes command to pump driver
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public boolean isInitialized() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.isInitialized();
|
|
||||||
else return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSuspended() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.isSuspended();
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBusy() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.isBusy();
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setNewBasalProfile(Profile profile) {
|
|
||||||
// Compare with pump limits
|
|
||||||
Profile.BasalValue[] basalValues = profile.getBasalValues();
|
|
||||||
|
|
||||||
for (int index = 0; index < basalValues.length; index++) {
|
|
||||||
if (basalValues[index].value < getPumpDescription().basalMinimumRate) {
|
|
||||||
Notification notification = new Notification(Notification.BASAL_VALUE_BELOW_MINIMUM, MainApp.sResources.getString(R.string.basalvaluebelowminimum), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
return FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.BASAL_VALUE_BELOW_MINIMUM));
|
|
||||||
|
|
||||||
if (isThisProfileSet(profile)) {
|
|
||||||
log.debug("Correct profile already set");
|
|
||||||
return NOT_NEEDED;
|
|
||||||
} else if (activePump != null) {
|
|
||||||
return activePump.setNewBasalProfile(profile);
|
|
||||||
} else
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isThisProfileSet(Profile profile) {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.isThisProfileSet(profile);
|
|
||||||
else return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Date lastDataTime() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.lastDataTime();
|
|
||||||
else return new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (activePump != null)
|
|
||||||
activePump.refreshDataFromPump(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getBaseBasalRate() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.getBaseBasalRate();
|
|
||||||
else
|
|
||||||
return 0d;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
|
||||||
mWakeLock.acquire();
|
|
||||||
PumpEnactResult result;
|
|
||||||
detailedBolusInfo.insulin = applyBolusConstraints(detailedBolusInfo.insulin);
|
|
||||||
detailedBolusInfo.carbs = applyCarbsConstraints((int) detailedBolusInfo.carbs);
|
|
||||||
|
|
||||||
BolusProgressDialog bolusProgressDialog = null;
|
|
||||||
if (detailedBolusInfo.context != null) {
|
|
||||||
bolusProgressDialog = new BolusProgressDialog();
|
|
||||||
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin);
|
|
||||||
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
|
|
||||||
} else {
|
|
||||||
Intent i = new Intent();
|
|
||||||
i.putExtra("insulin", detailedBolusInfo.insulin);
|
|
||||||
i.setClass(MainApp.instance(), BolusProgressHelperActivity.class);
|
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
MainApp.instance().startActivity(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin));
|
|
||||||
|
|
||||||
result = activePump.deliverTreatment(detailedBolusInfo);
|
|
||||||
|
|
||||||
BolusProgressDialog.bolusEnded = true;
|
|
||||||
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
|
|
||||||
|
|
||||||
mWakeLock.release();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stopBolusDelivering() {
|
|
||||||
activePump.stopBolusDelivering();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* apply constraints, set temp based on absolute valus and expecting absolute result
|
|
||||||
*
|
|
||||||
* @param absoluteRate
|
|
||||||
* @param durationInMinutes
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean force) {
|
|
||||||
Double rateAfterConstraints = applyBasalConstraints(absoluteRate);
|
|
||||||
PumpEnactResult result = activePump.setTempBasalAbsolute(rateAfterConstraints, durationInMinutes, force);
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("setTempBasalAbsolute rate: " + rateAfterConstraints + " durationInMinutes: " + durationInMinutes + " success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
|
||||||
return setTempBasalAbsolute(absoluteRate, durationInMinutes, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* apply constraints, set temp based on percent and expecting result in percent
|
|
||||||
*
|
|
||||||
* @param percent 0 ... 100 ...
|
|
||||||
* @param durationInMinutes
|
|
||||||
* @return result
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
|
||||||
Integer percentAfterConstraints = applyBasalConstraints(percent);
|
|
||||||
PumpEnactResult result = activePump.setTempBasalPercent(percentAfterConstraints, durationInMinutes);
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("setTempBasalPercent percent: " + percentAfterConstraints + " durationInMinutes: " + durationInMinutes + " success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
|
||||||
Double rateAfterConstraints = applyBolusConstraints(insulin);
|
|
||||||
PumpEnactResult result = activePump.setExtendedBolus(rateAfterConstraints, durationInMinutes);
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("setExtendedBolus rate: " + rateAfterConstraints + " durationInMinutes: " + durationInMinutes + " success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult cancelTempBasal(boolean force) {
|
|
||||||
PumpEnactResult result = activePump.cancelTempBasal(force);
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("cancelTempBasal success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult cancelExtendedBolus() {
|
|
||||||
PumpEnactResult result = activePump.cancelExtendedBolus();
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("cancelExtendedBolus success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* expect absolute request and allow both absolute and percent response based on pump capabilities
|
* expect absolute request and allow both absolute and percent response based on pump capabilities
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
* @return
|
* @return
|
||||||
|
* true if command is going to be executed
|
||||||
|
* false if error
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public PumpEnactResult applyAPSRequest(APSResult request) {
|
public boolean applyAPSRequest(APSResult request, Callback callback) {
|
||||||
|
PumpInterface pump = getActivePump();
|
||||||
request.rate = applyBasalConstraints(request.rate);
|
request.rate = applyBasalConstraints(request.rate);
|
||||||
PumpEnactResult result;
|
PumpEnactResult result;
|
||||||
|
|
||||||
if (!isInitialized()) {
|
if (!pump.isInitialized()) {
|
||||||
result = new PumpEnactResult();
|
|
||||||
result.comment = MainApp.sResources.getString(R.string.pumpNotInitialized);
|
|
||||||
result.enacted = false;
|
|
||||||
result.success = false;
|
|
||||||
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized));
|
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized));
|
||||||
return result;
|
if (callback != null) {
|
||||||
|
callback.result(new PumpEnactResult().comment(MainApp.sResources.getString(R.string.pumpNotInitialized)).enacted(false).success(false)).run();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSuspended()) {
|
if (pump.isSuspended()) {
|
||||||
result = new PumpEnactResult();
|
|
||||||
result.comment = MainApp.sResources.getString(R.string.pumpsuspended);
|
|
||||||
result.enacted = false;
|
|
||||||
result.success = false;
|
|
||||||
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpsuspended));
|
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpsuspended));
|
||||||
return result;
|
if (callback != null) {
|
||||||
|
callback.result(new PumpEnactResult().comment(MainApp.sResources.getString(R.string.pumpsuspended)).enacted(false).success(false)).run();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) {
|
||||||
if (isTempBasalInProgress()) {
|
if (isTempBasalInProgress()) {
|
||||||
if (Config.logCongigBuilderActions)
|
if (Config.logCongigBuilderActions)
|
||||||
log.debug("applyAPSRequest: cancelTempBasal()");
|
log.debug("applyAPSRequest: cancelTempBasal()");
|
||||||
result = cancelTempBasal(false);
|
getCommandQueue().cancelTempBasal(false, callback);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
result = new PumpEnactResult();
|
|
||||||
result.absolute = request.rate;
|
|
||||||
result.duration = 0;
|
|
||||||
result.enacted = false;
|
|
||||||
result.comment = "Basal set correctly";
|
|
||||||
result.success = true;
|
|
||||||
if (Config.logCongigBuilderActions)
|
if (Config.logCongigBuilderActions)
|
||||||
log.debug("applyAPSRequest: Basal set correctly");
|
log.debug("applyAPSRequest: Basal set correctly");
|
||||||
|
if (callback != null) {
|
||||||
|
callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run();
|
||||||
}
|
}
|
||||||
} else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRateHistory()) < getPumpDescription().basalStep) {
|
return false;
|
||||||
result = new PumpEnactResult();
|
}
|
||||||
result.absolute = getTempBasalAbsoluteRateHistory();
|
} else if (isTempBasalInProgress()
|
||||||
result.duration = getTempBasalFromHistory(System.currentTimeMillis()).getPlannedRemainingMinutes();
|
&& getTempBasalRemainingMinutesFromHistory() > 5
|
||||||
result.enacted = false;
|
&& Math.abs(request.rate - getTempBasalAbsoluteRateHistory()) < pump.getPumpDescription().basalStep) {
|
||||||
result.comment = "Temp basal set correctly";
|
|
||||||
result.success = true;
|
|
||||||
if (Config.logCongigBuilderActions)
|
if (Config.logCongigBuilderActions)
|
||||||
log.debug("applyAPSRequest: Temp basal set correctly");
|
log.debug("applyAPSRequest: Temp basal set correctly");
|
||||||
|
if (callback != null) {
|
||||||
|
callback.result(new PumpEnactResult().absolute(getTempBasalAbsoluteRateHistory()).duration(getTempBasalFromHistory(System.currentTimeMillis()).getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (Config.logCongigBuilderActions)
|
if (Config.logCongigBuilderActions)
|
||||||
log.debug("applyAPSRequest: setTempBasalAbsolute()");
|
log.debug("applyAPSRequest: setTempBasalAbsolute()");
|
||||||
result = setTempBasalAbsolute(request.rate, request.duration);
|
getCommandQueue().tempBasalAbsolute(request.rate, request.duration, false, callback);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public JSONObject getJSONStatus() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.getJSONStatus();
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String deviceID() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.deviceID();
|
|
||||||
else return "No Pump active!";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public PumpDescription getPumpDescription() {
|
public PumpDescription getPumpDescription() {
|
||||||
if (activePump != null)
|
if (activePump != null)
|
||||||
|
@ -620,20 +436,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
return emptyDescription;
|
return emptyDescription;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
@Override
|
|
||||||
public String shortStatus(boolean veryShort) {
|
|
||||||
if (activePump != null) {
|
|
||||||
return activePump.shortStatus(veryShort);
|
|
||||||
} else {
|
|
||||||
return "No Pump active!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isFakingTempsByExtendedBoluses() {
|
|
||||||
return activePump.isFakingTempsByExtendedBoluses();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraints interface
|
* Constraints interface
|
||||||
|
@ -810,7 +613,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTempBasalInProgress() {
|
public boolean isTempBasalInProgress() {
|
||||||
return activeTreatments.isTempBasalInProgress();
|
return activeTreatments != null && activeTreatments.isTempBasalInProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,7 +16,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +62,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
@Override
|
@Override
|
||||||
public String getNameShort() {
|
public String getNameShort() {
|
||||||
String name = MainApp.sResources.getString(R.string.objectives_shortname);
|
String name = MainApp.sResources.getString(R.string.objectives_shortname);
|
||||||
if (!name.trim().isEmpty()){
|
if (!name.trim().isEmpty()) {
|
||||||
//only if translation exists
|
//only if translation exists
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == CONSTRAINTS && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
return type == CONSTRAINTS && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == CONSTRAINTS && fragmentVisible && !BuildConfig.NSCLIENTOLNY;
|
return type == CONSTRAINTS && fragmentVisible && !Config.NSCLIENT && !Config.G5UPLOADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,6 +104,11 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
if (type == CONSTRAINTS) this.fragmentVisible = fragmentVisible;
|
if (type == CONSTRAINTS) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
class Objective {
|
class Objective {
|
||||||
Integer num;
|
Integer num;
|
||||||
String objective;
|
String objective;
|
||||||
|
|
|
@ -10,9 +10,10 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
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.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.HardLimits;
|
import info.nightscout.utils.HardLimits;
|
||||||
import info.nightscout.utils.Round;
|
import info.nightscout.utils.Round;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -86,9 +87,14 @@ 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 ConfigBuilderPlugin.getActivePump().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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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() {
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package info.nightscout.androidaps.plugins.Insulin;
|
package info.nightscout.androidaps.plugins.Insulin;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
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.Iob;
|
import info.nightscout.androidaps.data.Iob;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +60,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
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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());
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.IobCobCalculator;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
|
import android.os.Process;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.LongSparseArray;
|
import android.support.v4.util.LongSparseArray;
|
||||||
|
|
||||||
|
@ -126,10 +127,15 @@ 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) {
|
||||||
sHandlerThread = new HandlerThread(IobCobCalculatorPlugin.class.getSimpleName());
|
sHandlerThread = new HandlerThread(IobCobCalculatorPlugin.class.getSimpleName(), Process.THREAD_PRIORITY_LOWEST);
|
||||||
sHandlerThread.start();
|
sHandlerThread.start();
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
sHandler = new Handler(sHandlerThread.getLooper());
|
||||||
}
|
}
|
||||||
|
@ -227,7 +233,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
private BgReading findOlder(long time) {
|
private BgReading findOlder(long time) {
|
||||||
BgReading lastFound = bgReadings.get(bgReadings.size() - 1);
|
BgReading lastFound = bgReadings.get(bgReadings.size() - 1);
|
||||||
if (lastFound.date > time) return null;
|
if (lastFound.date > time) return null;
|
||||||
for (int i = bgReadings.size() - 2; i >=0 ; --i) {
|
for (int i = bgReadings.size() - 2; i >= 0; --i) {
|
||||||
if (bgReadings.get(i).date < time) continue;
|
if (bgReadings.get(i).date < time) continue;
|
||||||
lastFound = bgReadings.get(i);
|
lastFound = bgReadings.get(i);
|
||||||
if (bgReadings.get(i).date > time) break;
|
if (bgReadings.get(i).date > time) break;
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
|
||||||
|
@ -25,15 +26,16 @@ public class APSResult {
|
||||||
public double rate;
|
public double rate;
|
||||||
public int duration;
|
public int duration;
|
||||||
public boolean changeRequested = false;
|
public boolean changeRequested = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final ConfigBuilderPlugin configBuilder = MainApp.getConfigBuilder();
|
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
if (changeRequested) {
|
if (changeRequested) {
|
||||||
if (rate == 0 && duration == 0)
|
if (rate == 0 && duration == 0)
|
||||||
return MainApp.sResources.getString(R.string.canceltemp);
|
return MainApp.sResources.getString(R.string.canceltemp);
|
||||||
else
|
else
|
||||||
return MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
return MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
||||||
"(" + DecimalFormatter.to2Decimal(rate/configBuilder.getBaseBasalRate() *100) + "%)\n" +
|
"(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100) + "%)\n" +
|
||||||
MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to0Decimal(duration) + " min\n" +
|
MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to0Decimal(duration) + " min\n" +
|
||||||
MainApp.sResources.getString(R.string.reason) + ": " + reason;
|
MainApp.sResources.getString(R.string.reason) + ": " + reason;
|
||||||
} else
|
} else
|
||||||
|
@ -41,13 +43,13 @@ public class APSResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Spanned toSpanned() {
|
public Spanned toSpanned() {
|
||||||
final ConfigBuilderPlugin configBuilder = MainApp.getConfigBuilder();
|
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
if (changeRequested) {
|
if (changeRequested) {
|
||||||
String ret = "";
|
String ret = "";
|
||||||
if (rate == 0 && duration == 0) ret = MainApp.sResources.getString(R.string.canceltemp);
|
if (rate == 0 && duration == 0) ret = MainApp.sResources.getString(R.string.canceltemp);
|
||||||
else
|
else
|
||||||
ret = "<b>" + MainApp.sResources.getString(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
ret = "<b>" + MainApp.sResources.getString(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
||||||
"(" + DecimalFormatter.to2Decimal(rate/configBuilder.getBaseBasalRate() *100) + "%) <br>" +
|
"(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100) + "%) <br>" +
|
||||||
"<b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>" +
|
"<b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>" +
|
||||||
"<b>" + MainApp.sResources.getString(R.string.reason) + "</b>: " + reason.replace("<", "<").replace(">", ">");
|
"<b>" + MainApp.sResources.getString(R.string.reason) + "</b>: " + reason.replace("<", "<").replace(">", ">");
|
||||||
return Html.fromHtml(ret);
|
return Html.fromHtml(ret);
|
||||||
|
|
|
@ -6,15 +6,12 @@ import android.app.PendingIntent;
|
||||||
import android.app.TaskStackBuilder;
|
import android.app.TaskStackBuilder;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v7.app.NotificationCompat;
|
import android.support.v7.app.NotificationCompat;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -31,14 +28,14 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
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.Loop.events.EventLoopSetLastRunGui;
|
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
|
||||||
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.SafeParse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
|
@ -55,14 +52,12 @@ public class LoopPlugin implements PluginBase {
|
||||||
return loopPlugin;
|
return loopPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
private boolean fragmentEnabled = false;
|
private boolean fragmentEnabled = false;
|
||||||
private boolean fragmentVisible = false;
|
private boolean fragmentVisible = false;
|
||||||
|
|
||||||
private long loopSuspendedTill = 0L; // end of manual loop suspend
|
private long loopSuspendedTill = 0L; // end of manual loop suspend
|
||||||
private boolean isSuperBolus = false;
|
private boolean isSuperBolus = false;
|
||||||
|
private boolean isDisconnected = false;
|
||||||
|
|
||||||
public class LastRun {
|
public class LastRun {
|
||||||
public APSResult request = null;
|
public APSResult request = null;
|
||||||
|
@ -77,14 +72,10 @@ public class LoopPlugin implements PluginBase {
|
||||||
static public LastRun lastRun = null;
|
static public LastRun lastRun = null;
|
||||||
|
|
||||||
public LoopPlugin() {
|
public LoopPlugin() {
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(LoopPlugin.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
loopSuspendedTill = SP.getLong("loopSuspendedTill", 0L);
|
loopSuspendedTill = SP.getLong("loopSuspendedTill", 0L);
|
||||||
isSuperBolus = SP.getBoolean("isSuperBolus", false);
|
isSuperBolus = SP.getBoolean("isSuperBolus", false);
|
||||||
|
isDisconnected = SP.getBoolean("isDisconnected", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,7 +96,7 @@ public class LoopPlugin implements PluginBase {
|
||||||
@Override
|
@Override
|
||||||
public String getNameShort() {
|
public String getNameShort() {
|
||||||
String name = MainApp.sResources.getString(R.string.loop_shortname);
|
String name = MainApp.sResources.getString(R.string.loop_shortname);
|
||||||
if (!name.trim().isEmpty()){
|
if (!name.trim().isEmpty()) {
|
||||||
//only if translation exists
|
//only if translation exists
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -115,12 +106,14 @@ public class LoopPlugin implements PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == LOOP && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == LOOP && fragmentEnabled && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == LOOP && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == LOOP && fragmentVisible && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,6 +141,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);
|
||||||
|
@ -165,13 +163,28 @@ public class LoopPlugin implements PluginBase {
|
||||||
public void suspendTo(long endTime) {
|
public void suspendTo(long endTime) {
|
||||||
loopSuspendedTill = endTime;
|
loopSuspendedTill = endTime;
|
||||||
isSuperBolus = false;
|
isSuperBolus = false;
|
||||||
|
isDisconnected = false;
|
||||||
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
||||||
|
SP.putBoolean("isSuperBolus", isSuperBolus);
|
||||||
|
SP.putBoolean("isDisconnected", isDisconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void superBolusTo(long endTime) {
|
public void superBolusTo(long endTime) {
|
||||||
loopSuspendedTill = endTime;
|
loopSuspendedTill = endTime;
|
||||||
isSuperBolus = true;
|
isSuperBolus = true;
|
||||||
|
isDisconnected = false;
|
||||||
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
||||||
|
SP.putBoolean("isSuperBolus", isSuperBolus);
|
||||||
|
SP.putBoolean("isDisconnected", isDisconnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnectTo(long endTime) {
|
||||||
|
loopSuspendedTill = endTime;
|
||||||
|
isSuperBolus = false;
|
||||||
|
isDisconnected = true;
|
||||||
|
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
||||||
|
SP.putBoolean("isSuperBolus", isSuperBolus);
|
||||||
|
SP.putBoolean("isDisconnected", isDisconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int minutesToEndOfSuspend() {
|
public int minutesToEndOfSuspend() {
|
||||||
|
@ -217,6 +230,19 @@ public class LoopPlugin implements PluginBase {
|
||||||
return isSuperBolus;
|
return isSuperBolus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDisconnected() {
|
||||||
|
if (loopSuspendedTill == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (loopSuspendedTill <= now) { // time exceeded
|
||||||
|
suspendTo(0L);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return isDisconnected;
|
||||||
|
}
|
||||||
|
|
||||||
public void invoke(String initiator, boolean allowNotification) {
|
public void invoke(String initiator, boolean allowNotification) {
|
||||||
try {
|
try {
|
||||||
if (Config.logFunctionCalls)
|
if (Config.logFunctionCalls)
|
||||||
|
@ -227,10 +253,10 @@ public class LoopPlugin implements PluginBase {
|
||||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.loopdisabled)));
|
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.loopdisabled)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ConfigBuilderPlugin configBuilder = MainApp.getConfigBuilder();
|
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
APSResult result = null;
|
APSResult result = null;
|
||||||
|
|
||||||
if (configBuilder == null || !isEnabled(PluginBase.LOOP))
|
if (!isEnabled(PluginBase.LOOP))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isSuspended()) {
|
if (isSuspended()) {
|
||||||
|
@ -239,22 +265,22 @@ public class LoopPlugin implements PluginBase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configBuilder.isSuspended()) {
|
if (pump.isSuspended()) {
|
||||||
log.debug(MainApp.sResources.getString(R.string.pumpsuspended));
|
log.debug(MainApp.sResources.getString(R.string.pumpsuspended));
|
||||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.pumpsuspended)));
|
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.pumpsuspended)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configBuilder.getProfile() == null) {
|
if (MainApp.getConfigBuilder().getProfile() == null) {
|
||||||
log.debug(MainApp.sResources.getString(R.string.noprofileselected));
|
log.debug(MainApp.sResources.getString(R.string.noprofileselected));
|
||||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.noprofileselected)));
|
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.noprofileselected)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if pump info is loaded
|
// Check if pump info is loaded
|
||||||
if (configBuilder.getBaseBasalRate() < 0.01d) return;
|
if (pump.getBaseBasalRate() < 0.01d) return;
|
||||||
|
|
||||||
APSInterface usedAPS = configBuilder.getActiveAPS();
|
APSInterface usedAPS = MainApp.getConfigBuilder().getActiveAPS();
|
||||||
if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) {
|
if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) {
|
||||||
usedAPS.invoke(initiator);
|
usedAPS.invoke(initiator);
|
||||||
result = usedAPS.getLastAPSResult();
|
result = usedAPS.getLastAPSResult();
|
||||||
|
@ -284,13 +310,12 @@ public class LoopPlugin implements PluginBase {
|
||||||
waiting.queued = true;
|
waiting.queued = true;
|
||||||
lastRun.setByPump = waiting;
|
lastRun.setByPump = waiting;
|
||||||
MainApp.bus().post(new EventLoopUpdateGui());
|
MainApp.bus().post(new EventLoopUpdateGui());
|
||||||
sHandler.post(new Runnable() {
|
MainApp.getConfigBuilder().applyAPSRequest(resultAfterConstraints, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final PumpEnactResult applyResult = configBuilder.applyAPSRequest(resultAfterConstraints);
|
|
||||||
Answers.getInstance().logCustom(new CustomEvent("APSRequest"));
|
Answers.getInstance().logCustom(new CustomEvent("APSRequest"));
|
||||||
if (applyResult.enacted || applyResult.success) {
|
if (result.enacted || result.success) {
|
||||||
lastRun.setByPump = applyResult;
|
lastRun.setByPump = result;
|
||||||
lastRun.lastEnact = lastRun.lastAPSRun;
|
lastRun.lastEnact = lastRun.lastAPSRun;
|
||||||
} else {
|
} else {
|
||||||
lastRun.setByPump = previousResult;
|
lastRun.setByPump = previousResult;
|
||||||
|
|
|
@ -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 {
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class NSClientInternalPlugin implements PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean showInList(int type) {
|
public boolean showInList(int type) {
|
||||||
return !Config.NSCLIENT;
|
return !Config.NSCLIENT && !Config.G5UPLOADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -135,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;
|
||||||
|
|
|
@ -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) {
|
||||||
|
@ -308,6 +308,15 @@ public class NSDeviceStatus {
|
||||||
return Html.fromHtml(string.toString());
|
return Html.fromHtml(string.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getOpenApsTimestamp() {
|
||||||
|
|
||||||
|
if (deviceStatusOpenAPSData.clockSuggested != 0) {
|
||||||
|
return deviceStatusOpenAPSData.clockSuggested;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Spanned getExtendedOpenApsStatus() {
|
public Spanned getExtendedOpenApsStatus() {
|
||||||
StringBuilder string = new StringBuilder();
|
StringBuilder string = new StringBuilder();
|
||||||
|
|
||||||
|
@ -336,7 +345,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 {
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.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.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -632,6 +632,13 @@ public class NSClientService extends Service {
|
||||||
if (sgv.getMills() > latestDateInReceivedData)
|
if (sgv.getMills() > latestDateInReceivedData)
|
||||||
latestDateInReceivedData = sgv.getMills();
|
latestDateInReceivedData = sgv.getMills();
|
||||||
}
|
}
|
||||||
|
// Was that sgv more less 15 mins ago ?
|
||||||
|
boolean lessThan15MinAgo = false;
|
||||||
|
if((System.currentTimeMillis()-latestDateInReceivedData)/(60 * 1000L) < 15L )
|
||||||
|
lessThan15MinAgo = true;
|
||||||
|
if(Notification.isAlarmForStaleData() && lessThan15MinAgo){
|
||||||
|
MainApp.bus().post(new EventDismissNotification(Notification.NSALARM));
|
||||||
|
}
|
||||||
BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
|
BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData)));
|
MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData)));
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
|
@ -25,11 +24,10 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
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.plugins.OpenAPSMA.LoggerCallback;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
@ -186,7 +184,7 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
double minBg,
|
double minBg,
|
||||||
double maxBg,
|
double maxBg,
|
||||||
double targetBg,
|
double targetBg,
|
||||||
PumpInterface pump,
|
double basalrate,
|
||||||
IobTotal[] iobArray,
|
IobTotal[] iobArray,
|
||||||
GlucoseStatus glucoseStatus,
|
GlucoseStatus glucoseStatus,
|
||||||
MealData mealData,
|
MealData mealData,
|
||||||
|
@ -210,7 +208,7 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
mProfile.put("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.put("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.put("skip_neutral_temps", true);
|
mProfile.put("skip_neutral_temps", true);
|
||||||
mProfile.put("current_basal", pump.getBaseBasalRate());
|
mProfile.put("current_basal", basalrate);
|
||||||
mProfile.put("temptargetSet", tempTargetSet);
|
mProfile.put("temptargetSet", tempTargetSet);
|
||||||
mProfile.put("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true));
|
mProfile.put("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true));
|
||||||
mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d));
|
mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d));
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
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;
|
||||||
|
|
|
@ -14,15 +14,15 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -75,12 +75,14 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == APS && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == APS && fragmentEnabled && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == APS && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == APS && fragmentVisible && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,6 +105,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;
|
||||||
|
@ -132,7 +139,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
public void invoke(String initiator) {
|
public void invoke(String initiator) {
|
||||||
log.debug("invoke from " + initiator);
|
log.debug("invoke from " + initiator);
|
||||||
lastAPSResult = null;
|
lastAPSResult = null;
|
||||||
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS = null;
|
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS;
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -142,7 +149,6 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
||||||
|
@ -210,7 +216,8 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), 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(ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), "current_basal", 0.01, 5))
|
||||||
|
return;
|
||||||
|
|
||||||
startPart = new Date();
|
startPart = new Date();
|
||||||
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
||||||
|
@ -224,7 +231,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
start = new Date();
|
start = new Date();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData,
|
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), 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
|
||||||
|
@ -243,7 +250,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
||||||
determineBasalResultAMA.changeRequested = false;
|
determineBasalResultAMA.changeRequested = false;
|
||||||
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getBaseBasalRate()) < 0.1)
|
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
|
||||||
determineBasalResultAMA.changeRequested = false;
|
determineBasalResultAMA.changeRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,8 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
public class DetermineBasalAdapterMAJS {
|
public class DetermineBasalAdapterMAJS {
|
||||||
|
@ -155,7 +154,7 @@ public class DetermineBasalAdapterMAJS {
|
||||||
double minBg,
|
double minBg,
|
||||||
double maxBg,
|
double maxBg,
|
||||||
double targetBg,
|
double targetBg,
|
||||||
PumpInterface pump,
|
double basalRate,
|
||||||
IobTotal iobData,
|
IobTotal iobData,
|
||||||
GlucoseStatus glucoseStatus,
|
GlucoseStatus glucoseStatus,
|
||||||
MealData mealData) throws JSONException {
|
MealData mealData) throws JSONException {
|
||||||
|
@ -174,7 +173,7 @@ public class DetermineBasalAdapterMAJS {
|
||||||
mProfile.put("carb_ratio", profile.getIc());
|
mProfile.put("carb_ratio", profile.getIc());
|
||||||
mProfile.put("sens", Profile.toMgdl(profile.getIsf().doubleValue(), units));
|
mProfile.put("sens", Profile.toMgdl(profile.getIsf().doubleValue(), units));
|
||||||
|
|
||||||
mProfile.put("current_basal", pump.getBaseBasalRate());
|
mProfile.put("current_basal", basalRate);
|
||||||
|
|
||||||
if (units.equals(Constants.MMOL)) {
|
if (units.equals(Constants.MMOL)) {
|
||||||
mProfile.put("out_units", "mmol/L");
|
mProfile.put("out_units", "mmol/L");
|
||||||
|
|
|
@ -14,13 +14,13 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -63,7 +63,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
@Override
|
@Override
|
||||||
public String getNameShort() {
|
public String getNameShort() {
|
||||||
String name = MainApp.sResources.getString(R.string.oaps_shortname);
|
String name = MainApp.sResources.getString(R.string.oaps_shortname);
|
||||||
if (!name.trim().isEmpty()){
|
if (!name.trim().isEmpty()) {
|
||||||
//only if translation exists
|
//only if translation exists
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -73,12 +73,14 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == APS && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == APS && fragmentEnabled && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == APS && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == APS && fragmentVisible && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,6 +103,11 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
if (type == APS) this.fragmentVisible = fragmentVisible;
|
if (type == APS) this.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return R.xml.pref_openapsma;
|
||||||
|
}
|
||||||
|
|
||||||
@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;
|
||||||
|
@ -140,7 +147,6 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
||||||
|
@ -208,11 +214,12 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), 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(ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), "current_basal", 0.01, 5))
|
||||||
|
return;
|
||||||
|
|
||||||
start = new Date();
|
start = new Date();
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobTotal, glucoseStatus, mealData);
|
determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobTotal, glucoseStatus, mealData);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +234,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
||||||
determineBasalResultMA.changeRequested = false;
|
determineBasalResultMA.changeRequested = false;
|
||||||
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getBaseBasalRate()) < 0.1)
|
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
|
||||||
determineBasalResultMA.changeRequested = false;
|
determineBasalResultMA.changeRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package info.nightscout.androidaps.plugins.OpenAPSMA.events;
|
package info.nightscout.androidaps.plugins.OpenAPSMA.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.EventUpdateGui;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class EventOpenAPSUpdateGui {
|
public class EventOpenAPSUpdateGui extends EventUpdateGui {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package info.nightscout.androidaps.plugins.OpenAPSMA.events;
|
package info.nightscout.androidaps.plugins.OpenAPSMA.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.EventUpdateGui;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class EventOpenAPSUpdateResultGui {
|
public class EventOpenAPSUpdateResultGui extends EventUpdateGui {
|
||||||
public String text = null;
|
public String text = null;
|
||||||
|
|
||||||
public EventOpenAPSUpdateResultGui(String text) {
|
public EventOpenAPSUpdateResultGui(String text) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
static double amount;
|
static double amount;
|
||||||
public static boolean bolusEnded = false;
|
public static boolean bolusEnded = false;
|
||||||
public static boolean running = true;
|
public static boolean running = true;
|
||||||
|
public static boolean stopPressed = false;
|
||||||
|
|
||||||
public BolusProgressDialog() {
|
public BolusProgressDialog() {
|
||||||
super();
|
super();
|
||||||
|
@ -62,6 +63,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
progressBar.setMax(100);
|
progressBar.setMax(100);
|
||||||
statusView.setText(MainApp.sResources.getString(R.string.waitingforpump));
|
statusView.setText(MainApp.sResources.getString(R.string.waitingforpump));
|
||||||
setCancelable(false);
|
setCancelable(false);
|
||||||
|
stopPressed = false;
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +97,10 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.overview_bolusprogress_stop:
|
case R.id.overview_bolusprogress_stop:
|
||||||
log.debug("Stop bolus delivery button pressed");
|
log.debug("Stop bolus delivery button pressed");
|
||||||
|
stopPressed = true;
|
||||||
stopPressedView.setVisibility(View.VISIBLE);
|
stopPressedView.setVisibility(View.VISIBLE);
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
stopButton.setVisibility(View.INVISIBLE);
|
||||||
pump.stopBolusDelivering();
|
ConfigBuilderPlugin.getActivePump().stopBolusDelivering();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +126,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
|
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
|
||||||
if(BolusProgressDialog.running){
|
if (BolusProgressDialog.running) {
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.Services.AlarmSoundService;
|
||||||
|
|
||||||
|
public class ErrorDialog extends DialogFragment implements View.OnClickListener {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(ErrorDialog.class);
|
||||||
|
Button okButton;
|
||||||
|
TextView statusView;
|
||||||
|
ErrorHelperActivity helperActivity;
|
||||||
|
|
||||||
|
static String status;
|
||||||
|
static String title;
|
||||||
|
static int soundId;
|
||||||
|
|
||||||
|
public ErrorDialog() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSound(int soundId) {
|
||||||
|
this.soundId = soundId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHelperActivity(ErrorHelperActivity activity) {
|
||||||
|
this.helperActivity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
getDialog().setTitle(title);
|
||||||
|
View view = inflater.inflate(R.layout.overview_error_dialog, container, false);
|
||||||
|
okButton = (Button) view.findViewById(R.id.overview_error_ok);
|
||||||
|
statusView = (TextView) view.findViewById(R.id.overview_error_status);
|
||||||
|
okButton.setOnClickListener(this);
|
||||||
|
setCancelable(false);
|
||||||
|
|
||||||
|
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||||
|
alarm.putExtra("soundid", soundId);
|
||||||
|
MainApp.instance().startService(alarm);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (getDialog() != null)
|
||||||
|
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
statusView.setText(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dismiss() {
|
||||||
|
super.dismiss();
|
||||||
|
if (helperActivity != null) {
|
||||||
|
helperActivity.finish();
|
||||||
|
}
|
||||||
|
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||||
|
MainApp.instance().stopService(alarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
switch (view.getId()) {
|
||||||
|
case R.id.overview_error_ok:
|
||||||
|
log.debug("Error dialog ok button pressed");
|
||||||
|
dismiss();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
|
public class ErrorHelperActivity extends AppCompatActivity {
|
||||||
|
public ErrorHelperActivity() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
ErrorDialog errorDialog = new ErrorDialog();
|
||||||
|
errorDialog.setHelperActivity(this);
|
||||||
|
errorDialog.setStatus(getIntent().getStringExtra("status"));
|
||||||
|
errorDialog.setSound(getIntent().getIntExtra("soundid", 0));
|
||||||
|
errorDialog.setTitle(getIntent().getStringExtra("title"));
|
||||||
|
errorDialog.show(this.getSupportFragmentManager(), "Error");
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,9 +2,8 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
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.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -30,12 +29,11 @@ import info.nightscout.androidaps.Constants;
|
||||||
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.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -49,12 +47,11 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
private Integer maxCarbs;
|
private Integer maxCarbs;
|
||||||
private Double maxInsulin;
|
private Double maxInsulin;
|
||||||
|
|
||||||
private Handler mHandler;
|
//one shot guards
|
||||||
|
private boolean accepted;
|
||||||
|
private boolean okClicked;
|
||||||
|
|
||||||
public NewTreatmentDialog() {
|
public NewTreatmentDialog() {
|
||||||
HandlerThread mHandlerThread = new HandlerThread(NewTreatmentDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final private TextWatcher textWatcher = new TextWatcher() {
|
final private TextWatcher textWatcher = new TextWatcher() {
|
||||||
|
@ -103,15 +100,21 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
||||||
|
|
||||||
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
|
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
|
||||||
editInsulin.setParams(0d, 0d, maxInsulin, MainApp.getConfigBuilder().getPumpDescription().bolusStep, new DecimalFormat("0.00"), false, textWatcher);
|
editInsulin.setParams(0d, 0d, maxInsulin, ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep, new DecimalFormat("0.00"), false, textWatcher);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public synchronized void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.ok:
|
case R.id.ok:
|
||||||
|
if (okClicked) {
|
||||||
|
log.debug("guarding: ok already clicked");
|
||||||
|
dismiss();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
okClicked = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Double insulin = SafeParse.stringToDouble(editInsulin.getText());
|
Double insulin = SafeParse.stringToDouble(editInsulin.getText());
|
||||||
|
@ -132,17 +135,19 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
final int finalCarbsAfterConstraints = carbsAfterConstraints;
|
final int finalCarbsAfterConstraints = carbsAfterConstraints;
|
||||||
|
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
|
||||||
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
||||||
builder.setMessage(Html.fromHtml(confirmMessage));
|
builder.setMessage(Html.fromHtml(confirmMessage));
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
synchronized (builder) {
|
||||||
|
if (accepted) {
|
||||||
|
log.debug("guarding: already accepted");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
accepted = true;
|
||||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
if (finalInsulinAfterConstraints == 0)
|
if (finalInsulinAfterConstraints == 0)
|
||||||
detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION;
|
detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION;
|
||||||
|
@ -152,28 +157,29 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||||
detailedBolusInfo.context = context;
|
detailedBolusInfo.context = context;
|
||||||
detailedBolusInfo.source = Source.USER;
|
detailedBolusInfo.source = Source.USER;
|
||||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
try {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
i.putExtra("status", result.comment);
|
||||||
builder.setMessage(result.comment);
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
builder.show();
|
MainApp.instance().startActivity(i);
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
|
||||||
// window has been destroyed
|
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Answers.getInstance().logCustom(new CustomEvent("Bolus"));
|
Answers.getInstance().logCustom(new CustomEvent("Bolus"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(getString(R.string.cancel), null);
|
builder.setNegativeButton(
|
||||||
|
|
||||||
|
getString(R.string.cancel), null);
|
||||||
builder.show();
|
builder.show();
|
||||||
|
|
||||||
dismiss();
|
dismiss();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
|
|
@ -3,9 +3,8 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
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.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -32,7 +31,6 @@ import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.mozilla.javascript.tools.debugger.Main;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -47,7 +45,6 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
@ -59,13 +56,11 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|
||||||
import info.nightscout.utils.BolusWizard;
|
import info.nightscout.utils.BolusWizard;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.OKDialog;
|
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -109,16 +104,14 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
JSONObject boluscalcJSON;
|
JSONObject boluscalcJSON;
|
||||||
boolean cobAvailable = false;
|
boolean cobAvailable = false;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
public static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
|
//one shot guards
|
||||||
|
private boolean accepted;
|
||||||
|
private boolean okClicked;
|
||||||
|
|
||||||
public WizardDialog() {
|
public WizardDialog() {
|
||||||
super();
|
super();
|
||||||
mHandlerThread = new HandlerThread(WizardDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -253,7 +246,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
|
|
||||||
editBg.setParams(0d, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, textWatcher);
|
editBg.setParams(0d, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, textWatcher);
|
||||||
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
|
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
|
||||||
double bolusstep = MainApp.getConfigBuilder().getPumpDescription().bolusStep;
|
double bolusstep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep;
|
||||||
editCorr.setParams(0d, -maxCorrection, maxCorrection, bolusstep, new DecimalFormat("0.00"), false, textWatcher);
|
editCorr.setParams(0d, -maxCorrection, maxCorrection, bolusstep, new DecimalFormat("0.00"), false, textWatcher);
|
||||||
editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false);
|
editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false);
|
||||||
initDialog();
|
initDialog();
|
||||||
|
@ -297,9 +290,15 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public synchronized void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.ok:
|
case R.id.ok:
|
||||||
|
if (okClicked) {
|
||||||
|
log.debug("guarding: ok already clicked");
|
||||||
|
dismiss();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
okClicked = true;
|
||||||
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
|
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
|
||||||
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
|
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
|
||||||
|
|
||||||
|
@ -327,29 +326,38 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
final int carbTime = SafeParse.stringToInt(editCarbTime.getText());
|
final int carbTime = SafeParse.stringToInt(editCarbTime.getText());
|
||||||
final boolean useSuperBolus = superbolusCheckbox.isChecked();
|
final boolean useSuperBolus = superbolusCheckbox.isChecked();
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||||
builder.setMessage(Html.fromHtml(confirmMessage));
|
builder.setMessage(Html.fromHtml(confirmMessage));
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
synchronized (builder) {
|
||||||
|
if (accepted) {
|
||||||
|
log.debug("guarding: already accepted");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
accepted = true;
|
||||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
PumpEnactResult result;
|
|
||||||
if (useSuperBolus) {
|
if (useSuperBolus) {
|
||||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
|
||||||
if (activeloop != null) {
|
if (activeloop != null) {
|
||||||
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
||||||
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
|
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
|
||||||
}
|
}
|
||||||
pump.cancelTempBasal(true);
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 120, true, new Callback() {
|
||||||
result = pump.setTempBasalAbsolute(0d, 120, true);
|
@Override
|
||||||
|
public void run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror), result.comment, null);
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
|
i.putExtra("status", result.comment);
|
||||||
|
i.putExtra("title", MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
MainApp.instance().startActivity(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||||
|
@ -360,25 +368,23 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
detailedBolusInfo.carbTime = carbTime;
|
detailedBolusInfo.carbTime = carbTime;
|
||||||
detailedBolusInfo.boluscalc = boluscalcJSON;
|
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||||
detailedBolusInfo.source = Source.USER;
|
detailedBolusInfo.source = Source.USER;
|
||||||
result = pump.deliverTreatment(detailedBolusInfo);
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
try {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
i.putExtra("status", result.comment);
|
||||||
builder.setMessage(result.comment);
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
builder.show();
|
MainApp.instance().startActivity(i);
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
|
||||||
// window has been destroyed
|
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Answers.getInstance().logCustom(new CustomEvent("Wizard"));
|
Answers.getInstance().logCustom(new CustomEvent("Wizard"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(getString(R.string.cancel), null);
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
||||||
builder.show();
|
builder.show();
|
||||||
|
@ -393,7 +399,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
|
|
||||||
private void initDialog() {
|
private void initDialog() {
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
ProfileStore profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile();
|
ProfileStore profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile();
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile));
|
||||||
|
@ -403,7 +409,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
ArrayList<CharSequence> profileList;
|
ArrayList<CharSequence> profileList;
|
||||||
profileList = profileStore.getProfileList();
|
profileList = profileStore.getProfileList();
|
||||||
profileList.add(0, MainApp.sResources.getString(R.string.active));
|
profileList.add(0, MainApp.sResources.getString(R.string.active));
|
||||||
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(),
|
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(getContext(),
|
||||||
R.layout.spinner_centered, profileList);
|
R.layout.spinner_centered, profileList);
|
||||||
|
|
||||||
profileSpinner.setAdapter(adapter);
|
profileSpinner.setAdapter(adapter);
|
||||||
|
@ -444,7 +450,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateInsulin() {
|
private void calculateInsulin() {
|
||||||
ProfileStore profile = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile();
|
ProfileStore profile = ConfigBuilderPlugin.getActiveProfileInterface().getProfile();
|
||||||
if (profileSpinner == null || profileSpinner.getSelectedItem() == null)
|
if (profileSpinner == null || profileSpinner.getSelectedItem() == null)
|
||||||
return; // not initialized yet
|
return; // not initialized yet
|
||||||
String selectedAlternativeProfile = profileSpinner.getSelectedItem().toString();
|
String selectedAlternativeProfile = profileSpinner.getSelectedItem().toString();
|
||||||
|
|
|
@ -5,12 +5,11 @@ import android.app.Activity;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.DashPathEffect;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
@ -26,7 +25,6 @@ import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
@ -37,13 +35,6 @@ 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.jjoe64.graphview.GraphView;
|
import com.jjoe64.graphview.GraphView;
|
||||||
import com.jjoe64.graphview.LabelFormatter;
|
|
||||||
import com.jjoe64.graphview.ValueDependentColor;
|
|
||||||
import com.jjoe64.graphview.Viewport;
|
|
||||||
import com.jjoe64.graphview.series.BarGraphSeries;
|
|
||||||
import com.jjoe64.graphview.series.DataPoint;
|
|
||||||
import com.jjoe64.graphview.series.LineGraphSeries;
|
|
||||||
import com.jjoe64.graphview.series.Series;
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -52,10 +43,8 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
@ -72,16 +61,13 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
|
||||||
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.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
|
@ -100,7 +86,6 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData;
|
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
||||||
|
@ -109,26 +94,23 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
|
||||||
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.EventSetWakeLock;
|
import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries;
|
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint;
|
import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter;
|
|
||||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
|
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.BolusWizard;
|
import info.nightscout.utils.BolusWizard;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.OKDialog;
|
import info.nightscout.utils.OKDialog;
|
||||||
import info.nightscout.utils.Profiler;
|
import info.nightscout.utils.Profiler;
|
||||||
import info.nightscout.utils.Round;
|
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
|
||||||
|
@ -186,24 +168,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
public static boolean shorttextmode = false;
|
public static boolean shorttextmode = false;
|
||||||
|
|
||||||
|
private boolean accepted;
|
||||||
|
|
||||||
private int rangeToDisplay = 6; // for graph
|
private int rangeToDisplay = 6; // for graph
|
||||||
|
|
||||||
Handler sLoopHandler = new Handler();
|
Handler sLoopHandler = new Handler();
|
||||||
Runnable sRefreshLoop = null;
|
Runnable sRefreshLoop = null;
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
||||||
private static ScheduledFuture<?> scheduledUpdate = null;
|
private static ScheduledFuture<?> scheduledUpdate = null;
|
||||||
|
|
||||||
public OverviewFragment() {
|
public OverviewFragment() {
|
||||||
super();
|
super();
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(OverviewFragment.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -216,15 +192,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||||
int screen_width = dm.widthPixels;
|
int screen_width = dm.widthPixels;
|
||||||
int screen_height = dm.heightPixels;
|
int screen_height = dm.heightPixels;
|
||||||
smallWidth = screen_width < Constants.SMALL_WIDTH;
|
smallWidth = screen_width <= Constants.SMALL_WIDTH;
|
||||||
smallHeight = screen_height < Constants.SMALL_HEIGHT;
|
smallHeight = screen_height <= Constants.SMALL_HEIGHT;
|
||||||
boolean landscape = screen_height < screen_width;
|
boolean landscape = screen_height < screen_width;
|
||||||
|
|
||||||
View view;
|
View view;
|
||||||
|
|
||||||
if (MainApp.sResources.getBoolean(R.bool.isTablet) && BuildConfig.NSCLIENTOLNY) {
|
if (MainApp.sResources.getBoolean(R.bool.isTablet) && (Config.NSCLIENT || Config.G5UPLOADER)) {
|
||||||
view = inflater.inflate(R.layout.overview_fragment_nsclient_tablet, container, false);
|
view = inflater.inflate(R.layout.overview_fragment_nsclient_tablet, container, false);
|
||||||
} else if (BuildConfig.NSCLIENTOLNY) {
|
} else if (Config.NSCLIENT || Config.G5UPLOADER) {
|
||||||
view = inflater.inflate(R.layout.overview_fragment_nsclient, container, false);
|
view = inflater.inflate(R.layout.overview_fragment_nsclient, container, false);
|
||||||
shorttextmode = true;
|
shorttextmode = true;
|
||||||
} else if (smallHeight || landscape) {
|
} else if (smallHeight || landscape) {
|
||||||
|
@ -418,10 +394,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
activeloop.setFragmentVisible(PluginBase.LOOP, false);
|
activeloop.setFragmentVisible(PluginBase.LOOP, false);
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -439,10 +414,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) {
|
||||||
activeloop.suspendTo(0L);
|
activeloop.suspendTo(0L);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -453,10 +427,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 60L * 60 * 1000);
|
activeloop.suspendTo(System.currentTimeMillis() + 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -467,10 +440,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
activeloop.suspendTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -481,10 +453,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
|
activeloop.suspendTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -495,10 +466,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 10 * 60L * 60 * 1000);
|
activeloop.suspendTo(System.currentTimeMillis() + 10 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -507,12 +477,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
NSUpload.uploadOpenAPSOffline(600);
|
NSUpload.uploadOpenAPSOffline(600);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 30L * 60 * 1000);
|
activeloop.disconnectTo(System.currentTimeMillis() + 30L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 30, true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 30, true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -521,12 +490,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
NSUpload.uploadOpenAPSOffline(30);
|
NSUpload.uploadOpenAPSOffline(30);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 1 * 60L * 60 * 1000);
|
activeloop.disconnectTo(System.currentTimeMillis() + 1 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 60, true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 60, true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -535,12 +503,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
NSUpload.uploadOpenAPSOffline(60);
|
NSUpload.uploadOpenAPSOffline(60);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
activeloop.disconnectTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 2 * 60, true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 2 * 60, true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -549,12 +516,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
NSUpload.uploadOpenAPSOffline(120);
|
NSUpload.uploadOpenAPSOffline(120);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
|
activeloop.disconnectTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 3 * 60, true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 3 * 60, true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -600,13 +566,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
treatmentDialogFragment.show(manager, "TreatmentDialog");
|
treatmentDialogFragment.show(manager, "TreatmentDialog");
|
||||||
break;
|
break;
|
||||||
case R.id.overview_pumpstatus:
|
case R.id.overview_pumpstatus:
|
||||||
if (MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInitialized())
|
if (ConfigBuilderPlugin.getActivePump().isSuspended() || !ConfigBuilderPlugin.getActivePump().isInitialized())
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().readStatus("RefreshClicked", null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MainApp.getConfigBuilder().refreshDataFromPump("RefreshClicked");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,14 +583,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
builder.setMessage(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed);
|
builder.setMessage(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed);
|
||||||
builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
sHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
hideTempRecommendation();
|
hideTempRecommendation();
|
||||||
clearNotification();
|
clearNotification();
|
||||||
PumpEnactResult applyResult = MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed);
|
MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed, new Callback() {
|
||||||
if (applyResult.enacted) {
|
@Override
|
||||||
finalLastRun.setByPump = applyResult;
|
public void run() {
|
||||||
|
if (result.enacted) {
|
||||||
|
finalLastRun.setByPump = result;
|
||||||
finalLastRun.lastEnact = new Date();
|
finalLastRun.lastEnact = new Date();
|
||||||
finalLastRun.lastOpenModeAccept = new Date();
|
finalLastRun.lastOpenModeAccept = new Date();
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
|
@ -706,16 +666,19 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
|
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
|
||||||
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
|
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
accepted = false;
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||||
builder.setMessage(confirmMessage);
|
builder.setMessage(confirmMessage);
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
synchronized (builder) {
|
||||||
|
if (accepted) {
|
||||||
|
log.debug("guarding: already accepted");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
accepted = true;
|
||||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
|
||||||
sHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||||
|
@ -723,25 +686,23 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
detailedBolusInfo.context = context;
|
detailedBolusInfo.context = context;
|
||||||
detailedBolusInfo.boluscalc = boluscalcJSON;
|
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||||
detailedBolusInfo.source = Source.USER;
|
detailedBolusInfo.source = Source.USER;
|
||||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
try {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
i.putExtra("status", result.comment);
|
||||||
builder.setMessage(result.comment);
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
builder.show();
|
MainApp.instance().startActivity(i);
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
|
||||||
// window has been destroyed
|
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Answers.getInstance().logCustom(new CustomEvent("QuickWizard"));
|
Answers.getInstance().logCustom(new CustomEvent("QuickWizard"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(getString(R.string.cancel), null);
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
||||||
builder.show();
|
builder.show();
|
||||||
|
@ -927,7 +888,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
BgReading actualBG = DatabaseHelper.actualBg();
|
BgReading actualBG = DatabaseHelper.actualBg();
|
||||||
BgReading lastBG = DatabaseHelper.lastBg();
|
BgReading lastBG = DatabaseHelper.lastBg();
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
String units = profile.getUnits();
|
String units = profile.getUnits();
|
||||||
|
@ -939,8 +900,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Double lowLine = SP.getDouble("low_mark", 0d);
|
double lowLine = SP.getDouble("low_mark", 0d);
|
||||||
Double highLine = SP.getDouble("high_mark", 0d);
|
double highLine = SP.getDouble("high_mark", 0d);
|
||||||
|
|
||||||
//Start with updating the BG as it is unaffected by loop.
|
//Start with updating the BG as it is unaffected by loop.
|
||||||
// **** BG value ****
|
// **** BG value ****
|
||||||
|
@ -969,7 +930,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
// open loop mode
|
// open loop mode
|
||||||
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
||||||
if (Config.APS && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable) {
|
if (Config.APS && pump.getPumpDescription().isTempBasalCapable) {
|
||||||
apsModeView.setVisibility(View.VISIBLE);
|
apsModeView.setVisibility(View.VISIBLE);
|
||||||
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopenabled));
|
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopenabled));
|
||||||
apsModeView.setTextColor(Color.BLACK);
|
apsModeView.setTextColor(Color.BLACK);
|
||||||
|
@ -1007,16 +968,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
tempTargetView.setTextColor(Color.BLACK);
|
tempTargetView.setTextColor(Color.BLACK);
|
||||||
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground));
|
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground));
|
||||||
tempTargetView.setVisibility(View.VISIBLE);
|
tempTargetView.setVisibility(View.VISIBLE);
|
||||||
tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units));
|
tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + " " + DateUtil.untilString(tempTarget.end()));
|
||||||
} else {
|
} else {
|
||||||
tempTargetView.setTextColor(Color.WHITE);
|
tempTargetView.setTextColor(Color.WHITE);
|
||||||
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetDisabledBackground));
|
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetDisabledBackground));
|
||||||
tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units, units));
|
tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units, units));
|
||||||
tempTargetView.setVisibility(View.VISIBLE);
|
tempTargetView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
if (Config.NSCLIENT && tempTarget == null) {
|
|
||||||
tempTargetView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// **** Temp button ****
|
// **** Temp button ****
|
||||||
if (acceptTempLayout != null) {
|
if (acceptTempLayout != null) {
|
||||||
|
@ -1065,7 +1023,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
if (activeTemp != null) {
|
if (activeTemp != null) {
|
||||||
basalText = activeTemp.toStringFull() + " ";
|
basalText = activeTemp.toStringFull() + " ";
|
||||||
}
|
}
|
||||||
if (Config.NSCLIENT)
|
if (Config.NSCLIENT || Config.G5UPLOADER)
|
||||||
basalText += "(" + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + " U/h)";
|
basalText += "(" + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + " U/h)";
|
||||||
else if (pump.getPumpDescription().isTempBasalCapable) {
|
else if (pump.getPumpDescription().isTempBasalCapable) {
|
||||||
basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)";
|
basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)";
|
||||||
|
@ -1082,15 +1040,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
final ExtendedBolus extendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
final ExtendedBolus extendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
String extendedBolusText = "";
|
String extendedBolusText = "";
|
||||||
if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) {
|
|
||||||
extendedBolusText = extendedBolus.toString();
|
|
||||||
}
|
|
||||||
if (extendedBolusView != null) { // must not exists in all layouts
|
if (extendedBolusView != null) { // must not exists in all layouts
|
||||||
if (shorttextmode) {
|
if (shorttextmode) {
|
||||||
if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) {
|
if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) {
|
||||||
extendedBolusText = DecimalFormatter.to2Decimal(extendedBolus.absoluteRate()) + "U/h";
|
extendedBolusText = DecimalFormatter.to2Decimal(extendedBolus.absoluteRate()) + "U/h";
|
||||||
} else {
|
|
||||||
extendedBolusText = "";
|
|
||||||
}
|
}
|
||||||
extendedBolusView.setText(extendedBolusText);
|
extendedBolusView.setText(extendedBolusText);
|
||||||
extendedBolusView.setOnClickListener(new View.OnClickListener() {
|
extendedBolusView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -1101,8 +1054,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) {
|
||||||
|
extendedBolusText = extendedBolus.toString();
|
||||||
|
}
|
||||||
extendedBolusView.setText(extendedBolusText);
|
extendedBolusView.setText(extendedBolusText);
|
||||||
}
|
}
|
||||||
|
if (extendedBolusText.equals(""))
|
||||||
|
extendedBolusView.setVisibility(View.GONE);
|
||||||
|
else
|
||||||
|
extendedBolusView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
activeProfileView.setText(MainApp.getConfigBuilder().getProfileName());
|
activeProfileView.setText(MainApp.getConfigBuilder().getProfileName());
|
||||||
|
@ -1251,7 +1211,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ****** GRAPH *******
|
// ****** GRAPH *******
|
||||||
//log.debug("updateGUI checkpoint 1");
|
|
||||||
|
|
||||||
// allign to hours
|
// allign to hours
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
@ -1280,464 +1239,82 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
endTime = toTime;
|
endTime = toTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
LineGraphSeries<DataPoint> basalsLineSeries = null;
|
|
||||||
LineGraphSeries<DataPoint> absoluteBasalsLineSeries = null;
|
|
||||||
LineGraphSeries<DataPoint> baseBasalsSeries = null;
|
|
||||||
LineGraphSeries<DataPoint> tempBasalsSeries = null;
|
|
||||||
AreaGraphSeries<DoubleDataPoint> areaSeries;
|
|
||||||
LineGraphSeries<DataPoint> seriesNow, seriesNow2;
|
|
||||||
|
|
||||||
// **** TEMP BASALS graph ****
|
|
||||||
Double maxBasalValueFound = 0d;
|
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
|
|
||||||
List<DataPoint> baseBasalArray = new ArrayList<>();
|
|
||||||
List<DataPoint> tempBasalArray = new ArrayList<>();
|
|
||||||
List<DataPoint> basalLineArray = new ArrayList<>();
|
|
||||||
List<DataPoint> absoluteBasalLineArray = new ArrayList<>();
|
|
||||||
double lastLineBasal = 0;
|
|
||||||
double lastAbsoluteLineBasal = 0;
|
|
||||||
double lastBaseBasal = 0;
|
|
||||||
double lastTempBasal = 0;
|
|
||||||
for (long time = fromTime; time < now; time += 60 * 1000L) {
|
|
||||||
BasalData basalData = IobCobCalculatorPlugin.getBasalData(time);
|
|
||||||
double baseBasalValue = basalData.basal;
|
|
||||||
double absoluteLineValue = baseBasalValue;
|
|
||||||
double tempBasalValue = 0;
|
|
||||||
double basal = 0d;
|
|
||||||
if (basalData.isTempBasalRunning) {
|
|
||||||
absoluteLineValue = tempBasalValue = basalData.tempBasalAbsolute;
|
|
||||||
if (tempBasalValue != lastTempBasal) {
|
|
||||||
tempBasalArray.add(new DataPoint(time, lastTempBasal));
|
|
||||||
tempBasalArray.add(new DataPoint(time, basal = tempBasalValue));
|
|
||||||
}
|
|
||||||
if (lastBaseBasal != 0d) {
|
|
||||||
baseBasalArray.add(new DataPoint(time, lastBaseBasal));
|
|
||||||
baseBasalArray.add(new DataPoint(time, 0d));
|
|
||||||
lastBaseBasal = 0d;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (baseBasalValue != lastBaseBasal) {
|
|
||||||
baseBasalArray.add(new DataPoint(time, lastBaseBasal));
|
|
||||||
baseBasalArray.add(new DataPoint(time, basal = baseBasalValue));
|
|
||||||
lastBaseBasal = baseBasalValue;
|
|
||||||
}
|
|
||||||
if (lastTempBasal != 0) {
|
|
||||||
tempBasalArray.add(new DataPoint(time, lastTempBasal));
|
|
||||||
tempBasalArray.add(new DataPoint(time, 0d));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (baseBasalValue != lastLineBasal) {
|
|
||||||
basalLineArray.add(new DataPoint(time, lastLineBasal));
|
|
||||||
basalLineArray.add(new DataPoint(time, baseBasalValue));
|
|
||||||
}
|
|
||||||
if (absoluteLineValue != lastAbsoluteLineBasal) {
|
|
||||||
absoluteBasalLineArray.add(new DataPoint(time, lastAbsoluteLineBasal));
|
|
||||||
absoluteBasalLineArray.add(new DataPoint(time, basal));
|
|
||||||
}
|
|
||||||
|
|
||||||
lastAbsoluteLineBasal = absoluteLineValue;
|
|
||||||
lastLineBasal = baseBasalValue;
|
|
||||||
lastTempBasal = tempBasalValue;
|
|
||||||
maxBasalValueFound = Math.max(maxBasalValueFound, basal);
|
|
||||||
}
|
|
||||||
basalLineArray.add(new DataPoint(now, lastLineBasal));
|
|
||||||
baseBasalArray.add(new DataPoint(now, lastBaseBasal));
|
|
||||||
tempBasalArray.add(new DataPoint(now, lastTempBasal));
|
|
||||||
absoluteBasalLineArray.add(new DataPoint(now, lastAbsoluteLineBasal));
|
|
||||||
|
|
||||||
DataPoint[] baseBasal = new DataPoint[baseBasalArray.size()];
|
|
||||||
baseBasal = baseBasalArray.toArray(baseBasal);
|
|
||||||
baseBasalsSeries = new LineGraphSeries<>(baseBasal);
|
|
||||||
baseBasalsSeries.setDrawBackground(true);
|
|
||||||
baseBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.basebasal));
|
|
||||||
baseBasalsSeries.setThickness(0);
|
|
||||||
|
|
||||||
DataPoint[] tempBasal = new DataPoint[tempBasalArray.size()];
|
|
||||||
tempBasal = tempBasalArray.toArray(tempBasal);
|
|
||||||
tempBasalsSeries = new LineGraphSeries<>(tempBasal);
|
|
||||||
tempBasalsSeries.setDrawBackground(true);
|
|
||||||
tempBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.tempbasal));
|
|
||||||
tempBasalsSeries.setThickness(0);
|
|
||||||
|
|
||||||
DataPoint[] basalLine = new DataPoint[basalLineArray.size()];
|
|
||||||
basalLine = basalLineArray.toArray(basalLine);
|
|
||||||
basalsLineSeries = new LineGraphSeries<>(basalLine);
|
|
||||||
Paint paint = new Paint();
|
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
|
||||||
paint.setStrokeWidth(2);
|
|
||||||
paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0));
|
|
||||||
paint.setColor(MainApp.sResources.getColor(R.color.basal));
|
|
||||||
basalsLineSeries.setCustomPaint(paint);
|
|
||||||
|
|
||||||
DataPoint[] absoluteBasalLine = new DataPoint[absoluteBasalLineArray.size()];
|
|
||||||
absoluteBasalLine = absoluteBasalLineArray.toArray(absoluteBasalLine);
|
|
||||||
absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine);
|
|
||||||
Paint absolutePaint = new Paint();
|
|
||||||
absolutePaint.setStyle(Paint.Style.STROKE);
|
|
||||||
absolutePaint.setStrokeWidth(4);
|
|
||||||
absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal));
|
|
||||||
absoluteBasalsLineSeries.setCustomPaint(absolutePaint);
|
|
||||||
}
|
|
||||||
|
|
||||||
//log.debug("updateGUI checkpoint 2");
|
|
||||||
|
|
||||||
// **** IOB COB DEV graph ****
|
|
||||||
class DeviationDataPoint extends DataPoint {
|
|
||||||
public int color;
|
|
||||||
|
|
||||||
public DeviationDataPoint(double x, double y, int color) {
|
|
||||||
super(x, y);
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FixedLineGraphSeries<DataPoint> iobSeries;
|
|
||||||
FixedLineGraphSeries<DataPoint> cobSeries;
|
|
||||||
BarGraphSeries<DeviationDataPoint> devSeries;
|
|
||||||
LineGraphSeries<DataPoint> ratioSeries;
|
|
||||||
Double maxIobValueFound = 0d;
|
|
||||||
Double maxCobValueFound = 0d;
|
|
||||||
Double maxDevValueFound = 0d;
|
|
||||||
Double maxRatioValueFound = 0d;
|
|
||||||
|
|
||||||
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) {
|
|
||||||
//Date start = new Date();
|
|
||||||
List<DataPoint> iobArray = new ArrayList<>();
|
|
||||||
List<DataPoint> cobArray = new ArrayList<>();
|
|
||||||
List<DeviationDataPoint> devArray = new ArrayList<>();
|
|
||||||
List<DataPoint> ratioArray = new ArrayList<>();
|
|
||||||
double lastIob = 0;
|
|
||||||
int lastCob = 0;
|
|
||||||
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
|
|
||||||
if (showIobView.isChecked()) {
|
|
||||||
double iob = IobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time).iob;
|
|
||||||
if (Math.abs(lastIob - iob) > 0.02) {
|
|
||||||
if (Math.abs(lastIob - iob) > 0.2)
|
|
||||||
iobArray.add(new DataPoint(time, lastIob));
|
|
||||||
iobArray.add(new DataPoint(time, iob));
|
|
||||||
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(iob));
|
|
||||||
lastIob = iob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) {
|
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
|
||||||
if (autosensData != null && showCobView.isChecked()) {
|
|
||||||
int cob = (int) autosensData.cob;
|
|
||||||
if (cob != lastCob) {
|
|
||||||
if (autosensData.carbsFromBolus > 0)
|
|
||||||
cobArray.add(new DataPoint(time, lastCob));
|
|
||||||
cobArray.add(new DataPoint(time, cob));
|
|
||||||
maxCobValueFound = Math.max(maxCobValueFound, cob);
|
|
||||||
lastCob = cob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (autosensData != null && showDeviationsView.isChecked()) {
|
|
||||||
int color = Color.BLACK; // "="
|
|
||||||
if (autosensData.pastSensitivity.equals("C")) color = Color.GRAY;
|
|
||||||
if (autosensData.pastSensitivity.equals("+")) color = Color.GREEN;
|
|
||||||
if (autosensData.pastSensitivity.equals("-")) color = Color.RED;
|
|
||||||
devArray.add(new DeviationDataPoint(time, autosensData.deviation, color));
|
|
||||||
maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation));
|
|
||||||
}
|
|
||||||
if (autosensData != null && showRatiosView.isChecked()) {
|
|
||||||
ratioArray.add(new DataPoint(time, autosensData.autosensRatio));
|
|
||||||
maxRatioValueFound = Math.max(maxRatioValueFound, Math.abs(autosensData.autosensRatio));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Profiler.log(log, "IOB processed", start);
|
|
||||||
DataPoint[] iobData = new DataPoint[iobArray.size()];
|
|
||||||
iobData = iobArray.toArray(iobData);
|
|
||||||
iobSeries = new FixedLineGraphSeries<>(iobData);
|
|
||||||
iobSeries.setDrawBackground(true);
|
|
||||||
iobSeries.setBackgroundColor(0x80FFFFFF & MainApp.sResources.getColor(R.color.iob)); //50%
|
|
||||||
iobSeries.setColor(MainApp.sResources.getColor(R.color.iob));
|
|
||||||
iobSeries.setThickness(3);
|
|
||||||
|
|
||||||
|
|
||||||
Double maxByScale = null;
|
|
||||||
int graphsToShow = 0;
|
|
||||||
if (showIobView.isChecked()) {
|
|
||||||
if (maxByScale == null) maxByScale = maxIobValueFound;
|
|
||||||
graphsToShow++;
|
|
||||||
}
|
|
||||||
if (showCobView.isChecked()) {
|
|
||||||
if (maxByScale == null) maxByScale = maxCobValueFound;
|
|
||||||
graphsToShow++;
|
|
||||||
}
|
|
||||||
if (showDeviationsView.isChecked()) {
|
|
||||||
if (maxByScale == null) maxByScale = maxDevValueFound;
|
|
||||||
graphsToShow++;
|
|
||||||
}
|
|
||||||
if (showRatiosView.isChecked()) {
|
|
||||||
if (maxByScale == null) maxByScale = maxRatioValueFound;
|
|
||||||
graphsToShow++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (graphsToShow > 1) {
|
|
||||||
if (!maxByScale.equals(maxCobValueFound)) {
|
|
||||||
List<DataPoint> cobArrayRescaled = new ArrayList<>();
|
|
||||||
for (int ci = 0; ci < cobArray.size(); ci++) {
|
|
||||||
cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxByScale / maxCobValueFound / 2));
|
|
||||||
}
|
|
||||||
cobArray = cobArrayRescaled;
|
|
||||||
}
|
|
||||||
if (!maxByScale.equals(maxDevValueFound)) {
|
|
||||||
List<DeviationDataPoint> devArrayRescaled = new ArrayList<>();
|
|
||||||
for (int ci = 0; ci < devArray.size(); ci++) {
|
|
||||||
devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxByScale / maxDevValueFound, devArray.get(ci).color));
|
|
||||||
}
|
|
||||||
devArray = devArrayRescaled;
|
|
||||||
}
|
|
||||||
if (!maxByScale.equals(maxRatioValueFound)) {
|
|
||||||
List<DataPoint> ratioArrayRescaled = new ArrayList<>();
|
|
||||||
for (int ci = 0; ci < ratioArray.size(); ci++) {
|
|
||||||
ratioArrayRescaled.add(new DataPoint(ratioArray.get(ci).getX(), (ratioArray.get(ci).getY() - 1) * maxByScale / maxRatioValueFound));
|
|
||||||
}
|
|
||||||
ratioArray = ratioArrayRescaled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// COB
|
|
||||||
DataPoint[] cobData = new DataPoint[cobArray.size()];
|
|
||||||
cobData = cobArray.toArray(cobData);
|
|
||||||
cobSeries = new FixedLineGraphSeries<>(cobData);
|
|
||||||
cobSeries.setDrawBackground(true);
|
|
||||||
cobSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50%
|
|
||||||
cobSeries.setColor(MainApp.sResources.getColor(R.color.cob));
|
|
||||||
cobSeries.setThickness(3);
|
|
||||||
|
|
||||||
// DEVIATIONS
|
|
||||||
DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()];
|
|
||||||
devData = devArray.toArray(devData);
|
|
||||||
devSeries = new BarGraphSeries<>(devData);
|
|
||||||
devSeries.setValueDependentColor(new ValueDependentColor<DeviationDataPoint>() {
|
|
||||||
@Override
|
|
||||||
public int get(DeviationDataPoint data) {
|
|
||||||
return data.color;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// RATIOS
|
|
||||||
DataPoint[] ratioData = new DataPoint[ratioArray.size()];
|
|
||||||
ratioData = ratioArray.toArray(ratioData);
|
|
||||||
ratioSeries = new LineGraphSeries<>(ratioData);
|
|
||||||
ratioSeries.setColor(MainApp.sResources.getColor(R.color.ratio));
|
|
||||||
ratioSeries.setThickness(3);
|
|
||||||
|
|
||||||
|
// 2nd graph
|
||||||
|
// remove old data
|
||||||
iobGraph.getSeries().clear();
|
iobGraph.getSeries().clear();
|
||||||
|
|
||||||
if (showIobView.isChecked() && iobData.length > 0) {
|
GraphData secondGraphData = new GraphData();
|
||||||
addSeriesWithoutInvalidate(iobSeries, iobGraph);
|
|
||||||
}
|
boolean useIobForScale = false;
|
||||||
if (showCobView.isChecked() && cobData.length > 0) {
|
boolean useCobForScale = false;
|
||||||
addSeriesWithoutInvalidate(cobSeries, iobGraph);
|
boolean useDevForScale = false;
|
||||||
}
|
boolean useRatioForScale = false;
|
||||||
if (showDeviationsView.isChecked() && devData.length > 0) {
|
|
||||||
addSeriesWithoutInvalidate(devSeries, iobGraph);
|
if (showIobView.isChecked()) {
|
||||||
}
|
useIobForScale = true;
|
||||||
if (showRatiosView.isChecked() && ratioData.length > 0) {
|
} else if (showCobView.isChecked()) {
|
||||||
addSeriesWithoutInvalidate(ratioSeries, iobGraph);
|
useCobForScale = true;
|
||||||
|
} else if (showDeviationsView.isChecked()) {
|
||||||
|
useDevForScale = true;
|
||||||
|
} else if (showRatiosView.isChecked()) {
|
||||||
|
useRatioForScale = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showIobView.isChecked())
|
||||||
|
secondGraphData.addIob(iobGraph, fromTime, now, useIobForScale, 1d);
|
||||||
|
if (showCobView.isChecked())
|
||||||
|
secondGraphData.addCob(iobGraph, fromTime, now, useCobForScale, useCobForScale ? 1d : 0.5d);
|
||||||
|
if (showDeviationsView.isChecked())
|
||||||
|
secondGraphData.addDeviations(iobGraph, fromTime, now, useDevForScale, 1d);
|
||||||
|
if (showRatiosView.isChecked())
|
||||||
|
secondGraphData.addRatio(iobGraph, fromTime, now, useRatioForScale, 1d);
|
||||||
|
|
||||||
|
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) {
|
||||||
iobGraph.setVisibility(View.VISIBLE);
|
iobGraph.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
iobGraph.setVisibility(View.GONE);
|
iobGraph.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
//log.debug("updateGUI checkpoint 3");
|
|
||||||
|
|
||||||
// remove old data from graph
|
// remove old data from graph
|
||||||
bgGraph.getSecondScale().getSeries().clear();
|
|
||||||
bgGraph.getSeries().clear();
|
bgGraph.getSeries().clear();
|
||||||
//log.debug("updateGUI checkpoint 4");
|
|
||||||
|
|
||||||
// **** Area ****
|
GraphData graphData = new GraphData();
|
||||||
DoubleDataPoint[] areaDataPoints = new DoubleDataPoint[]{
|
|
||||||
new DoubleDataPoint(fromTime, lowLine, highLine),
|
// **** In range Area ****
|
||||||
new DoubleDataPoint(endTime, lowLine, highLine)
|
graphData.addInRangeArea(bgGraph, fromTime, endTime, lowLine, highLine);
|
||||||
};
|
|
||||||
areaSeries = new AreaGraphSeries<>(areaDataPoints);
|
// **** BG ****
|
||||||
addSeriesWithoutInvalidate(areaSeries, bgGraph);
|
if (showPrediction)
|
||||||
areaSeries.setColor(0);
|
graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, (DetermineBasalResultAMA) finalLastRun.constraintsProcessed);
|
||||||
areaSeries.setDrawBackground(true);
|
else
|
||||||
areaSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.inrangebackground));
|
graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, null);
|
||||||
|
|
||||||
// set manual x bounds to have nice steps
|
// set manual x bounds to have nice steps
|
||||||
bgGraph.getViewport().setMaxX(endTime);
|
graphData.formatAxis(bgGraph, fromTime, endTime);
|
||||||
bgGraph.getViewport().setMinX(fromTime);
|
secondGraphData.formatAxis(iobGraph, fromTime, endTime);
|
||||||
bgGraph.getViewport().setXAxisBoundsManual(true);
|
|
||||||
bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
|
|
||||||
bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
|
|
||||||
iobGraph.getViewport().setMaxX(endTime);
|
|
||||||
iobGraph.getViewport().setMinX(fromTime);
|
|
||||||
iobGraph.getViewport().setXAxisBoundsManual(true);
|
|
||||||
iobGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
|
|
||||||
iobGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
|
|
||||||
|
|
||||||
//log.debug("updateGUI checkpoint 5");
|
|
||||||
// **** BG graph ****
|
|
||||||
List<BgReading> bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
|
|
||||||
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
|
|
||||||
|
|
||||||
if (bgReadingsArray.size() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<BgReading> it = bgReadingsArray.iterator();
|
|
||||||
Double maxBgValue = 0d;
|
|
||||||
while (it.hasNext()) {
|
|
||||||
BgReading bg = it.next();
|
|
||||||
if (bg.value > maxBgValue) maxBgValue = bg.value;
|
|
||||||
bgListArray.add(bg);
|
|
||||||
}
|
|
||||||
if (showPrediction) {
|
|
||||||
DetermineBasalResultAMA amaResult = (DetermineBasalResultAMA) finalLastRun.constraintsProcessed;
|
|
||||||
List<BgReading> predArray = amaResult.getPredictions();
|
|
||||||
bgListArray.addAll(predArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units);
|
|
||||||
maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4;
|
|
||||||
if (highLine > maxBgValue) maxBgValue = highLine;
|
|
||||||
Integer numOfVertLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1);
|
|
||||||
|
|
||||||
DataPointWithLabelInterface[] bg = new DataPointWithLabelInterface[bgListArray.size()];
|
|
||||||
bg = bgListArray.toArray(bg);
|
|
||||||
|
|
||||||
if (bg.length > 0) {
|
|
||||||
addSeriesWithoutInvalidate(new PointsWithLabelGraphSeries<>(bg), bgGraph);
|
|
||||||
}
|
|
||||||
|
|
||||||
//log.debug("updateGUI checkpoint 6");
|
|
||||||
// Treatments
|
// Treatments
|
||||||
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
|
graphData.addTreatments(bgGraph, fromTime, endTime);
|
||||||
|
|
||||||
List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory();
|
// add basal data
|
||||||
|
|
||||||
for (int tx = 0; tx < treatments.size(); tx++) {
|
|
||||||
Treatment t = treatments.get(tx);
|
|
||||||
if (t.getX() < fromTime || t.getX() > endTime) continue;
|
|
||||||
t.setY(getNearestBg((long) t.getX(), bgReadingsArray));
|
|
||||||
filteredTreatments.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
//log.debug("updateGUI checkpoint 7");
|
|
||||||
// ProfileSwitch
|
|
||||||
List<ProfileSwitch> profileSwitches = MainApp.getConfigBuilder().getProfileSwitchesFromHistory().getList();
|
|
||||||
|
|
||||||
for (int tx = 0; tx < profileSwitches.size(); tx++) {
|
|
||||||
DataPointWithLabelInterface t = profileSwitches.get(tx);
|
|
||||||
if (t.getX() < fromTime || t.getX() > endTime) continue;
|
|
||||||
filteredTreatments.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
//log.debug("updateGUI checkpoint 8");
|
|
||||||
// Extended bolus
|
|
||||||
if (!pump.isFakingTempsByExtendedBoluses()) {
|
|
||||||
List<ExtendedBolus> extendedBoluses = MainApp.getConfigBuilder().getExtendedBolusesFromHistory().getList();
|
|
||||||
|
|
||||||
for (int tx = 0; tx < extendedBoluses.size(); tx++) {
|
|
||||||
DataPointWithLabelInterface t = extendedBoluses.get(tx);
|
|
||||||
if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue;
|
|
||||||
if (t.getDuration() == 0) continue;
|
|
||||||
t.setY(getNearestBg((long) t.getX(), bgReadingsArray));
|
|
||||||
filteredTreatments.add(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//log.debug("updateGUI checkpoint 9");
|
|
||||||
// Careportal
|
|
||||||
List<CareportalEvent> careportalEvents = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, true);
|
|
||||||
|
|
||||||
for (int tx = 0; tx < careportalEvents.size(); tx++) {
|
|
||||||
DataPointWithLabelInterface t = careportalEvents.get(tx);
|
|
||||||
if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue;
|
|
||||||
t.setY(getNearestBg((long) t.getX(), bgReadingsArray));
|
|
||||||
filteredTreatments.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
DataPointWithLabelInterface[] treatmentsArray = new DataPointWithLabelInterface[filteredTreatments.size()];
|
|
||||||
treatmentsArray = filteredTreatments.toArray(treatmentsArray);
|
|
||||||
if (treatmentsArray.length > 0) {
|
|
||||||
addSeriesWithoutInvalidate(new PointsWithLabelGraphSeries<>(treatmentsArray), bgGraph);
|
|
||||||
}
|
|
||||||
//log.debug("updateGUI checkpoint 10");
|
|
||||||
|
|
||||||
// set manual y bounds to have nice steps
|
|
||||||
bgGraph.getViewport().setMaxY(maxBgValue);
|
|
||||||
bgGraph.getViewport().setMinY(0);
|
|
||||||
bgGraph.getViewport().setYAxisBoundsManual(true);
|
|
||||||
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfVertLines);
|
|
||||||
|
|
||||||
// set second scale
|
|
||||||
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
|
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
|
||||||
bgGraph.getSecondScale().setMinY(0);
|
graphData.addBasals(bgGraph, fromTime, now, lowLine / graphData.maxY / 1.2d);
|
||||||
bgGraph.getSecondScale().setMaxY(maxBgValue / lowLine * maxBasalValueFound * 1.2d);
|
|
||||||
bgGraph.getSecondScale().addSeries(baseBasalsSeries);
|
|
||||||
bgGraph.getSecondScale().addSeries(tempBasalsSeries);
|
|
||||||
bgGraph.getSecondScale().addSeries(basalsLineSeries);
|
|
||||||
bgGraph.getSecondScale().addSeries(absoluteBasalsLineSeries);
|
|
||||||
}
|
|
||||||
bgGraph.getSecondScale().setLabelFormatter(new LabelFormatter() {
|
|
||||||
@Override
|
|
||||||
public String formatLabel(double value, boolean isValueX) {
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setViewport(Viewport viewport) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//log.debug("updateGUI checkpoint 11");
|
|
||||||
// **** NOW line ****
|
// **** NOW line ****
|
||||||
DataPoint[] nowPoints = new DataPoint[]{
|
graphData.addNowLine(bgGraph, now);
|
||||||
new DataPoint(now, 0),
|
secondGraphData.addNowLine(iobGraph, now);
|
||||||
new DataPoint(now, maxBgValue)
|
|
||||||
};
|
// finaly enforce drawing of graphs
|
||||||
addSeriesWithoutInvalidate(seriesNow = new LineGraphSeries<>(nowPoints), bgGraph);
|
|
||||||
seriesNow.setDrawDataPoints(false);
|
|
||||||
DataPoint[] nowPoints2 = new DataPoint[]{
|
|
||||||
new DataPoint(now, 0),
|
|
||||||
new DataPoint(now, maxIobValueFound)
|
|
||||||
};
|
|
||||||
addSeriesWithoutInvalidate(seriesNow2 = new LineGraphSeries<>(nowPoints2), iobGraph);
|
|
||||||
seriesNow2.setDrawDataPoints(false);
|
|
||||||
//seriesNow.setThickness(1);
|
|
||||||
// custom paint to make a dotted line
|
|
||||||
Paint paint = new Paint();
|
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
|
||||||
paint.setStrokeWidth(2);
|
|
||||||
paint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0));
|
|
||||||
paint.setColor(Color.WHITE);
|
|
||||||
seriesNow.setCustomPaint(paint);
|
|
||||||
seriesNow2.setCustomPaint(paint);
|
|
||||||
bgGraph.onDataChanged(false, false);
|
bgGraph.onDataChanged(false, false);
|
||||||
iobGraph.onDataChanged(false, false);
|
iobGraph.onDataChanged(false, false);
|
||||||
|
|
||||||
Profiler.log(log, from, updateGUIStart);
|
Profiler.log(log, from, updateGUIStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getNearestBg(long date, List<BgReading> bgReadingsArray) {
|
|
||||||
double bg = 0;
|
|
||||||
String units = MainApp.getConfigBuilder().getProfileUnits();
|
|
||||||
for (int r = bgReadingsArray.size() - 1; r >= 0; r--) {
|
|
||||||
BgReading reading = bgReadingsArray.get(r);
|
|
||||||
if (reading.date > date) continue;
|
|
||||||
bg = Profile.fromMgdlToUnits(reading.value, units);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return bg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addSeriesWithoutInvalidate(Series s, GraphView graph) {
|
|
||||||
s.onGraphViewAttached(graph);
|
|
||||||
graph.getSeries().add(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Notifications
|
//Notifications
|
||||||
static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.NotificationsViewHolder> {
|
static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.NotificationsViewHolder> {
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
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.androidaps.plugins.Overview.notifications.NotificationStore;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,6 +104,11 @@ public class OverviewPlugin implements PluginBase {
|
||||||
// Always visible
|
// Always visible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return PluginBase.GENERAL;
|
return PluginBase.GENERAL;
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package info.nightscout.androidaps.plugins.Overview.events;
|
package info.nightscout.androidaps.plugins.Overview.events;
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by adrian on 20/02/17.
|
* Created by adrian on 20/02/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventDismissBolusprogressIfRunning {
|
public class EventDismissBolusprogressIfRunning extends Event {
|
||||||
public final PumpEnactResult result;
|
public final PumpEnactResult result;
|
||||||
|
|
||||||
public EventDismissBolusprogressIfRunning(PumpEnactResult result) {
|
public EventDismissBolusprogressIfRunning(PumpEnactResult result) {
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package info.nightscout.androidaps.plugins.Overview.events;
|
package info.nightscout.androidaps.plugins.Overview.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 03.12.2016.
|
* Created by mike on 03.12.2016.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventDismissNotification {
|
public class EventDismissNotification extends Event {
|
||||||
public int id;
|
public int id;
|
||||||
|
|
||||||
public EventDismissNotification(int did) {
|
public EventDismissNotification(int did) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue