diff --git a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java
index 0bfcbb1002..062f6ae391 100644
--- a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java
+++ b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java
@@ -50,7 +50,7 @@ public class QuickWizardEntry {
useTemptarget: 0
}
*/
- public QuickWizardEntry() {
+ QuickWizardEntry() {
String emptyData = "{\"buttonText\":\"\",\"carbs\":0,\"validFrom\":0,\"validTo\":86340}";
try {
storage = new JSONObject(emptyData);
@@ -60,18 +60,17 @@ public class QuickWizardEntry {
position = -1;
}
- public QuickWizardEntry(JSONObject entry, int position) {
+ QuickWizardEntry(JSONObject entry, int position) {
storage = entry;
this.position = position;
}
- public Boolean isActive() {
+ Boolean isActive() {
return Profile.secondsFromMidnight() >= validFrom() && Profile.secondsFromMidnight() <= validTo();
}
- public BolusWizard doCalc(Profile profile, TempTarget tempTarget, BgReading lastBG, boolean _synchronized) {
- BolusWizard wizard = new BolusWizard();
-
+ public BolusWizard doCalc(Profile profile, String profileName, BgReading lastBG, boolean _synchronized) {
+ final TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory();
//BG
double bg = 0;
if (lastBG != null && useBG() == YES) {
@@ -86,11 +85,6 @@ public class QuickWizardEntry {
cob = cobInfo.displayCob;
}
- // Temp target
- if (useTempTarget() == NO) {
- tempTarget = null;
- }
-
// Bolus IOB
boolean bolusIOB = false;
if (useBolusIOB() == YES) {
@@ -130,8 +124,7 @@ public class QuickWizardEntry {
trend = true;
}
- wizard.doCalc(profile, tempTarget, carbs(), cob, bg, 0d, bolusIOB, basalIOB, superBolus, trend);
- return wizard;
+ return new BolusWizard(profile, profileName, tempTarget, carbs(), cob, bg, 0d, 100, true, useCOB() == YES, bolusIOB, basalIOB, superBolus, useTempTarget() == YES, trend, "QuickWizard");
}
public String buttonText() {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java
index 65dc119c6a..127752d8dc 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java
@@ -13,10 +13,10 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
@@ -196,7 +196,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (pump != null) {
- double rounded = Round.roundTo(insulin.value(), pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulin.value()));
+ double rounded = pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulin.value());
insulin.setIfDifferent(rounded, MainApp.gs(R.string.pumplimit), this);
}
return insulin;
@@ -213,7 +213,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (pump != null) {
- double rounded = Round.roundTo(insulin.value(), pump.getPumpDescription().pumpType.determineCorrectExtendedBolusSize(insulin.value()));
+ double rounded = pump.getPumpDescription().pumpType.determineCorrectExtendedBolusSize(insulin.value());
insulin.setIfDifferent(rounded, MainApp.gs(R.string.pumplimit), this);
}
return insulin;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java
index ee19d09f99..23440c2491 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java
@@ -37,12 +37,9 @@ import android.widget.TextView;
import com.jjoe64.graphview.GraphView;
import com.squareup.otto.Subscribe;
-import org.json.JSONException;
-import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
@@ -55,7 +52,6 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.QuickWizardEntry;
@@ -95,7 +91,6 @@ import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity;
import info.nightscout.androidaps.plugins.general.overview.dialogs.CalibrationDialog;
-import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.plugins.general.overview.dialogs.NewCarbsDialog;
import info.nightscout.androidaps.plugins.general.overview.dialogs.NewInsulinDialog;
import info.nightscout.androidaps.plugins.general.overview.dialogs.NewTreatmentDialog;
@@ -781,141 +776,25 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
void onClickQuickwizard() {
final BgReading actualBg = DatabaseHelper.actualBg();
final Profile profile = ProfileFunctions.getInstance().getProfile();
- final TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory();
+ final String profileName = ProfileFunctions.getInstance().getProfileName();
+ final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
- if (quickWizardEntry != null && actualBg != null && profile != null) {
+ if (quickWizardEntry != null && actualBg != null && profile != null && pump != null) {
quickWizardButton.setVisibility(View.VISIBLE);
- final BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, actualBg, true);
+ final BolusWizard wizard = quickWizardEntry.doCalc(profile, profileName, actualBg, true);
- final JSONObject boluscalcJSON = new JSONObject();
- try {
- boluscalcJSON.put("eventTime", DateUtil.toISOString(new Date()));
- boluscalcJSON.put("targetBGLow", wizard.targetBGLow);
- boluscalcJSON.put("targetBGHigh", wizard.targetBGHigh);
- boluscalcJSON.put("isf", wizard.sens);
- boluscalcJSON.put("ic", wizard.ic);
- boluscalcJSON.put("iob", -(wizard.insulingFromBolusIOB + wizard.insulingFromBasalsIOB));
- boluscalcJSON.put("bolusiobused", true);
- boluscalcJSON.put("basaliobused", true);
- boluscalcJSON.put("bg", actualBg.valueToUnits(profile.getUnits()));
- boluscalcJSON.put("insulinbg", wizard.insulinFromBG);
- boluscalcJSON.put("insulinbgused", true);
- boluscalcJSON.put("bgdiff", wizard.bgDiff);
- boluscalcJSON.put("insulincarbs", wizard.insulinFromCarbs);
- boluscalcJSON.put("carbs", quickWizardEntry.carbs());
- boluscalcJSON.put("othercorrection", 0d);
- boluscalcJSON.put("insulintrend", wizard.insulinFromTrend);
- boluscalcJSON.put("insulin", wizard.calculatedTotalInsulin);
- } catch (JSONException e) {
- log.error("Unhandled exception", e);
- }
- if (wizard.calculatedTotalInsulin > 0d && quickWizardEntry.carbs() > 0d) {
- DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
- String confirmMessage = MainApp.gs(R.string.entertreatmentquestion);
-
- Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(wizard.calculatedTotalInsulin)).value();
+ if (wizard.getCalculatedTotalInsulin() > 0d && quickWizardEntry.carbs() > 0d) {
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(quickWizardEntry.carbs())).value();
- confirmMessage += "\n" + MainApp.gs(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U";
- confirmMessage += "\n" + MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
-
- if (Math.abs(insulinAfterConstraints - wizard.calculatedTotalInsulin) >= 0.01 || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
- builder.setTitle(MainApp.gs(R.string.treatmentdeliveryerror));
- builder.setMessage(MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput));
- builder.setPositiveButton(MainApp.gs(R.string.ok), null);
- builder.show();
+ if (Math.abs(wizard.getInsulinAfterConstraints() - wizard.getCalculatedTotalInsulin()) >= pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(wizard.getInsulinAfterConstraints()) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
+ OKDialog.show(getContext(), MainApp.gs(R.string.treatmentdeliveryerror), MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput), null);
return;
}
- final Double finalInsulinAfterConstraints = insulinAfterConstraints;
- final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
- final Context context = getContext();
- final AlertDialog.Builder builder = new AlertDialog.Builder(context);
- accepted = false;
- builder.setTitle(MainApp.gs(R.string.confirmation));
- builder.setMessage(confirmMessage);
- builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
- synchronized (builder) {
- if (accepted) {
- if (L.isEnabled(L.OVERVIEW))
- log.debug("guarding: already accepted");
- return;
- }
- accepted = true;
- if (Math.abs(insulinAfterConstraints - wizard.calculatedTotalInsulin) >= 0.01 || finalCarbsAfterConstraints > 0) {
- if (wizard.superBolus) {
- final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
- if (loopPlugin.isEnabled(PluginType.LOOP)) {
- loopPlugin.superBolusTo(System.currentTimeMillis() + T.hours(2).msecs());
- MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
- }
-
- PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
-
- if (pump.getPumpDescription().tempBasalStyle == PumpDescription.ABSOLUTE) {
- ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(0.0d, 120, true, profile, new Callback() {
- @Override
- public void run() {
- if (!result.success) {
- Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
- i.putExtra("soundid", R.raw.boluserror);
- i.putExtra("status", result.comment);
- i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
- i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- MainApp.instance().startActivity(i);
- }
- }
- });
- } else {
- ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(0, 120, true, profile, new Callback() {
- @Override
- public void run() {
- if (!result.success) {
- Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
- i.putExtra("soundid", R.raw.boluserror);
- i.putExtra("status", result.comment);
- i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
- i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- MainApp.instance().startActivity(i);
- }
- }
- });
- }
- }
- DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
- detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
- detailedBolusInfo.insulin = finalInsulinAfterConstraints;
- detailedBolusInfo.carbs = finalCarbsAfterConstraints;
- detailedBolusInfo.context = context;
- detailedBolusInfo.boluscalc = boluscalcJSON;
- detailedBolusInfo.source = Source.USER;
- if (finalInsulinAfterConstraints > 0 || ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().storesCarbInfo) {
- ConfigBuilderPlugin.getPlugin().getCommandQueue().bolus(detailedBolusInfo, new Callback() {
- @Override
- public void run() {
- if (!result.success) {
- Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
- i.putExtra("soundid", R.raw.boluserror);
- i.putExtra("status", result.comment);
- i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror));
- i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- MainApp.instance().startActivity(i);
- }
- }
- });
- } else {
- TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
- }
- }
- }
- });
- builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
- builder.show();
+ wizard.confirmAndExecute(getContext());
}
}
-
}
@Override
@@ -1100,6 +979,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
final Profile profile = ProfileFunctions.getInstance().getProfile();
+ final String profileName = ProfileFunctions.getInstance().getProfileName();
final String units = profile.getUnits();
final double lowLine = OverviewPlugin.getPlugin().determineLowLine(units);
@@ -1297,10 +1177,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) {
quickWizardButton.setVisibility(View.VISIBLE);
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
- BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, lastBG, false);
- text += " " + DecimalFormatter.toPumpSupportedBolus(wizard.calculatedTotalInsulin) + "U";
+ BolusWizard wizard = quickWizardEntry.doCalc(profile, profileName, lastBG, false);
+ text += " " + DecimalFormatter.toPumpSupportedBolus(wizard.getCalculatedTotalInsulin()) + "U";
quickWizardButton.setText(text);
- if (wizard.calculatedTotalInsulin <= 0)
+ if (wizard.getCalculatedTotalInsulin() <= 0)
quickWizardButton.setVisibility(View.GONE);
} else
quickWizardButton.setVisibility(View.GONE);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java
index 27e2e33ba7..ae29e98a3b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java
@@ -225,7 +225,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener
}
}
- if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints))
+ if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints))
actions.add("" + MainApp.gs(R.string.bolusconstraintapplied) + "");
int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewTreatmentDialog.java
index 837d206fb3..495cef0db5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewTreatmentDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewTreatmentDialog.java
@@ -141,7 +141,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
if (recordOnlyCheckbox.isChecked()) {
confirmMessage += "
" + MainApp.gs(R.string.bolusrecordedonly) + "";
}
- if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints) || !Objects.equals(carbsAfterConstraints, carbs))
+ if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints) || !Objects.equals(carbsAfterConstraints, carbs))
confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintapplied) + "";
}
if (carbsAfterConstraints > 0)
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.java
index 608be5b29f..0f7bbaf1f2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.java
@@ -2,13 +2,9 @@ package info.nightscout.androidaps.plugins.general.overview.dialogs;
import android.app.Activity;
import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
-import android.support.v7.app.AlertDialog;
import android.text.Editable;
-import android.text.Html;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
@@ -28,47 +24,35 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe;
-import org.json.JSONException;
-import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.ArrayList;
-import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.db.BgReading;
-import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.DatabaseHelper;
-import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.events.EventFeatureRunning;
-import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.Constraint;
-import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.interfaces.PumpDescription;
-import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
-import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.utils.BolusWizard;
-import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.NumberPicker;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.StringUtils;
import info.nightscout.androidaps.utils.ToastUtils;
public class WizardDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener, Spinner.OnItemSelectedListener {
@@ -109,8 +93,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
EditText notesEdit;
Integer calculatedCarbs = 0;
- Double calculatedTotalInsulin = 0d;
- JSONObject boluscalcJSON;
+ BolusWizard wizard;
Context context;
@@ -312,119 +295,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
return;
}
okClicked = true;
- final Profile profile = ProfileFunctions.getInstance().getProfile();
- final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
-
- if (pump != null && profile != null && (calculatedTotalInsulin > 0d || calculatedCarbs > 0d)) {
- String confirmMessage = MainApp.gs(R.string.entertreatmentquestion);
-
- Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(calculatedTotalInsulin)).value();
- Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(calculatedCarbs)).value();
-
- if (insulinAfterConstraints > 0)
- confirmMessage += "
" + MainApp.gs(R.string.bolus) + ": " + "" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + "";
- if (carbsAfterConstraints > 0)
- confirmMessage += "
" + MainApp.gs(R.string.carbs) + ": " + "" + carbsAfterConstraints + "g" + "";
-
- if (Math.abs(insulinAfterConstraints - calculatedTotalInsulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints) || !carbsAfterConstraints.equals(calculatedCarbs)) {
- confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintapplied) + "";
- }
-
- final Double finalInsulinAfterConstraints = insulinAfterConstraints;
- final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
- final Double bg = SafeParse.stringToDouble(editBg.getText());
- final int carbTime = SafeParse.stringToInt(editCarbTime.getText());
- final boolean useSuperBolus = superbolusCheckbox.isChecked();
- final String finalNotes = notesEdit.getText().toString();
-
- final AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(MainApp.gs(R.string.confirmation));
- builder.setMessage(Html.fromHtml(confirmMessage));
- builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
- 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 (useSuperBolus) {
- final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
- if (loopPlugin.isEnabled(PluginType.LOOP)) {
- loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
- MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
- }
-
- PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
-
- if (pump.getPumpDescription().tempBasalStyle == PumpDescription.ABSOLUTE) {
- ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(0.0d, 120, true, profile, new Callback() {
- @Override
- public void run() {
- if (!result.success) {
- Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
- i.putExtra("soundid", R.raw.boluserror);
- i.putExtra("status", result.comment);
- i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
- i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- MainApp.instance().startActivity(i);
- }
- }
- });
- } else {
-
- ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(0, 120, true, profile, new Callback() {
- @Override
- public void run() {
- if (!result.success) {
- Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
- i.putExtra("soundid", R.raw.boluserror);
- i.putExtra("status", result.comment);
- i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
- i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- MainApp.instance().startActivity(i);
- }
- }
- });
- }
- }
- DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
- detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
- detailedBolusInfo.insulin = finalInsulinAfterConstraints;
- detailedBolusInfo.carbs = finalCarbsAfterConstraints;
- detailedBolusInfo.context = context;
- detailedBolusInfo.glucose = bg;
- detailedBolusInfo.glucoseType = "Manual";
- detailedBolusInfo.carbTime = carbTime;
- detailedBolusInfo.boluscalc = boluscalcJSON;
- detailedBolusInfo.source = Source.USER;
- detailedBolusInfo.notes = finalNotes;
- if (detailedBolusInfo.insulin > 0 || ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().storesCarbInfo) {
- ConfigBuilderPlugin.getPlugin().getCommandQueue().bolus(detailedBolusInfo, new Callback() {
- @Override
- public void run() {
- if (!result.success) {
- Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
- i.putExtra("soundid", R.raw.boluserror);
- i.putExtra("status", result.comment);
- i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror));
- i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- MainApp.instance().startActivity(i);
- }
- }
- });
- } else {
- TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
- }
- }
- }
- }
- });
- builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
- builder.show();
- dismiss();
- }
+ wizard.confirmAndExecute(context);
+ dismiss();
break;
case R.id.cancel:
dismiss();
@@ -471,8 +343,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals();
IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round();
- bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U");
- basalIobInsulin.setText(DecimalFormatter.to2Decimal(-basalIob.basaliob) + "U");
+ bolusIobInsulin.setText(StringUtils.formatInsulin(-bolusIob.iob));
+ basalIobInsulin.setText(StringUtils.formatInsulin(-basalIob.basaliob));
calculateInsulin();
}
@@ -481,13 +353,13 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
ProfileStore profileStore = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile();
if (profileSpinner == null || profileSpinner.getSelectedItem() == null || profileStore == null)
return; // not initialized yet
- String selectedAlternativeProfile = profileSpinner.getSelectedItem().toString();
+ String profileName = profileSpinner.getSelectedItem().toString();
Profile specificProfile;
- if (selectedAlternativeProfile.equals(MainApp.gs(R.string.active))) {
+ if (profileName.equals(MainApp.gs(R.string.active))) {
specificProfile = ProfileFunctions.getInstance().getProfile();
- selectedAlternativeProfile = ProfileFunctions.getInstance().getProfileName();
+ profileName = ProfileFunctions.getInstance().getProfileName();
} else
- specificProfile = profileStore.getSpecificProfile(selectedAlternativeProfile);
+ specificProfile = profileStore.getSpecificProfile(profileName);
// Entered values
Double c_bg = SafeParse.stringToDouble(editBg.getText());
@@ -515,104 +387,61 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
Double c_cob = 0d;
if (cobCheckbox.isChecked()) {
CobInfo cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "Wizard COB");
- if (cobInfo != null && cobInfo.displayCob != null)
+ if (cobInfo.displayCob != null)
c_cob = cobInfo.displayCob;
}
- BolusWizard wizard = new BolusWizard();
- wizard.doCalc(specificProfile, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), bgtrendCheckbox.isChecked());
+ wizard = new BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, 100d, bgCheckbox.isChecked(), cobCheckbox.isChecked(), bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), ttCheckbox.isChecked(), bgtrendCheckbox.isChecked(), notesEdit.getText().toString(), SafeParse.stringToInt(editCarbTime.getText()));
- bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.sens));
- bgInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromBG) + "U");
+ bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.getSens()));
+ bgInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromBG()));
- carbs.setText(DecimalFormatter.to0Decimal(c_carbs) + "g IC: " + DecimalFormatter.to1Decimal(wizard.ic));
- carbsInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromCarbs) + "U");
+ carbs.setText(DecimalFormatter.to0Decimal(c_carbs) + "g IC: " + DecimalFormatter.to1Decimal(wizard.getIc()));
+ carbsInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromCarbs()));
- bolusIobInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulingFromBolusIOB) + "U");
- basalIobInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulingFromBasalsIOB) + "U");
+ bolusIobInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromBolusIOB()));
+ basalIobInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromBasalsIOB()));
- correctionInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromCorrection) + "U");
- calculatedTotalInsulin = wizard.calculatedTotalInsulin;
+ correctionInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromCorrection()));
calculatedCarbs = carbsAfterConstraint;
// Superbolus
- if (superbolusCheckbox.isChecked()) {
- superbolus.setText("2h");
- } else {
- superbolus.setText("");
- }
- superbolusInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromSuperBolus) + "U");
+ superbolus.setText(superbolusCheckbox.isChecked() ? MainApp.gs(R.string.twohours) : "");
+ superbolusInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromSuperBolus()));
// Trend
- if (bgtrendCheckbox.isChecked()) {
- if (wizard.glucoseStatus != null) {
- bgTrend.setText((wizard.glucoseStatus.avgdelta > 0 ? "+" : "") + Profile.toUnitsString(wizard.glucoseStatus.avgdelta * 3, wizard.glucoseStatus.avgdelta * 3 / 18, specificProfile.getUnits()) + " " + specificProfile.getUnits());
- } else {
- bgTrend.setText("");
- }
+ if (bgtrendCheckbox.isChecked() && wizard.getGlucoseStatus() != null) {
+ bgTrend.setText(
+ (wizard.getTrend() > 0 ? "+" : "")
+ + Profile.toUnitsString(wizard.getTrend() * 3, wizard.getTrend() * 3 / Constants.MMOLL_TO_MGDL, specificProfile.getUnits())
+ + " " + specificProfile.getUnits());
} else {
bgTrend.setText("");
}
- bgTrendInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromTrend) + "U");
+ bgTrendInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromTrend()));
// COB
if (cobCheckbox.isChecked()) {
- cob.setText(DecimalFormatter.to2Decimal(c_cob) + "g IC: " + DecimalFormatter.to1Decimal(wizard.ic));
- cobInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromCOB) + "U");
+ cob.setText(DecimalFormatter.to2Decimal(c_cob) + "g IC: " + DecimalFormatter.to1Decimal(wizard.getIc()));
+ cobInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromCOB()));
} else {
cob.setText("");
cobInsulin.setText("");
}
- if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
- String insulinText = calculatedTotalInsulin > 0d ? (DecimalFormatter.toPumpSupportedBolus(calculatedTotalInsulin) + "U") : "";
+ if (wizard.getCalculatedTotalInsulin() > 0d || calculatedCarbs > 0d) {
+ String insulinText = wizard.getCalculatedTotalInsulin() > 0d ? (DecimalFormatter.toPumpSupportedBolus(wizard.getCalculatedTotalInsulin()) + "U") : "";
String carbsText = calculatedCarbs > 0d ? (DecimalFormatter.to0Decimal(calculatedCarbs) + "g") : "";
total.setText(MainApp.gs(R.string.result) + ": " + insulinText + " " + carbsText);
okButton.setVisibility(View.VISIBLE);
} else {
// TODO this should also be run when loading the dialog as the OK button is initially visible
// but does nothing if neither carbs nor insulin is > 0
- total.setText(MainApp.gs(R.string.missing) + " " + DecimalFormatter.to0Decimal(wizard.carbsEquivalent) + "g");
+ total.setText(MainApp.gs(R.string.missing) + " " + DecimalFormatter.to0Decimal(wizard.getCarbsEquivalent()) + "g");
okButton.setVisibility(View.INVISIBLE);
}
- boluscalcJSON = new JSONObject();
- try {
- boluscalcJSON.put("profile", selectedAlternativeProfile);
- boluscalcJSON.put("notes", notesEdit.getText());
- boluscalcJSON.put("eventTime", DateUtil.toISOString(new Date()));
- boluscalcJSON.put("targetBGLow", wizard.targetBGLow);
- boluscalcJSON.put("targetBGHigh", wizard.targetBGHigh);
- boluscalcJSON.put("isf", wizard.sens);
- boluscalcJSON.put("ic", wizard.ic);
- boluscalcJSON.put("iob", -(wizard.insulingFromBolusIOB + wizard.insulingFromBasalsIOB));
- boluscalcJSON.put("bolusiob", wizard.insulingFromBolusIOB);
- boluscalcJSON.put("basaliob", wizard.insulingFromBasalsIOB);
- boluscalcJSON.put("bolusiobused", bolusIobCheckbox.isChecked());
- boluscalcJSON.put("basaliobused", basalIobCheckbox.isChecked());
- boluscalcJSON.put("bg", c_bg);
- boluscalcJSON.put("insulinbg", wizard.insulinFromBG);
- boluscalcJSON.put("insulinbgused", bgCheckbox.isChecked());
- boluscalcJSON.put("bgdiff", wizard.bgDiff);
- boluscalcJSON.put("insulincarbs", wizard.insulinFromCarbs);
- boluscalcJSON.put("carbs", c_carbs);
- boluscalcJSON.put("cob", c_cob);
- boluscalcJSON.put("cobused", cobCheckbox.isChecked());
- boluscalcJSON.put("insulincob", wizard.insulinFromCOB);
- boluscalcJSON.put("othercorrection", corrAfterConstraint);
- boluscalcJSON.put("insulinsuperbolus", wizard.insulinFromSuperBolus);
- boluscalcJSON.put("insulintrend", wizard.insulinFromTrend);
- boluscalcJSON.put("insulin", calculatedTotalInsulin);
- boluscalcJSON.put("superbolusused", superbolusCheckbox.isChecked());
- boluscalcJSON.put("insulinsuperbolus", wizard.insulinFromSuperBolus);
- boluscalcJSON.put("trendused", bgtrendCheckbox.isChecked());
- boluscalcJSON.put("insulintrend", wizard.insulinFromTrend);
- boluscalcJSON.put("trend", bgTrend.getText());
- boluscalcJSON.put("ttused", ttCheckbox.isChecked());
- } catch (JSONException e) {
- log.error("Unhandled exception", e);
- }
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java
index 1a01a783cd..6cc681fa23 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java
@@ -207,6 +207,7 @@ public class ActionStringHandler {
int percentage = Integer.parseInt(act[2]);
Profile profile = ProfileFunctions.getInstance().getProfile();
+ String profileName = ProfileFunctions.getInstance().getProfileName();
if (profile == null) {
sendError("No profile found!");
return;
@@ -226,45 +227,38 @@ public class ActionStringHandler {
DecimalFormat format = new DecimalFormat("0.00");
DecimalFormat formatInt = new DecimalFormat("0");
- BolusWizard bolusWizard = new BolusWizard();
- bolusWizard.doCalc(profile, useTT ? TreatmentsPlugin.getPlugin().getTempTargetFromHistory() : null,
- carbsAfterConstraints, useCOB?cobInfo.displayCob:0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d,
- 0d, percentage, useBolusIOB, useBasalIOB, false, useTrend);
+ BolusWizard bolusWizard = new BolusWizard(profile, profileName, TreatmentsPlugin.getPlugin().getTempTargetFromHistory(),
+ carbsAfterConstraints, cobInfo.displayCob, bgReading.valueToUnits(profile.getUnits()),
+ 0d, percentage, useBG, useCOB, useBolusIOB, useBasalIOB, false, useTT, useTrend);
- Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(bolusWizard.calculatedTotalInsulin)).value();
- if (Math.abs(insulinAfterConstraints - bolusWizard.calculatedTotalInsulin) >= 0.01) {
+ if (Math.abs(bolusWizard.getInsulinAfterConstraints() - bolusWizard.getCalculatedTotalInsulin()) >= 0.01) {
sendError("Insulin constraint violation!" +
- "\nCannot deliver " + format.format(bolusWizard.calculatedTotalInsulin) + "!");
+ "\nCannot deliver " + format.format(bolusWizard.getCalculatedTotalInsulin()) + "!");
return;
}
-
- if (bolusWizard.calculatedTotalInsulin < 0) {
- bolusWizard.calculatedTotalInsulin = 0d;
- }
-
- if (bolusWizard.calculatedTotalInsulin <= 0 && bolusWizard.carbs <= 0) {
+ if (bolusWizard.getCalculatedTotalInsulin() <= 0 && bolusWizard.getCarbs() <= 0) {
rAction = "info";
rTitle = "INFO";
} else {
rAction = actionstring;
}
- rMessage += "Carbs: " + bolusWizard.carbs + "g";
- rMessage += "\nBolus: " + format.format(bolusWizard.calculatedTotalInsulin) + "U";
+ rMessage += "Carbs: " + bolusWizard.getCarbs() + "g";
+ rMessage += "\nBolus: " + format.format(bolusWizard.getCalculatedTotalInsulin()) + "U";
rMessage += "\n_____________";
- rMessage += "\nCalc (IC:" + DecimalFormatter.to1Decimal(bolusWizard.ic) + ", " + "ISF:" + DecimalFormatter.to1Decimal(bolusWizard.sens) + "): ";
- rMessage += "\nFrom Carbs: " + format.format(bolusWizard.insulinFromCarbs) + "U";
+ rMessage += "\nCalc (IC:" + DecimalFormatter.to1Decimal(bolusWizard.getIc()) + ", " + "ISF:" + DecimalFormatter.to1Decimal(bolusWizard.getSens()) + "): ";
+ rMessage += "\nFrom Carbs: " + format.format(bolusWizard.getInsulinFromCarbs()) + "U";
if (useCOB)
- rMessage += "\nFrom" + formatInt.format(cobInfo.displayCob) + "g COB : " + format.format(bolusWizard.insulinFromCOB) + "U";
- if (useBG) rMessage += "\nFrom BG: " + format.format(bolusWizard.insulinFromBG) + "U";
+ rMessage += "\nFrom" + formatInt.format(cobInfo.displayCob) + "g COB : " + format.format(bolusWizard.getInsulinFromCOB()) + "U";
+ if (useBG) rMessage += "\nFrom BG: " + format.format(bolusWizard.getInsulinFromBG()) + "U";
if (useBolusIOB)
- rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U";
+ rMessage += "\nBolus IOB: " + format.format(bolusWizard.getInsulinFromBolusIOB()) + "U";
if (useBasalIOB)
- rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U";
+ rMessage += "\nBasal IOB: " + format.format(bolusWizard.getInsulinFromBasalsIOB()) + "U";
if (useTrend)
- rMessage += "\nFrom 15' trend: " + format.format(bolusWizard.insulinFromTrend) + "U";
+ rMessage += "\nFrom 15' trend: " + format.format(bolusWizard.getInsulinFromTrend()) + "U";
if (percentage != 100) {
- rMessage += "\nPercentage: " + format.format(bolusWizard.totalBeforePercentageAdjustment) + "U * " + percentage + "% -> ~" + format.format(bolusWizard.calculatedTotalInsulin) + "U";
+ rMessage += "\nPercentage: " + format.format(bolusWizard.getTotalBeforePercentageAdjustment()) + "U * " + percentage + "% -> ~" + format.format(bolusWizard.getCalculatedTotalInsulin()) + "U";
}
lastBolusWizard = bolusWizard;
@@ -628,7 +622,7 @@ public class ActionStringHandler {
if (lastBolusWizard != null) {
//use last calculation as confirmed string matches
- doBolus(lastBolusWizard.calculatedTotalInsulin, lastBolusWizard.carbs);
+ doBolus(lastBolusWizard.getCalculatedTotalInsulin(), lastBolusWizard.getCarbs());
lastBolusWizard = null;
}
} else if ("bolus".equals(act[0])) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java
index 9a7e351bf1..df92114ea4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java
@@ -7,83 +7,83 @@ import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.data.DoseSettings;
-
+import info.nightscout.androidaps.utils.Round;
/**
* Created by andy on 02/05/2018.
- *
+ *
* Most of this defintions is intended for VirtualPump only, but they can be used by other plugins.
*/
public enum PumpType {
GenericAAPS("Generic AAPS", 0.1d, null, //
- new DoseSettings(0.05d, 30, 8*60, 0.05d), //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, //
- new DoseSettings(10,30, 24*60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ new DoseSettings(10, 30, 24 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01d, 0.01d, null, PumpCapability.VirtualPumpCapabilities), //
// Cellnovo
Cellnovo1("Cellnovo", 0.05d, null, //
- new DoseSettings(0.05d, 30, 24*60, 1d, null),
+ new DoseSettings(0.05d, 30, 24 * 60, 1d, null),
PumpTempBasalType.Percent,
- new DoseSettings(5,30, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration30minAllowed, //
+ new DoseSettings(5, 30, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), //
// Accu-Chek
AccuChekCombo("Accu-Chek Combo", 0.1d, null, //
- new DoseSettings(0.1d, 15, 12*60, 0.1d), //
+ new DoseSettings(0.1d, 15, 12 * 60, 0.1d), //
PumpTempBasalType.Percent,
- new DoseSettings(10, 15, 12*60,0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01d, 0.01d, DoseStepSize.ComboBasal, PumpCapability.ComboCapabilities), //
AccuChekSpirit("Accu-Chek Spirit", 0.1d, null, //
- new DoseSettings(0.1d, 15, 12*60, 0.1d), //
+ new DoseSettings(0.1d, 15, 12 * 60, 0.1d), //
PumpTempBasalType.Percent,
- new DoseSettings(10, 15, 12*60,0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01d, 0.1d, null, PumpCapability.VirtualPumpCapabilities), //
AccuChekInsight("Accu-Chek Insight", 0.05d, DoseStepSize.InsightBolus, //
- new DoseSettings(0.05d, 15, 24*60, 0.05d), //
+ new DoseSettings(0.05d, 15, 24 * 60, 0.05d), //
PumpTempBasalType.Percent,
- new DoseSettings(10, 15, 24*60,0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.02d, 0.01d, null, PumpCapability.InsightCapabilities), //
AccuChekInsightBluetooth("Accu-Chek Insight", 0.01d, null, //
- new DoseSettings(0.01d, 15, 24*60, 0.05d), //
+ new DoseSettings(0.01d, 15, 24 * 60, 0.05d), //
PumpTempBasalType.Percent,
- new DoseSettings(10, 15, 24*60,0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.02d, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities), //
// Animas
AnimasVibe("Animas Vibe", 0.05d, null, // AnimasBolus?
- new DoseSettings(0.05d, 30, 12*60, 0.05d), //
+ new DoseSettings(0.05d, 30, 12 * 60, 0.05d), //
PumpTempBasalType.Percent, //
- new DoseSettings(10, 30, 24*60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, //
+ new DoseSettings(10, 30, 24 * 60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 5d, 0d, null, PumpCapability.VirtualPumpCapabilities), //
AnimasPing("Animas Ping", AnimasVibe),
// Dana
DanaR("DanaR", 0.05d, null, //
- new DoseSettings(0.05d, 30, 8*60, 0.05d), //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, //
- new DoseSettings(10d, 60, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
+ new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
0.04d, 0.01d, null, PumpCapability.DanaCapabilities),
DanaRKorean("DanaR Korean", 0.05d, null, //
- new DoseSettings(0.05d, 30, 8*60, 0.05d), //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, //
- new DoseSettings(10d, 60, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
+ new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
0.1d, 0.01d, null, PumpCapability.DanaCapabilities),
DanaRS("DanaRS", 0.05d, null, //
- new DoseSettings(0.05d, 30, 8*60, 0.05d), //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, //
- new DoseSettings(10d, 60, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.04d, 0.01d, null, PumpCapability.DanaWithHistoryCapabilities),
DanaRv2("DanaRv2", DanaRS),
@@ -91,40 +91,40 @@ public enum PumpType {
// Insulet
Insulet_Omnipod("Insulet Omnipod", 0.05d, null, //
- new DoseSettings(0.05d, 30, 8*60, 0.05d), //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
- new DoseSettings(0.05d, 30, 12*60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr
+ new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities),
// Medtronic
Medtronic_512_712("Medtronic 512/712", 0.05d, null, //
- new DoseSettings(0.05d, 30, 8*60, 0.05d), //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
- new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
+ new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), // TODO
Medtronic_515_715("Medtronic 515/715", Medtronic_512_712),
Medtronic_522_722("Medtronic 522/722", Medtronic_512_712),
Medtronic_523_723_Revel("Medtronic 523/723 (Revel)", 0.05d, null, //
- new DoseSettings(0.05d, 30, 8*60, 0.05d), //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
- new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
+ new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
Medtronic_554_754_Veo("Medtronic 554/754 (Veo)", Medtronic_523_723_Revel), // TODO
Medtronic_640G("Medtronic 640G", 0.025d, null, //
- new DoseSettings(0.05d, 30, 8*60, 0.05d), //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
- new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
+ new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
// Tandem
TandemTSlim("Tandem t:slim", 0.01d, null, //
- new DoseSettings(0.01d,15, 8*60, 0.4d),
+ new DoseSettings(0.01d, 15, 8 * 60, 0.4d),
PumpTempBasalType.Percent,
- new DoseSettings(1,15, 8*60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ new DoseSettings(1, 15, 8 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.1d, 0.001d, null, PumpCapability.VirtualPumpCapabilities),
TandemTFlex("Tandem t:flex", TandemTSlim), //
@@ -146,10 +146,9 @@ public enum PumpType {
private PumpCapability pumpCapability;
private PumpType parent;
- private static Map
" + MainApp.gs(R.string.bolus) + ": " + "" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + ""
+ if (carbs > 0)
+ confirmMessage += "
" + MainApp.gs(R.string.carbs) + ": " + "" + carbs + "g" + ""
+
+ if (Math.abs(insulinAfterConstraints - calculatedTotalInsulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) {
+ confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintapplied) + ""
+ }
+
+ return confirmMessage
+ }
+
+ fun confirmAndExecute(context: Context) {
+ val profile = ProfileFunctions.getInstance().profile
+ val pump = ConfigBuilderPlugin.getPlugin().activePump
+
+ if (pump != null && profile != null && (calculatedTotalInsulin > 0.0 || carbs > 0.0)) {
+ val confirmMessage = confirmMessageAfterConstraints(pump)
+
+ val builder = AlertDialog.Builder(context)
+ builder.setTitle(MainApp.gs(R.string.confirmation))
+ builder.setMessage(Html.fromHtml(confirmMessage))
+ builder.setPositiveButton(MainApp.gs(R.string.ok)) { _, _ ->
+ synchronized(builder) {
+ if (accepted) {
+ log.debug("guarding: already accepted")
+ return@setPositiveButton
+ }
+ accepted = true
+ if (insulinAfterConstraints > 0 || carbs > 0) {
+ if (useSuperBolus) {
+ val loopPlugin = LoopPlugin.getPlugin()
+ if (loopPlugin.isEnabled(PluginType.LOOP)) {
+ loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000)
+ MainApp.bus().post(EventRefreshOverview("WizardDialog"))
+ }
+
+ val pump1 = ConfigBuilderPlugin.getPlugin().activePump
+
+ if (pump1.pumpDescription.tempBasalStyle == PumpDescription.ABSOLUTE) {
+ ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(0.0, 120, true, profile, object : Callback() {
+ override fun run() {
+ if (!result.success) {
+ val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
+ i.putExtra("soundid", R.raw.boluserror)
+ i.putExtra("status", result.comment)
+ i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror))
+ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ MainApp.instance().startActivity(i)
+ }
+ }
+ })
+ } else {
+
+ ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalPercent(0, 120, true, profile, object : Callback() {
+ override fun run() {
+ if (!result.success) {
+ val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
+ i.putExtra("soundid", R.raw.boluserror)
+ i.putExtra("status", result.comment)
+ i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror))
+ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ MainApp.instance().startActivity(i)
+ }
+ }
+ })
+ }
+ }
+ val detailedBolusInfo = DetailedBolusInfo()
+ detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD
+ detailedBolusInfo.insulin = insulinAfterConstraints
+ detailedBolusInfo.carbs = carbs.toDouble()
+ detailedBolusInfo.context = context
+ detailedBolusInfo.glucose = bg
+ detailedBolusInfo.glucoseType = "Manual"
+ detailedBolusInfo.carbTime = carbTime
+ detailedBolusInfo.boluscalc = nsJSON()
+ detailedBolusInfo.source = Source.USER
+ detailedBolusInfo.notes = notes
+ if (detailedBolusInfo.insulin > 0 || ConfigBuilderPlugin.getPlugin().activePump.pumpDescription.storesCarbInfo) {
+ ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
+ override fun run() {
+ if (!result.success) {
+ val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
+ i.putExtra("soundid", R.raw.boluserror)
+ i.putExtra("status", result.comment)
+ i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror))
+ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ MainApp.instance().startActivity(i)
+ }
+ }
+ })
+ } else {
+ TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false)
+ }
+ }
+ }
+ }
+ builder.setNegativeButton(MainApp.gs(R.string.cancel), null)
+ builder.show()
+ }
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java b/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java
index cad2b76291..d089d213d4 100644
--- a/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java
+++ b/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java
@@ -1,5 +1,8 @@
package info.nightscout.androidaps.utils;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+
/**
* class contains useful String functions
*/
@@ -17,4 +20,8 @@ public class StringUtils {
return string;
}
+
+ public static String formatInsulin(double insulin) {
+ return String.format(MainApp.gs(R.string.formatinsulinunits), insulin);
+ }
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9620b64a50..f807d67cab 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1334,6 +1334,8 @@