diff --git a/app/build.gradle b/app/build.gradle
index 8c86af585e..cbcc428f25 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -188,4 +188,6 @@ dependencies {
compile 'com.google.code.gson:gson:2.7'
compile 'com.google.guava:guava:20.0'
+ compile 'net.danlew:android.joda:2.9.9.1'
+ testCompile 'joda-time:joda-time:2.9.4.2'
}
diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java
index 694b93743e..9fe435d838 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainApp.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java
@@ -15,6 +15,8 @@ import com.squareup.otto.Bus;
import com.squareup.otto.LoggingBus;
import com.squareup.otto.ThreadEnforcer;
+import net.danlew.android.joda.JodaTimeAndroid;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -97,6 +99,7 @@ public class MainApp extends Application {
super.onCreate();
Fabric.with(this, new Crashlytics());
Fabric.with(this, new Answers());
+ JodaTimeAndroid.init(this);
Crashlytics.setString("BUILDVERSION", BuildConfig.BUILDVERSION);
log.info("Version: " + BuildConfig.VERSION_NAME);
log.info("BuildVersion: " + BuildConfig.BUILDVERSION);
diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java
index 7a6ebbd701..0114b8a48d 100644
--- a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java
@@ -21,5 +21,5 @@ public interface InsulinInterface {
String getFriendlyName();
String getComment();
double getDia();
- Iob iobCalcForTreatment(Treatment treatment, long time, Double dia);
+ Iob iobCalcForTreatment(Treatment treatment, long time, double dia);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java
index a3ada67538..087a1dd0bd 100644
--- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java
@@ -36,7 +36,7 @@ public interface PumpInterface {
PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo);
void stopBolusDelivering();
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew);
- PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes);
+ PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew);
PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes);
//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
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java
index e734cd4f96..e6c653b5ef 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java
@@ -155,7 +155,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
}
};
if (setAsPercent) {
- ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(finalBasalPercent, finalDurationInMinutes, callback);
+ ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(finalBasalPercent, finalDurationInMinutes, true, callback);
} else {
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(finalBasal, finalDurationInMinutes, true, callback);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java
index c7164ea60e..6218a2ecfe 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java
@@ -107,7 +107,7 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
}
@Override
- public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) {
+ public Iob iobCalcForTreatment(Treatment treatment, long time, double dia) {
Iob result = new Iob();
double scaleFactor = 3.0 / dia;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java
index 99c35a6c0b..4155a9be56 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java
@@ -107,7 +107,7 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte
}
@Override
- public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) {
+ public Iob iobCalcForTreatment(Treatment treatment, long time, double dia) {
Iob result = new Iob();
//Double scaleFactor = 3.0 / dia;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java
index 6210f91c9a..cbe5f2ff64 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java
@@ -64,7 +64,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf
}
@Override
- public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) {
+ public Iob iobCalcForTreatment(Treatment treatment, long time, double dia) {
Iob result = new Iob();
int peak = getPeak();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
index 464c422596..28dbf899c4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
@@ -344,7 +344,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
}
- ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 120, true, new Callback() {
+ ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, new Callback() {
@Override
public void run() {
if (!result.success) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
index 45526bc3a4..ce606214d0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
@@ -78,6 +78,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTempTargetChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
@@ -329,6 +330,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
super.onCreateContextMenu(menu, v, menuInfo);
if (v == apsModeView) {
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
+ final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription();
if (activeloop == null)
return;
menu.setHeaderTitle(MainApp.sResources.getString(R.string.loop));
@@ -339,7 +341,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
menu.add(MainApp.sResources.getString(R.string.suspendloopfor2h));
menu.add(MainApp.sResources.getString(R.string.suspendloopfor3h));
menu.add(MainApp.sResources.getString(R.string.suspendloopfor10h));
- menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m));
+ if (pumpDescription.tempDurationStep <= 30)
+ menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor1h));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor2h));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor3h));
@@ -478,7 +481,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
activeloop.disconnectTo(System.currentTimeMillis() + 30L * 60 * 1000);
updateGUI("suspendmenu");
- ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 30, true, new Callback() {
+ ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 30, true, new Callback() {
@Override
public void run() {
if (!result.success) {
@@ -491,7 +494,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
activeloop.disconnectTo(System.currentTimeMillis() + 1 * 60L * 60 * 1000);
updateGUI("suspendmenu");
- ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 60, true, new Callback() {
+ ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 60, true, new Callback() {
@Override
public void run() {
if (!result.success) {
@@ -504,7 +507,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
activeloop.disconnectTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
updateGUI("suspendmenu");
- ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 2 * 60, true, new Callback() {
+ ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 2 * 60, true, new Callback() {
@Override
public void run() {
if (!result.success) {
@@ -517,7 +520,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
activeloop.disconnectTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
updateGUI("suspendmenu");
- ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 3 * 60, true, new Callback() {
+ ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 3 * 60, true, new Callback() {
@Override
public void run() {
if (!result.success) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java
index 8637b863fb..ebd31e915f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java
@@ -23,6 +23,7 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventInitializationChanged;
+import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
@@ -84,15 +85,17 @@ public class LocalProfileFragment extends SubscriberFragment {
}
};
+ PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription();
+
View layout = inflater.inflate(R.layout.localprofile_fragment, container, false);
diaView = (NumberPicker) layout.findViewById(R.id.localprofile_dia);
diaView.setParams(localProfilePlugin.dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch);
mgdlView = (RadioButton) layout.findViewById(R.id.localprofile_mgdl);
mmolView = (RadioButton) layout.findViewById(R.id.localprofile_mmol);
- icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", getPlugin().ic, null, 0.1d, new DecimalFormat("0.0"), save);
- isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", getPlugin().isf, null, 0.1d, new DecimalFormat("0.0"), save);
- basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), getPlugin().basal, null, 0.01d, new DecimalFormat("0.00"), save);
- targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", getPlugin().targetLow, getPlugin().targetHigh, 0.1d, new DecimalFormat("0.0"), save);
+ icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save);
+ isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save);
+ basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save);
+ targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", getPlugin().targetLow, getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch);
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
index 167c430a6e..affa668148 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
@@ -434,7 +434,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
// Convert duration from minutes to hours
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)");
- return setTempBasalPercent(percentRate, durationInMinutes);
+ return setTempBasalPercent(percentRate, durationInMinutes, false);
}
if (doExtendedTemp) {
// Check if some temp is already in progress
@@ -499,7 +499,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
}
@Override
- public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
+ public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult();
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
percent = configBuilderPlugin.applyBasalConstraints(percent);
@@ -514,7 +514,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
- if (runningTB != null && runningTB.percentRate == percent) {
+ if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false;
result.success = true;
result.isTempCancel = false;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
index 32c9f209ef..0caab03cc8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
@@ -436,7 +436,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
// Convert duration from minutes to hours
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)");
- return setTempBasalPercent(percentRate, durationInMinutes);
+ return setTempBasalPercent(percentRate, durationInMinutes, false);
}
if (doExtendedTemp) {
// Check if some temp is already in progress
@@ -501,7 +501,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
}
@Override
- public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
+ public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult();
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
percent = configBuilderPlugin.applyBasalConstraints(percent);
@@ -516,7 +516,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
- if (runningTB != null && runningTB.percentRate == percent) {
+ if (runningTB != null && runningTB.percentRate == percent && enforceNew) {
result.enacted = false;
result.success = true;
result.isTempCancel = false;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java
index 87d8ccad5d..fcbd89cfab 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java
@@ -580,7 +580,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
}
@Override
- public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
+ public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult();
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
percent = configBuilderPlugin.applyBasalConstraints(percent);
@@ -595,7 +595,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
- if (runningTB != null && runningTB.percentRate == percent) {
+ if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false;
result.success = true;
result.isTempCancel = false;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java
index a30e237672..bd6f5ca690 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java
@@ -185,7 +185,10 @@ public class DanaRSService extends Service {
while (!msg.done && bleComm.isConnected()) {
SystemClock.sleep(100);
}
- lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded - 45 * 60 * 1000L; // always load last 45 min
+ if (DanaRS_Packet_APS_History_Events.lastEventTimeLoaded != 0)
+ lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded - 45 * 60 * 1000L; // always load last 45 min
+ else
+ lastHistoryFetched = 0;
log.debug("Events loaded");
return new PumpEnactResult().success(true);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
index 0c3ac39860..f074cb84c0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
@@ -437,7 +437,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
}
@Override
- public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
+ public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult();
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
percent = configBuilderPlugin.applyBasalConstraints(percent);
@@ -452,7 +452,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
- if (runningTB != null && runningTB.percentRate == percent) {
+ if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false;
result.success = true;
result.isTempCancel = false;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java
index 4e5b85177a..6d6ba34838 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java
@@ -527,7 +527,10 @@ public class DanaRv2ExecutionService extends Service {
waitMsec(100);
}
waitMsec(200);
- lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - 45 * 60 * 1000L; //always load last 45 min;
+ if (MsgHistoryEvents_v2.lastEventTimeLoaded != 0)
+ lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - 45 * 60 * 1000L; //always load last 45 min;
+ else
+ lastHistoryFetched = 0;
return new PumpEnactResult().success(true);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java
index fd5d2bd270..564d29d53b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java
@@ -204,7 +204,7 @@ public class MDIPlugin implements PluginBase, PumpInterface {
}
@Override
- public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
+ public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult();
result.success = false;
result.comment = MainApp.instance().getString(R.string.pumperror);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java
index c278f7fb16..13d3f134f4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java
@@ -304,7 +304,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
}
@Override
- public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
+ public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
PumpEnactResult result = new PumpEnactResult();
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
index be13f62960..1d12182df8 100644
--- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
+++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
@@ -213,7 +213,7 @@ public class CommandQueue {
}
// returns true if command is queued
- public boolean tempBasalPercent(int percent, int durationInMinutes, Callback callback) {
+ public boolean tempBasalPercent(int percent, int durationInMinutes, boolean enforceNew, Callback callback) {
if (isRunning(Command.CommandType.TEMPBASAL)) {
if (callback != null)
callback.result(executingNowError()).run();
@@ -226,7 +226,7 @@ public class CommandQueue {
Integer percentAfterConstraints = MainApp.getConfigBuilder().applyBasalConstraints(percent);
// add new command to queue
- add(new CommandTempBasalPercent(percentAfterConstraints, durationInMinutes, callback));
+ add(new CommandTempBasalPercent(percentAfterConstraints, durationInMinutes, enforceNew, callback));
notifyAboutNewCommand();
diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java
index 663a20380d..e037f0b869 100644
--- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java
+++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java
@@ -18,17 +18,19 @@ public class CommandTempBasalPercent extends Command {
int durationInMinutes;
int percent;
+ boolean enforceNew;
- public CommandTempBasalPercent(int percent, int durationInMinutes, Callback callback) {
+ public CommandTempBasalPercent(int percent, int durationInMinutes, boolean enforceNew, Callback callback) {
commandType = CommandType.TEMPBASAL;
this.percent = percent;
this.durationInMinutes = durationInMinutes;
+ this.enforceNew = enforceNew;
this.callback = callback;
}
@Override
public void execute() {
- PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalPercent(percent, durationInMinutes);
+ PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalPercent(percent, durationInMinutes, enforceNew);
if (Config.logCongigBuilderActions)
log.debug("setTempBasalPercent percent: " + percent + " durationInMinutes: " + durationInMinutes + " success: " + r.success + " enacted: " + r.enacted);
if (callback != null)
diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java
index a97ed233ff..5a683f1aaa 100644
--- a/app/src/main/java/info/nightscout/utils/BolusWizard.java
+++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java
@@ -71,7 +71,9 @@ public class BolusWizard {
targetBGLow = Profile.fromMgdlToUnits(tempTarget.low, specificProfile.getUnits());
targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, specificProfile.getUnits());
}
- if (bg <= targetBGLow) {
+ if (bg >= targetBGLow && bg <= targetBGHigh) {
+ bgDiff = 0d;
+ } else if (bg <= targetBGLow) {
bgDiff = bg - targetBGLow;
} else {
bgDiff = bg - targetBGHigh;
diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java
index c406568730..86965621d2 100644
--- a/app/src/main/java/info/nightscout/utils/DateUtil.java
+++ b/app/src/main/java/info/nightscout/utils/DateUtil.java
@@ -2,10 +2,12 @@ package info.nightscout.utils;
import android.support.v4.util.LongSparseArray;
import android.text.format.DateUtils;
-import android.util.SparseIntArray;
+
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
import java.text.DateFormat;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@@ -27,9 +29,7 @@ public class DateUtil {
/**
* The date format in iso.
*/
- private static String FORMAT_DATE_ISO = "yyyy-MM-dd'T'HH:mm:ssZ";
- private static String FORMAT_DATE_ISO_MSEC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
- private static String FORMAT_DATE_ISO_MSEC_UTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+ private static String FORMAT_DATE_ISO_OUT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
/**
* Takes in an ISO date string of the following format:
@@ -41,33 +41,10 @@ public class DateUtil {
*/
public static Date fromISODateString(String isoDateString)
throws Exception {
- SimpleDateFormat f = new SimpleDateFormat(FORMAT_DATE_ISO, Locale.getDefault());
- Date date;
- f.setTimeZone(TimeZone.getTimeZone("UTC"));
- try {
- date = f.parse(isoDateString);
- return date;
- } catch (ParseException e) {
- }
-
- f = new SimpleDateFormat(FORMAT_DATE_ISO_MSEC, Locale.getDefault());
- f.setTimeZone(TimeZone.getTimeZone("UTC"));
- try {
- date = f.parse(isoDateString);
- return date;
- } catch (ParseException e) {
- }
-
- f = new SimpleDateFormat(FORMAT_DATE_ISO_MSEC_UTC, Locale.getDefault());
- f.setTimeZone(TimeZone.getTimeZone("UTC"));
- try {
- date = f.parse(isoDateString);
- return date;
- } catch (ParseException e) {
- }
-
- throw new ParseException("Unparseable date: " + isoDateString, 0);
+ DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
+ DateTime dateTime = DateTime.parse(isoDateString, parser);
+ return dateTime.toDate();
}
/**
@@ -79,7 +56,7 @@ public class DateUtil {
* @return the iso-formatted date string
*/
public static String toISOString(Date date, String format, TimeZone tz) {
- if (format == null) format = FORMAT_DATE_ISO;
+ if (format == null) format = FORMAT_DATE_ISO_OUT;
if (tz == null) tz = TimeZone.getDefault();
DateFormat f = new SimpleDateFormat(format, Locale.getDefault());
f.setTimeZone(tz);
@@ -87,21 +64,18 @@ public class DateUtil {
}
public static String toISOString(Date date) {
- return toISOString(date, FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC"));
+ return toISOString(date, FORMAT_DATE_ISO_OUT, TimeZone.getTimeZone("UTC"));
}
public static String toISOString(long date) {
- return toISOString(new Date(date), FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC"));
+ return toISOString(new Date(date), FORMAT_DATE_ISO_OUT, TimeZone.getTimeZone("UTC"));
}
public static Date toDate(Integer seconds) {
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.HOUR_OF_DAY, seconds / 60 / 60);
- String a = calendar.getTime().toString();
calendar.set(Calendar.MINUTE, (seconds / 60) % 60);
- String b = calendar.getTime().toString();
calendar.set(Calendar.SECOND, 0);
- String c = calendar.getTime().toString();
return calendar.getTime();
}
diff --git a/app/src/main/java/info/nightscout/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/utils/TimeListEdit.java
index af3668310a..bc41ece59d 100644
--- a/app/src/main/java/info/nightscout/utils/TimeListEdit.java
+++ b/app/src/main/java/info/nightscout/utils/TimeListEdit.java
@@ -52,6 +52,8 @@ public class TimeListEdit {
private JSONArray data1;
private JSONArray data2;
private double step;
+ private double min;
+ private double max;
private NumberFormat formatter;
private Runnable save;
private LinearLayout layout;
@@ -59,7 +61,7 @@ public class TimeListEdit {
private int inflatedUntil = -1;
- public TimeListEdit(Context context, View view, int resLayoutId, String label, JSONArray data1, JSONArray data2, double step, NumberFormat formatter, Runnable save) {
+ public TimeListEdit(Context context, View view, int resLayoutId, String label, JSONArray data1, JSONArray data2, double min, double max, double step, NumberFormat formatter, Runnable save) {
this.context = context;
this.view = view;
this.resLayoutId = resLayoutId;
@@ -67,6 +69,8 @@ public class TimeListEdit {
this.data1 = data1;
this.data2 = data2;
this.step = step;
+ this.min = min;
+ this.max = max;
this.formatter = formatter;
this.save = save;
buildView();
@@ -239,8 +243,8 @@ public class TimeListEdit {
if (i == 0) next = ONEHOURINSECONDS;
fillSpinner(timeSpinner, secondFromMidnight(i), previous, next);
- editText1.setParams(value1(i), 0.1d, 100d, step, formatter, false);
- editText2.setParams(value2(i), 0.1d, 100d, step, formatter, false);
+ editText1.setParams(value1(i), min, max, step, formatter, false);
+ editText2.setParams(value2(i), min, max, step, formatter, false);
if (data2 == null) {
editText2.setVisibility(View.GONE);
diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml
index d1738abd28..c986fdba7f 100644
--- a/app/src/main/res/values-el/strings.xml
+++ b/app/src/main/res/values-el/strings.xml
@@ -208,7 +208,6 @@
Σύνδεση
Συνδέθηκε
Αποσύνδεση
- Συγχρονισμός προφίλ στην αντλία
Ρυθμίσεις αντλίας DanaR
Nightscout
Άδεια χρήσης τελικού χρήστη
@@ -675,4 +674,4 @@
Τοπικές Ειδοποιήσεις
Ειδοποίησε αν δεν ληφθούν δεδομένα μετρήσεων BG
Απενεργοποιεί το bluetooth του τηλεφώνου για ένα δευτερόλεπτο αν δεν είναι δυνατή η σύνδεση με την αντλία.Αυτό μπορεί να βοηθήσει σε ορισμένα τηλέφωνα όπου το bluetooth παγώνει
-
\ No newline at end of file
+
diff --git a/app/src/test/java/info/nightscout/utils/DateUtilTest.java b/app/src/test/java/info/nightscout/utils/DateUtilTest.java
index 4b48148341..d720487201 100644
--- a/app/src/test/java/info/nightscout/utils/DateUtilTest.java
+++ b/app/src/test/java/info/nightscout/utils/DateUtilTest.java
@@ -3,7 +3,9 @@ package info.nightscout.utils;
import org.junit.Test;
-import static org.junit.Assert.*;
+import java.util.Date;
+
+import static org.junit.Assert.assertEquals;
/**
* Created by mike on 20.11.2017.
@@ -17,10 +19,15 @@ public class DateUtilTest {
@Test
public void fromISODateStringTest() throws Exception {
- assertEquals( 1511124634417L, DateUtil.fromISODateString("2017-11-19T22:50:34.417+0200").getTime());
- assertEquals( 1511124634000L, DateUtil.fromISODateString("2017-11-19T22:50:34+0200").getTime());
- assertEquals( 1512317365000L, DateUtil.fromISODateString("2017-12-03T16:09:25.000Z").getTime());
+ assertEquals(1511124634417L, DateUtil.fromISODateString("2017-11-19T22:50:34.417+0200").getTime());
+ assertEquals(1511124634000L, DateUtil.fromISODateString("2017-11-19T22:50:34+0200").getTime());
+ assertEquals(1512317365000L, DateUtil.fromISODateString("2017-12-03T16:09:25.000Z").getTime());
+ assertEquals(1513902750000L, DateUtil.fromISODateString("2017-12-22T00:32:30Z").getTime());
}
+ @Test
+ public void toISOStringTest() throws Exception {
+ assertEquals("2017-12-22T00:32:30Z", DateUtil.toISOString(new Date(1513902750000L)));
+ }
}