diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 75e830e654..f45e57cfbe 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -666,8 +666,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TempTarget tempTarget = new TempTarget() .date(trJson.getLong("mills")) .duration(trJson.getInt("duration")) - .low(Profile.toMgdl(trJson.getDouble("targetBottom"), units)) - .high(Profile.toMgdl(trJson.getDouble("targetTop"), units)) + .low(trJson.getDouble("targetBottom")) + .high(trJson.getDouble("targetTop")) .reason(trJson.getString("reason")) ._id(trJson.getString("_id")) .source(Source.NIGHTSCOUT); 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 d7cb428312..3539bee093 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 @@ -59,7 +59,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener public static final double PLUS2_DEFAULT = 1d; public static final double PLUS3_DEFAULT = 2d; - private CheckBox startESMCheckbox; + private CheckBox startEatingSoonTTCheckbox; private CheckBox recordOnlyCheckbox; private LinearLayout editLayout; @@ -117,7 +117,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - startESMCheckbox = view.findViewById(R.id.newinsulin_start_eating_soon_tt); + startEatingSoonTTCheckbox = view.findViewById(R.id.newinsulin_start_eating_soon_tt); recordOnlyCheckbox = view.findViewById(R.id.newinsulin_record_only); recordOnlyCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> editLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE)); @@ -192,6 +192,10 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener okClicked = true; try { + Profile currentProfile = MainApp.getConfigBuilder().getProfile(); + if (currentProfile == null) + return; + Double insulin = SafeParse.stringToDouble(editInsulin.getText()); Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(insulin)).value(); @@ -206,24 +210,16 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener if (!insulinAfterConstraints.equals(insulin)) actions.add("" + MainApp.gs(R.string.bolusconstraintapplied) + ""); - double prefTTDuration = SP.getDouble(R.string.key_eatingsoon_duration, 45d); - double ttDuration = prefTTDuration > 0 ? prefTTDuration : 45d; - double prefTT = SP.getDouble(R.string.key_eatingsoon_target, 80d); - Profile currentProfile = MainApp.getConfigBuilder().getProfile(); - if (currentProfile == null) - return; - double tt; - if (currentProfile.getUnits().equals(Constants.MMOL)) - tt = prefTT > 0 ? Profile.toMgdl(prefTT, Constants.MMOL) : 80d; - else - tt = prefTT > 0 ? prefTT : 80d; - final double finalTT = tt; + int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration); + eatingSoonTTDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : Constants.defaultEatingSoonTTDuration; + double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl); + eatingSoonTT = eatingSoonTT > 0 ? eatingSoonTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl; - if (startESMCheckbox.isChecked()) { + if (startEatingSoonTTCheckbox.isChecked()) { if (currentProfile.getUnits().equals(Constants.MMOL)) { - actions.add("TT: " + "" + Profile.toMmol(tt, Constants.MGDL) + " mmol for " + ((int) ttDuration) + " min "); + actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(eatingSoonTT) + " mmol/l (" + eatingSoonTTDuration + " min)"); } else - actions.add("TT: " + "" + ((int) tt) + "mg/dl for " + ((int) ttDuration) + " min "); + actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to0Decimal(eatingSoonTT) + " mg/dl (" + eatingSoonTTDuration + " min)"); } int timeOffset = editTime.getValue().intValue(); @@ -237,12 +233,14 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener } final double finalInsulinAfterConstraints = insulinAfterConstraints; + final double finalEatigSoonTT = eatingSoonTT; + final int finalEatingSoonTTDuration = eatingSoonTTDuration; final Context context = getContext(); final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(MainApp.gs(R.string.confirmation)); - if (finalInsulinAfterConstraints > 0 || startESMCheckbox.isChecked()) { + if (finalInsulinAfterConstraints > 0 || startEatingSoonTTCheckbox.isChecked()) { builder.setMessage(Html.fromHtml(Joiner.on("
").join(actions))); builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> { synchronized (builder) { @@ -252,14 +250,14 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener } accepted = true; - if (startESMCheckbox.isChecked()) { + if (startEatingSoonTTCheckbox.isChecked()) { TempTarget tempTarget = new TempTarget() .date(System.currentTimeMillis()) - .duration((int) ttDuration) - .reason("Eating soon") + .duration(finalEatingSoonTTDuration) + .reason(MainApp.gs(R.string.eatingsoon)) .source(Source.USER) - .low(Profile.toMgdl(finalTT, currentProfile.getUnits())) - .high(Profile.toMgdl(finalTT, currentProfile.getUnits())); + .low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())) + .high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())); TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); }