fix rounding in dialogs

This commit is contained in:
Milos Kozak 2018-09-12 14:58:47 +02:00
parent f51de7da81
commit bbb6c5f3cc
3 changed files with 23 additions and 19 deletions

View file

@ -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<String> actions = new LinkedList<>();
if (insulin > 0) {
actions.add(MainApp.gs(R.string.bolus) + ": " + "<font color='" + MainApp.gc(R.color.bolus) + "'>" + DecimalFormatter.to2Decimal(insulinAfterConstraints) + "U" + "</font>");
actions.add(MainApp.gs(R.string.bolus) + ": " + "<font color='" + MainApp.gc(R.color.bolus) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + "</font>");
if (recordOnlyCheckbox.isChecked()) {
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusrecordedonly) + "</font>");
}
}
if (Math.abs(insulinAfterConstraints - insulin) > 0.01d)
if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints))
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>");
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));
}

View file

@ -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) + ": " + "<font color='" + MainApp.gc(R.color.colorCarbsButton) + "'>" + insulinAfterConstraints + "U" + "</font>";
confirmMessage += MainApp.gs(R.string.bolus) + ": " + "<font color='" + MainApp.gc(R.color.bolus) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + "</font>";
if (recordOnlyCheckbox.isChecked()) {
confirmMessage += "<br/><font color='" + MainApp.gc(R.color.low) + "'>" + MainApp.gs(R.string.bolusrecordedonly) + "</font>";
confirmMessage += "<br/><font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusrecordedonly) + "</font>";
}
if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints) || !Objects.equals(carbsAfterConstraints, carbs))
confirmMessage += "<br/><font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>";
}
if (carbsAfterConstraints > 0)
confirmMessage += "<br/>" + MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
if (Math.abs(insulinAfterConstraints - insulin) > 0.01d || !Objects.equals(carbsAfterConstraints, carbs))
confirmMessage += "<br/>" + MainApp.gs(R.string.constraintapllied);
confirmMessage += "<br/>" + MainApp.gs(R.string.carbs) + ": " + "<font color='" + MainApp.gc(R.color.carbs) + "'>" + carbsAfterConstraints + "g" + "</font>";
final double finalInsulinAfterConstraints = insulinAfterConstraints;

View file

@ -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 += "<br/>" + MainApp.gs(R.string.carbs) + ": " + "<font color='" + MainApp.gc(R.color.carbs) + "'>" + carbsAfterConstraints + "g" + "</font>";
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 += "<br/><font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>";
}
final Double finalInsulinAfterConstraints = insulinAfterConstraints;