From 9baea012253736e3ddaa4a2b8a975a7e84b3a573 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 1 Mar 2018 11:32:00 +0200 Subject: [PATCH] Not everybody's profile & targets are in mg/dl :) --- .../Overview/Dialogs/NewCarbsDialog.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java index 15e93816bd..a2e3cd1c56 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java @@ -36,6 +36,7 @@ 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.Profile; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; @@ -69,7 +70,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D private static final double FAV1_DEFAULT = 5; private static final double FAV2_DEFAULT = 10; private static final double FAV3_DEFAULT = 20; - + final double tempTargetValue = 140d; private CheckBox suspendLoopCheckbox; private CheckBox startActivityTTCheckbox; @@ -237,9 +238,22 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D double prefTTDuration = SP.getDouble(R.string.key_activity_duration, 90d); double ttDuration = prefTTDuration > 0 ? prefTTDuration : 90d; double prefTT = SP.getDouble(R.string.key_activity_target, 140d); - double tt = prefTT > 0 ? prefTT : 140d; + double tt = 140d; + Profile currentProfile = MainApp.getConfigBuilder().getProfile(); + if(currentProfile.equals(null)) + return; + if(currentProfile.getUnits().equals("mmol")) { + tt = prefTT > 0 ? prefTT*18 : 140d; + } else + tt = prefTT > 0 ? prefTT : 140d; + + final double finalTT = tt; if (startActivityTTCheckbox.isChecked()) { - confirmMessage += "
" + "TT: " + "" + ((int) tt) + "mg/dl for " + ((int) ttDuration) + " min "; + if(currentProfile.getUnits().equals("mmol")) { + confirmMessage += "
" + "TT: " + "" + finalTT + " mmol/l for " + ((int) ttDuration) + " min "; + } else + confirmMessage += "
" + "TT: " + "" + ((int) finalTT) + " mg/dl for " + ((int) ttDuration) + " min "; + } if (StringUtils.isNoneEmpty(food)) { @@ -286,8 +300,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D tempTarget.durationInMinutes = (int) ttDuration; tempTarget.reason = "Activity"; tempTarget.source = Source.USER; - tempTarget.low = (int) tt; - tempTarget.high = (int) tt; + tempTarget.low = (double) finalTT; + tempTarget.high = (double) finalTT; MainApp.getDbHelper().createOrUpdate(tempTarget); } @@ -326,4 +340,4 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D eventTime.setSeconds(second); timeButton.setText(DateUtil.timeString(eventTime)); } -} \ No newline at end of file +}