From bbb6c5f3cc12b818d7057a634ac3957ed7b4f72f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 12 Sep 2018 14:58:47 +0200 Subject: [PATCH] fix rounding in dialogs --- .../Overview/Dialogs/NewInsulinDialog.java | 11 +++++++---- .../Overview/Dialogs/NewTreatmentDialog.java | 16 +++++++++++----- .../plugins/Overview/Dialogs/WizardDialog.java | 15 +++++---------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java index 6040680aaf..942fde95fb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java @@ -39,6 +39,7 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; @@ -49,6 +50,7 @@ import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.NumberPicker; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; +import info.nightscout.utils.T; import info.nightscout.utils.ToastUtils; import static info.nightscout.utils.DateUtil.now; @@ -210,7 +212,8 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener try { Profile currentProfile = ProfileFunctions.getInstance().getProfile(); - if (currentProfile == null) + final PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); + if (currentProfile == null || pump == null) return; Double insulin = SafeParse.stringToDouble(editInsulin.getText()); @@ -218,13 +221,13 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener List actions = new LinkedList<>(); if (insulin > 0) { - actions.add(MainApp.gs(R.string.bolus) + ": " + "" + DecimalFormatter.to2Decimal(insulinAfterConstraints) + "U" + ""); + actions.add(MainApp.gs(R.string.bolus) + ": " + "" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + ""); if (recordOnlyCheckbox.isChecked()) { actions.add("" + MainApp.gs(R.string.bolusrecordedonly) + ""); } } - if (Math.abs(insulinAfterConstraints - insulin) > 0.01d) + if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints)) actions.add("" + MainApp.gs(R.string.bolusconstraintapplied) + ""); int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration); @@ -240,7 +243,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener } int timeOffset = editTime.getValue().intValue(); - final long time = now() + timeOffset * 1000 * 60; + final long time = now() + T.mins(timeOffset).msecs(); if (timeOffset != 0) { actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(time)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index eac1a5c09e..df85279592 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -31,6 +31,7 @@ import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; @@ -125,6 +126,11 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene okClicked = true; try { + final PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); + + if (pump == null) + return; + Double insulin = SafeParse.stringToDouble(editInsulin.getText()); final Integer carbs = SafeParse.stringToInt(editCarbs.getText()); @@ -134,15 +140,15 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value(); if (insulin > 0) { - confirmMessage += MainApp.gs(R.string.bolus) + ": " + "" + insulinAfterConstraints + "U" + ""; + confirmMessage += MainApp.gs(R.string.bolus) + ": " + "" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + ""; if (recordOnlyCheckbox.isChecked()) { - confirmMessage += "
" + MainApp.gs(R.string.bolusrecordedonly) + ""; + confirmMessage += "
" + MainApp.gs(R.string.bolusrecordedonly) + ""; } + if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints) || !Objects.equals(carbsAfterConstraints, carbs)) + confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintapplied) + ""; } if (carbsAfterConstraints > 0) - confirmMessage += "
" + MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g"; - if (Math.abs(insulinAfterConstraints - insulin) > 0.01d || !Objects.equals(carbsAfterConstraints, carbs)) - confirmMessage += "
" + MainApp.gs(R.string.constraintapllied); + confirmMessage += "
" + MainApp.gs(R.string.carbs) + ": " + "" + carbsAfterConstraints + "g" + ""; final double finalInsulinAfterConstraints = insulinAfterConstraints; 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 91c9077f66..ceee689f93 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 @@ -55,6 +55,7 @@ import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; @@ -164,7 +165,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } - @Subscribe public void onStatusEvent(final EventNewBG e) { Activity activity = getActivity(); @@ -327,8 +327,9 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } okClicked = true; final Profile profile = ProfileFunctions.getInstance().getProfile(); + final PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); - if (profile != null && (calculatedTotalInsulin > 0d || calculatedCarbs > 0d)) { + 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(); @@ -339,14 +340,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com if (carbsAfterConstraints > 0) confirmMessage += "
" + MainApp.gs(R.string.carbs) + ": " + "" + carbsAfterConstraints + "g" + ""; - if (Math.abs(insulinAfterConstraints - calculatedTotalInsulin) > 0.01d || !carbsAfterConstraints.equals(calculatedCarbs)) { - okClicked = false; - AlertDialog.Builder builder = new AlertDialog.Builder(context); - 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(); - return; + if (Math.abs(insulinAfterConstraints - calculatedTotalInsulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints) || !carbsAfterConstraints.equals(calculatedCarbs)) { + confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintapplied) + ""; } final Double finalInsulinAfterConstraints = insulinAfterConstraints;