From 9baea012253736e3ddaa4a2b8a975a7e84b3a573 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 1 Mar 2018 11:32:00 +0200 Subject: [PATCH 01/23] 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 +} From 7ca1fdc36ed3fe3d23baf507a9e4ca5f6b118050 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 1 Mar 2018 11:54:24 +0200 Subject: [PATCH 02/23] removed unused var --- .../androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java | 1 - 1 file changed, 1 deletion(-) 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 a2e3cd1c56..43d7069e30 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 @@ -70,7 +70,6 @@ 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; From 5b003c62e2ce09f6887cc9e2e97db97f3a68431a Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 1 Mar 2018 14:07:35 +0200 Subject: [PATCH 03/23] added fix for mmol profiles & targets --- .../Overview/Dialogs/NewInsulinDialog.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 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 7c86cde764..dcb457aa35 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 @@ -246,8 +246,19 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, double ttDuration = prefTTDuration > 0 ? prefTTDuration : 45d; double prefTT = SP.getDouble(R.string.key_eatingsoon_target, 80d); double tt = prefTT > 0 ? prefTT : 80d; + Profile currentProfile = MainApp.getConfigBuilder().getProfile(); + if(currentProfile.equals(null)) + return; + if(currentProfile.getUnits().equals("mmol")) { + tt = prefTT > 0 ? prefTT*18 : 80d; + } else + tt = prefTT > 0 ? prefTT : 80d; + final double finalTT = tt; if (startESMCheckbox.isChecked()) { - confirmMessage += "
" + "TT: " + "" + ((int) tt) + "mg/dl for " + ((int) ttDuration) + " min "; + if(currentProfile.getUnits().equals("mmol")){ + confirmMessage += "
" + "TT: " + "" + tt/18 + "mmol for " + ((int) ttDuration) + " min "; + } else + confirmMessage += "
" + "TT: " + "" + ((int) tt) + "mg/dl for " + ((int) ttDuration) + " min "; } if (!initialEventTime.equals(eventTime)) { @@ -277,8 +288,8 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, tempTarget.durationInMinutes = (int) ttDuration; tempTarget.reason = "Eating soon"; tempTarget.source = Source.USER; - tempTarget.low = (int) tt; - tempTarget.high = (int) tt; + tempTarget.low = (int) finalTT; + tempTarget.high = (int) finalTT; MainApp.getDbHelper().createOrUpdate(tempTarget); } @@ -339,4 +350,4 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, eventTime.setSeconds(second); timeButton.setText(DateUtil.timeString(eventTime)); } -} \ No newline at end of file +} From d3a7176209f8edc0f0fe3beb9944f9b4cab5efab Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 1 Mar 2018 15:20:00 +0200 Subject: [PATCH 04/23] Update MainApp.java --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index bfa801cbdb..412383c6e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -139,7 +139,7 @@ public class MainApp extends Application { if (Config.DANAR) pluginsList.add(DanaRv2Plugin.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRSPlugin.getPlugin()); pluginsList.add(CareportalPlugin.getPlugin()); - if (Config.DANAR) pluginsList.add(InsightPumpPlugin.getPlugin()); + // if (Config.DANAR) pluginsList.add(InsightPumpPlugin.getPlugin()); // <-- Enable Insight plugin here if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getPlugin()); if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); From 9456a246557661635b40e34f4fb180929cc3dafc Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 1 Mar 2018 16:22:05 +0200 Subject: [PATCH 05/23] Adding Eating soon mode to options --- app/src/main/res/layout/overview_newcarbs_dialog.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/overview_newcarbs_dialog.xml b/app/src/main/res/layout/overview_newcarbs_dialog.xml index 67f62e8cf2..7f00891e40 100644 --- a/app/src/main/res/layout/overview_newcarbs_dialog.xml +++ b/app/src/main/res/layout/overview_newcarbs_dialog.xml @@ -39,6 +39,13 @@ android:layout_marginTop="5dp" android:text="Start activity TT"/> + + - \ No newline at end of file + From 38933ac323babe07e692b87d39cb290334984c58 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 1 Mar 2018 16:27:52 +0200 Subject: [PATCH 06/23] Adding Eating soon TT check to carbs I use that a lot for meal anouncement only --- .../Overview/Dialogs/NewCarbsDialog.java | 37 ++++++++++++++++--- 1 file changed, 31 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 43d7069e30..eb56c8b086 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 @@ -72,6 +72,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D private static final double FAV3_DEFAULT = 20; private CheckBox suspendLoopCheckbox; private CheckBox startActivityTTCheckbox; + private CheckBox ESMCheckbox; private Integer maxCarbs; @@ -127,6 +128,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); startActivityTTCheckbox = view.findViewById(R.id.newcarbs_activity_tt); + ESMCheckbox = view.findViewById(R.id.carbs_eating_soon_tt); dateButton = view.findViewById(R.id.newcarbs_eventdate); timeButton = view.findViewById(R.id.newcarb_eventtime); @@ -235,26 +237,40 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D } double prefTTDuration = SP.getDouble(R.string.key_activity_duration, 90d); + double eatingSoonTTDuration = SP.getDouble(R.string.key_eatingsoon_duration, 45d); + double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, 90d); double ttDuration = prefTTDuration > 0 ? prefTTDuration : 90d; + final double esDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : 45d; double prefTT = SP.getDouble(R.string.key_activity_target, 140d); + double tt = 140d; + double esTT = 90d; Profile currentProfile = MainApp.getConfigBuilder().getProfile(); if(currentProfile.equals(null)) return; if(currentProfile.getUnits().equals("mmol")) { + esTT = eatingSoonTT > 0 ? eatingSoonTT*18 : 90d; tt = prefTT > 0 ? prefTT*18 : 140d; } else + esTT = eatingSoonTT > 0 ? eatingSoonTT : 90d; tt = prefTT > 0 ? prefTT : 140d; - final double finalTT = tt; - if (startActivityTTCheckbox.isChecked()) { + + if (startActivityTTCheckbox.isChecked() ||(startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked()) ) { if(currentProfile.getUnits().equals("mmol")) { - confirmMessage += "
" + "TT: " + "" + finalTT + " mmol/l for " + ((int) ttDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + tt/18 + " mmol/l for " + ((int) ttDuration) + " min "; } else - confirmMessage += "
" + "TT: " + "" + ((int) finalTT) + " mg/dl for " + ((int) ttDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + ((int) tt) + " mg/dl for " + ((int) ttDuration) + " min "; + + }else if (ESMCheckbox.isChecked()) { + if(currentProfile.getUnits().equals("mmol")) { + confirmMessage += "
" + "TT: " + "" + esTT/18 + " mmol/l for " + ((int) esDuration) + " min "; + } else + confirmMessage += "
" + "TT: " + "" + ((int) esTT) + " mg/dl for " + ((int) esDuration) + " min "; } - + final double finalTT = tt; + final double finalEsTT = esTT; if (StringUtils.isNoneEmpty(food)) { confirmMessage += "
" + "Food: " + food; } @@ -293,7 +309,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D }); } - if (startActivityTTCheckbox.isChecked()) { + if (startActivityTTCheckbox.isChecked() || (startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked())) { TempTarget tempTarget = new TempTarget(); tempTarget.date = System.currentTimeMillis(); tempTarget.durationInMinutes = (int) ttDuration; @@ -302,6 +318,15 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D tempTarget.low = (double) finalTT; tempTarget.high = (double) finalTT; MainApp.getDbHelper().createOrUpdate(tempTarget); + } else if (ESMCheckbox.isChecked()) { + TempTarget tempTarget = new TempTarget(); + tempTarget.date = System.currentTimeMillis(); + tempTarget.durationInMinutes = (int) esDuration; + tempTarget.reason = "Eating soon"; + tempTarget.source = Source.USER; + tempTarget.low = (double) finalEsTT; + tempTarget.high = (double) finalEsTT; + MainApp.getDbHelper().createOrUpdate(tempTarget); } if (finalCarbsAfterConstraints > 0 || food != null) { From bea486d81693a2e5402b17b53695281fc846c4d9 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 1 Mar 2018 16:57:36 +0200 Subject: [PATCH 07/23] Don't show confirmation on empty message/input --- .../Overview/Dialogs/NewCarbsDialog.java | 119 +++++++++--------- 1 file changed, 62 insertions(+), 57 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 eb56c8b086..1d028bf051 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 @@ -278,75 +278,80 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D if (!initialEventTime.equals(eventTime)) { confirmMessage += "
Time: " + DateUtil.dateAndTimeString(eventTime); } + if(confirmMessage.length() > 0) { - final int finalCarbsAfterConstraints = carbsAfterConstraints; + final int finalCarbsAfterConstraints = carbsAfterConstraints; - final Context context = getContext(); - final AlertDialog.Builder builder = new AlertDialog.Builder(context); + final Context context = getContext(); + final AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(this.getContext().getString(R.string.confirmation)); - if (confirmMessage.startsWith("
")) - confirmMessage = confirmMessage.substring("
".length()); - builder.setMessage(Html.fromHtml(confirmMessage)); - builder.setPositiveButton(getString(R.string.ok), (dialog, id) -> { - synchronized (builder) { - if (accepted) { - log.debug("guarding: already accepted"); - return; - } - accepted = true; + builder.setTitle(this.getContext().getString(R.string.confirmation)); + if (confirmMessage.startsWith("
")) + confirmMessage = confirmMessage.substring("
".length()); - if (suspendLoopCheckbox.isChecked()) { - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - activeloop.suspendTo(System.currentTimeMillis() + 30L * 60 * 1000); - ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { - @Override - public void run() { - if (!result.success) { - ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); + builder.setMessage(Html.fromHtml(confirmMessage)); + builder.setPositiveButton(getString(R.string.ok), (dialog, id) -> { + synchronized (builder) { + if (accepted) { + log.debug("guarding: already accepted"); + return; + } + accepted = true; + + if (suspendLoopCheckbox.isChecked()) { + final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); + activeloop.suspendTo(System.currentTimeMillis() + 30L * 60 * 1000); + ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { + @Override + public void run() { + if (!result.success) { + ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); + } } - } - }); - } + }); + } - if (startActivityTTCheckbox.isChecked() || (startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked())) { - TempTarget tempTarget = new TempTarget(); - tempTarget.date = System.currentTimeMillis(); - tempTarget.durationInMinutes = (int) ttDuration; - tempTarget.reason = "Activity"; - tempTarget.source = Source.USER; - tempTarget.low = (double) finalTT; - tempTarget.high = (double) finalTT; - MainApp.getDbHelper().createOrUpdate(tempTarget); - } else if (ESMCheckbox.isChecked()) { - TempTarget tempTarget = new TempTarget(); - tempTarget.date = System.currentTimeMillis(); - tempTarget.durationInMinutes = (int) esDuration; - tempTarget.reason = "Eating soon"; - tempTarget.source = Source.USER; - tempTarget.low = (double) finalEsTT; - tempTarget.high = (double) finalEsTT; - MainApp.getDbHelper().createOrUpdate(tempTarget); - } + if (startActivityTTCheckbox.isChecked() || (startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked())) { + TempTarget tempTarget = new TempTarget(); + tempTarget.date = System.currentTimeMillis(); + tempTarget.durationInMinutes = (int) ttDuration; + tempTarget.reason = "Activity"; + tempTarget.source = Source.USER; + tempTarget.low = (double) finalTT; + tempTarget.high = (double) finalTT; + MainApp.getDbHelper().createOrUpdate(tempTarget); + } else if (ESMCheckbox.isChecked()) { + TempTarget tempTarget = new TempTarget(); + tempTarget.date = System.currentTimeMillis(); + tempTarget.durationInMinutes = (int) esDuration; + tempTarget.reason = "Eating soon"; + tempTarget.source = Source.USER; + tempTarget.low = (double) finalEsTT; + tempTarget.high = (double) finalEsTT; + MainApp.getDbHelper().createOrUpdate(tempTarget); + } - if (finalCarbsAfterConstraints > 0 || food != null) { - DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - detailedBolusInfo.date = eventTime.getTime(); - detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION; - detailedBolusInfo.carbs = finalCarbsAfterConstraints; + if (finalCarbsAfterConstraints > 0 || food != null) { + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + detailedBolusInfo.date = eventTime.getTime(); + detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION; + detailedBolusInfo.carbs = finalCarbsAfterConstraints; // detailedBolusInfo.food = food; - detailedBolusInfo.context = context; - detailedBolusInfo.source = Source.USER; - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + detailedBolusInfo.context = context; + detailedBolusInfo.source = Source.USER; + MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + } } - } - }); - builder.setNegativeButton(getString(R.string.cancel), null); - builder.show(); - dismiss(); + }); + builder.setNegativeButton(getString(R.string.cancel), null); + builder.show(); + dismiss(); + } else + dismiss(); } catch (Exception e) { log.error("Unhandled exception", e); } + } @Override From 65ddf5ced5a52db150da688ba1a65c84bbcd197c Mon Sep 17 00:00:00 2001 From: PoweRGbg Date: Thu, 1 Mar 2018 18:31:29 +0200 Subject: [PATCH 08/23] format using the Profile class method and Constants --- .../plugins/Overview/Dialogs/NewInsulinDialog.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 dcb457aa35..3c57346c39 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 @@ -249,14 +249,14 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, Profile currentProfile = MainApp.getConfigBuilder().getProfile(); if(currentProfile.equals(null)) return; - if(currentProfile.getUnits().equals("mmol")) { - tt = prefTT > 0 ? prefTT*18 : 80d; + if(currentProfile.getUnits().equals(Constants.MMOL)) { + tt = prefTT > 0 ? Profile.toMgdl(prefTT, Constants.MGDL) : 80d; } else tt = prefTT > 0 ? prefTT : 80d; final double finalTT = tt; if (startESMCheckbox.isChecked()) { if(currentProfile.getUnits().equals("mmol")){ - confirmMessage += "
" + "TT: " + "" + tt/18 + "mmol for " + ((int) ttDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + Profile.toMmol(tt, Constants.MMOL) + "mmol for " + ((int) ttDuration) + " min "; } else confirmMessage += "
" + "TT: " + "" + ((int) tt) + "mg/dl for " + ((int) ttDuration) + " min "; } From c6a46129df7b98fb5da7f1b8e348c8528cd655c3 Mon Sep 17 00:00:00 2001 From: PoweRGbg Date: Thu, 1 Mar 2018 18:38:56 +0200 Subject: [PATCH 09/23] format using the Profile class method and Constants --- .../plugins/Overview/Dialogs/NewCarbsDialog.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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 1d028bf051..1508b003f5 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 @@ -248,23 +248,23 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D Profile currentProfile = MainApp.getConfigBuilder().getProfile(); if(currentProfile.equals(null)) return; - if(currentProfile.getUnits().equals("mmol")) { - esTT = eatingSoonTT > 0 ? eatingSoonTT*18 : 90d; - tt = prefTT > 0 ? prefTT*18 : 140d; + if(currentProfile.getUnits().equals(Constants.MMOL)) { + esTT = eatingSoonTT > 0 ? eatingSoonTT*Constants.MMOLL_TO_MGDL : 90d; + tt = prefTT > 0 ? prefTT*Constants.MMOLL_TO_MGDL : 140d; } else esTT = eatingSoonTT > 0 ? eatingSoonTT : 90d; tt = prefTT > 0 ? prefTT : 140d; if (startActivityTTCheckbox.isChecked() ||(startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked()) ) { - if(currentProfile.getUnits().equals("mmol")) { - confirmMessage += "
" + "TT: " + "" + tt/18 + " mmol/l for " + ((int) ttDuration) + " min "; + if(currentProfile.getUnits().equals(Constants.MMOL)) { + confirmMessage += "
" + "TT: " + "" + Profile.toMmol(tt,Constants.MGDL) + " mmol/l for " + ((int) ttDuration) + " min "; } else confirmMessage += "
" + "TT: " + "" + ((int) tt) + " mg/dl for " + ((int) ttDuration) + " min "; }else if (ESMCheckbox.isChecked()) { - if(currentProfile.getUnits().equals("mmol")) { - confirmMessage += "
" + "TT: " + "" + esTT/18 + " mmol/l for " + ((int) esDuration) + " min "; + if(currentProfile.getUnits().equals(Constants.MMOL)) { + confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT,Constants.MGDL) + " mmol/l for " + ((int) esDuration) + " min "; } else confirmMessage += "
" + "TT: " + "" + ((int) esTT) + " mg/dl for " + ((int) esDuration) + " min "; From 2fb0e6edc19b025d6953fe8c33937716caae504b Mon Sep 17 00:00:00 2001 From: PoweRGbg Date: Thu, 1 Mar 2018 18:40:06 +0200 Subject: [PATCH 10/23] format using the Profile class method and Constants --- .../androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3c57346c39..d9f9dcebfa 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 @@ -256,7 +256,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, final double finalTT = tt; if (startESMCheckbox.isChecked()) { if(currentProfile.getUnits().equals("mmol")){ - confirmMessage += "
" + "TT: " + "" + Profile.toMmol(tt, Constants.MMOL) + "mmol for " + ((int) ttDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + Profile.toMmol(tt, Constants.MGDL) + " mmol for " + ((int) ttDuration) + " min "; } else confirmMessage += "
" + "TT: " + "" + ((int) tt) + "mg/dl for " + ((int) ttDuration) + " min "; } From 3edec79b8d45faa8e3d26ae5382e77b9b7b00386 Mon Sep 17 00:00:00 2001 From: PoweRGbg Date: Thu, 1 Mar 2018 21:41:52 +0200 Subject: [PATCH 11/23] fixing identation and equals() to == --- .../plugins/Overview/Dialogs/NewCarbsDialog.java | 13 +++++++++---- .../plugins/Overview/Dialogs/NewInsulinDialog.java | 8 ++++---- 2 files changed, 13 insertions(+), 8 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 1508b003f5..45b73762c5 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 @@ -18,6 +18,7 @@ import android.view.WindowManager; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; +import android.widget.RadioButton; import android.widget.TextView; import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; @@ -71,8 +72,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D private static final double FAV2_DEFAULT = 10; private static final double FAV3_DEFAULT = 20; private CheckBox suspendLoopCheckbox; - private CheckBox startActivityTTCheckbox; - private CheckBox ESMCheckbox; + private RadioButton startActivityTTCheckbox; + private RadioButton ESMCheckbox; private Integer maxCarbs; @@ -212,6 +213,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D + SP.getDouble(MainApp.gs(R.string.key_carbs_button_increment_3), FAV3_DEFAULT)); validateInputs(); break; + } } @@ -246,7 +248,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D double tt = 140d; double esTT = 90d; Profile currentProfile = MainApp.getConfigBuilder().getProfile(); - if(currentProfile.equals(null)) + if(currentProfile == null) return; if(currentProfile.getUnits().equals(Constants.MMOL)) { esTT = eatingSoonTT > 0 ? eatingSoonTT*Constants.MMOLL_TO_MGDL : 90d; @@ -257,12 +259,15 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D if (startActivityTTCheckbox.isChecked() ||(startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked()) ) { + ESMCheckbox.setChecked(true); if(currentProfile.getUnits().equals(Constants.MMOL)) { confirmMessage += "
" + "TT: " + "" + Profile.toMmol(tt,Constants.MGDL) + " mmol/l for " + ((int) ttDuration) + " min "; } else confirmMessage += "
" + "TT: " + "" + ((int) tt) + " mg/dl for " + ((int) ttDuration) + " min "; - }else if (ESMCheckbox.isChecked()) { + } + if (ESMCheckbox.isChecked()) { + startActivityTTCheckbox.setChecked(true); if(currentProfile.getUnits().equals(Constants.MMOL)) { confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT,Constants.MGDL) + " mmol/l for " + ((int) esDuration) + " min "; } else 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 d9f9dcebfa..356c3a9b3d 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 @@ -247,12 +247,12 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, double prefTT = SP.getDouble(R.string.key_eatingsoon_target, 80d); double tt = prefTT > 0 ? prefTT : 80d; Profile currentProfile = MainApp.getConfigBuilder().getProfile(); - if(currentProfile.equals(null)) + if(currentProfile == null) return; - if(currentProfile.getUnits().equals(Constants.MMOL)) { + if(currentProfile.getUnits().equals(Constants.MMOL)) tt = prefTT > 0 ? Profile.toMgdl(prefTT, Constants.MGDL) : 80d; - } else - tt = prefTT > 0 ? prefTT : 80d; + else + tt = prefTT > 0 ? prefTT : 80d; final double finalTT = tt; if (startESMCheckbox.isChecked()) { if(currentProfile.getUnits().equals("mmol")){ From b3a10b47ce5ffc5bddfc6508a0e12b053daede0b Mon Sep 17 00:00:00 2001 From: PoweRGbg Date: Thu, 1 Mar 2018 21:57:30 +0200 Subject: [PATCH 12/23] undo the RadioButton tests --- .../plugins/Overview/Dialogs/NewCarbsDialog.java | 10 ++++------ 1 file changed, 4 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 45b73762c5..cf9a765617 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 @@ -72,8 +72,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D private static final double FAV2_DEFAULT = 10; private static final double FAV3_DEFAULT = 20; private CheckBox suspendLoopCheckbox; - private RadioButton startActivityTTCheckbox; - private RadioButton ESMCheckbox; + private CheckBox startActivityTTCheckbox; + private CheckBox ESMCheckbox; private Integer maxCarbs; @@ -258,16 +258,14 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D tt = prefTT > 0 ? prefTT : 140d; - if (startActivityTTCheckbox.isChecked() ||(startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked()) ) { - ESMCheckbox.setChecked(true); + if (startActivityTTCheckbox.isChecked()) { if(currentProfile.getUnits().equals(Constants.MMOL)) { confirmMessage += "
" + "TT: " + "" + Profile.toMmol(tt,Constants.MGDL) + " mmol/l for " + ((int) ttDuration) + " min "; } else confirmMessage += "
" + "TT: " + "" + ((int) tt) + " mg/dl for " + ((int) ttDuration) + " min "; } - if (ESMCheckbox.isChecked()) { - startActivityTTCheckbox.setChecked(true); + if (ESMCheckbox.isChecked() && !startActivityTTCheckbox.isChecked()) { if(currentProfile.getUnits().equals(Constants.MMOL)) { confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT,Constants.MGDL) + " mmol/l for " + ((int) esDuration) + " min "; } else From ab3953687660e90a1a0e2cbc00f9fa2ee41bd9cc Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Fri, 2 Mar 2018 10:12:05 +0200 Subject: [PATCH 13/23] Only one TT can be selected --- .../plugins/Overview/Dialogs/NewCarbsDialog.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 cf9a765617..bfcc136ce8 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 @@ -141,6 +141,10 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D dateButton.setOnClickListener(this); timeButton.setOnClickListener(this); + //To be able to select only one TT at a time + ESMCheckbox.setOnClickListener(this); + startActivityTTCheckbox.setOnClickListener(this); + // TODO prefilling carbs, maybe // TODO maybe update suggested carbs to target TT when checked // APSResult lastAPSResult = ConfigBuilderPlugin.getActiveAPS().getLastAPSResult(); @@ -213,6 +217,12 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D + SP.getDouble(MainApp.gs(R.string.key_carbs_button_increment_3), FAV3_DEFAULT)); validateInputs(); break; + case R.id.newcarbs_activity_tt: + ESMCheckbox.setChecked(false); + break; + case R.id.carbs_eating_soon_tt: + startActivityTTCheckbox.setChecked(false); + break; } } From 9dd129bbe66fa61df928fdd048144b54befe1da6 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Fri, 2 Mar 2018 10:37:12 +0200 Subject: [PATCH 14/23] Revert "Update MainApp.java" This reverts commit d3a7176209f8edc0f0fe3beb9944f9b4cab5efab. reverting changess to app/src/main/java/info/nightscout/androidaps/MainApp.java --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 412383c6e1..bfa801cbdb 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -139,7 +139,7 @@ public class MainApp extends Application { if (Config.DANAR) pluginsList.add(DanaRv2Plugin.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRSPlugin.getPlugin()); pluginsList.add(CareportalPlugin.getPlugin()); - // if (Config.DANAR) pluginsList.add(InsightPumpPlugin.getPlugin()); // <-- Enable Insight plugin here + if (Config.DANAR) pluginsList.add(InsightPumpPlugin.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getPlugin()); if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); From f3a12be0bed9a8033678e76f7a0756e79a51be8c Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Fri, 2 Mar 2018 14:53:19 +0200 Subject: [PATCH 15/23] renaming ESMCheckbox to startEsTTCheckbox --- .../plugins/Overview/Dialogs/NewCarbsDialog.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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 bfcc136ce8..cbe6575809 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 @@ -73,7 +73,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D private static final double FAV3_DEFAULT = 20; private CheckBox suspendLoopCheckbox; private CheckBox startActivityTTCheckbox; - private CheckBox ESMCheckbox; + private CheckBox startEsTTCheckbox; private Integer maxCarbs; @@ -129,7 +129,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); startActivityTTCheckbox = view.findViewById(R.id.newcarbs_activity_tt); - ESMCheckbox = view.findViewById(R.id.carbs_eating_soon_tt); + startEsTTCheckbox = view.findViewById(R.id.carbs_eating_soon_tt); dateButton = view.findViewById(R.id.newcarbs_eventdate); timeButton = view.findViewById(R.id.newcarb_eventtime); @@ -142,7 +142,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D timeButton.setOnClickListener(this); //To be able to select only one TT at a time - ESMCheckbox.setOnClickListener(this); + startEsTTCheckbox.setOnClickListener(this); startActivityTTCheckbox.setOnClickListener(this); // TODO prefilling carbs, maybe @@ -218,7 +218,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D validateInputs(); break; case R.id.newcarbs_activity_tt: - ESMCheckbox.setChecked(false); + startEsTTCheckbox.setChecked(false); break; case R.id.carbs_eating_soon_tt: startActivityTTCheckbox.setChecked(false); @@ -275,7 +275,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D confirmMessage += "
" + "TT: " + "" + ((int) tt) + " mg/dl for " + ((int) ttDuration) + " min "; } - if (ESMCheckbox.isChecked() && !startActivityTTCheckbox.isChecked()) { + if (startEsTTCheckbox.isChecked() && !startActivityTTCheckbox.isChecked()) { if(currentProfile.getUnits().equals(Constants.MMOL)) { confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT,Constants.MGDL) + " mmol/l for " + ((int) esDuration) + " min "; } else @@ -324,7 +324,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D }); } - if (startActivityTTCheckbox.isChecked() || (startActivityTTCheckbox.isChecked() && ESMCheckbox.isChecked())) { + if (startActivityTTCheckbox.isChecked() || (startActivityTTCheckbox.isChecked() && startEsTTCheckbox.isChecked())) { TempTarget tempTarget = new TempTarget(); tempTarget.date = System.currentTimeMillis(); tempTarget.durationInMinutes = (int) ttDuration; @@ -333,7 +333,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D tempTarget.low = (double) finalTT; tempTarget.high = (double) finalTT; MainApp.getDbHelper().createOrUpdate(tempTarget); - } else if (ESMCheckbox.isChecked()) { + } else if (startEsTTCheckbox.isChecked()) { TempTarget tempTarget = new TempTarget(); tempTarget.date = System.currentTimeMillis(); tempTarget.durationInMinutes = (int) esDuration; From e923bf21560d354cd69028fe23b46f324ac5eedb Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Fri, 2 Mar 2018 15:09:03 +0200 Subject: [PATCH 16/23] As Adrian asked .... Profile.toMgDl() --- .../plugins/Overview/Dialogs/NewCarbsDialog.java | 12 ++++++------ 1 file changed, 6 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 cbe6575809..d6254fd443 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 @@ -261,12 +261,12 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D if(currentProfile == null) return; if(currentProfile.getUnits().equals(Constants.MMOL)) { - esTT = eatingSoonTT > 0 ? eatingSoonTT*Constants.MMOLL_TO_MGDL : 90d; - tt = prefTT > 0 ? prefTT*Constants.MMOLL_TO_MGDL : 140d; - } else - esTT = eatingSoonTT > 0 ? eatingSoonTT : 90d; - tt = prefTT > 0 ? prefTT : 140d; - + esTT = eatingSoonTT > 0 ? Profile.toMgdl(eatingSoonTT,Constants.MGDL) : 90d; + tt = prefTT > 0 ? Profile.toMgdl(prefTT,Constants.MGDL) : 140d; + } else { + esTT = eatingSoonTT > 0 ? eatingSoonTT : 90d; + tt = prefTT > 0 ? prefTT : 140d; + } if (startActivityTTCheckbox.isChecked()) { if(currentProfile.getUnits().equals(Constants.MMOL)) { From 6c75b1b317bc4b21790b5f507b34c4952be6281d Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Fri, 2 Mar 2018 15:28:32 +0200 Subject: [PATCH 17/23] more readable var names and --- .../Overview/Dialogs/NewCarbsDialog.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 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 d6254fd443..ab0cd8dde0 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 @@ -248,41 +248,41 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D confirmMessage += "
" + "Loop: " + "" + "Suspend for 30 min"; } - double prefTTDuration = SP.getDouble(R.string.key_activity_duration, 90d); + double activityTTDurationSettings = SP.getDouble(R.string.key_activity_duration, 90d); double eatingSoonTTDuration = SP.getDouble(R.string.key_eatingsoon_duration, 45d); double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, 90d); - double ttDuration = prefTTDuration > 0 ? prefTTDuration : 90d; - final double esDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : 45d; + double activityTTDuration = activityTTDurationSettings > 0 ? activityTTDurationSettings : 90d; + final double esTTDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : 45d; double prefTT = SP.getDouble(R.string.key_activity_target, 140d); - double tt = 140d; + double activityTT = 140d; double esTT = 90d; Profile currentProfile = MainApp.getConfigBuilder().getProfile(); if(currentProfile == null) return; if(currentProfile.getUnits().equals(Constants.MMOL)) { esTT = eatingSoonTT > 0 ? Profile.toMgdl(eatingSoonTT,Constants.MGDL) : 90d; - tt = prefTT > 0 ? Profile.toMgdl(prefTT,Constants.MGDL) : 140d; + activityTT = prefTT > 0 ? Profile.toMgdl(prefTT,Constants.MGDL) : 140d; } else { esTT = eatingSoonTT > 0 ? eatingSoonTT : 90d; - tt = prefTT > 0 ? prefTT : 140d; + activityTT = prefTT > 0 ? prefTT : 140d; } if (startActivityTTCheckbox.isChecked()) { if(currentProfile.getUnits().equals(Constants.MMOL)) { - confirmMessage += "
" + "TT: " + "" + Profile.toMmol(tt,Constants.MGDL) + " mmol/l for " + ((int) ttDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + Profile.toMmol(activityTT,Constants.MGDL) + " mmol/l for " + ((int) activityTTDuration) + " min "; } else - confirmMessage += "
" + "TT: " + "" + ((int) tt) + " mg/dl for " + ((int) ttDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + ((int) activityTT) + " mg/dl for " + ((int) activityTTDuration) + " min "; } if (startEsTTCheckbox.isChecked() && !startActivityTTCheckbox.isChecked()) { if(currentProfile.getUnits().equals(Constants.MMOL)) { - confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT,Constants.MGDL) + " mmol/l for " + ((int) esDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT,Constants.MGDL) + " mmol/l for " + ((int) esTTDuration) + " min "; } else - confirmMessage += "
" + "TT: " + "" + ((int) esTT) + " mg/dl for " + ((int) esDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + ((int) esTT) + " mg/dl for " + ((int) esTTDuration) + " min "; } - final double finalTT = tt; + final double finalTT = activityTT; final double finalEsTT = esTT; if (StringUtils.isNoneEmpty(food)) { confirmMessage += "
" + "Food: " + food; @@ -327,7 +327,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D if (startActivityTTCheckbox.isChecked() || (startActivityTTCheckbox.isChecked() && startEsTTCheckbox.isChecked())) { TempTarget tempTarget = new TempTarget(); tempTarget.date = System.currentTimeMillis(); - tempTarget.durationInMinutes = (int) ttDuration; + tempTarget.durationInMinutes = (int) activityTTDuration; tempTarget.reason = "Activity"; tempTarget.source = Source.USER; tempTarget.low = (double) finalTT; @@ -336,7 +336,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D } else if (startEsTTCheckbox.isChecked()) { TempTarget tempTarget = new TempTarget(); tempTarget.date = System.currentTimeMillis(); - tempTarget.durationInMinutes = (int) esDuration; + tempTarget.durationInMinutes = (int) esTTDuration; tempTarget.reason = "Eating soon"; tempTarget.source = Source.USER; tempTarget.low = (double) finalEsTT; From ea29b6ad82ca68e6d2b44b29b36040e2dbbf58c7 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Fri, 2 Mar 2018 16:33:53 +0200 Subject: [PATCH 18/23] propper conversion from MMOL to MgDl --- .../androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java | 4 ++-- .../androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java | 2 +- 2 files changed, 3 insertions(+), 3 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 ab0cd8dde0..5e2a811dbb 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 @@ -261,8 +261,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D if(currentProfile == null) return; if(currentProfile.getUnits().equals(Constants.MMOL)) { - esTT = eatingSoonTT > 0 ? Profile.toMgdl(eatingSoonTT,Constants.MGDL) : 90d; - activityTT = prefTT > 0 ? Profile.toMgdl(prefTT,Constants.MGDL) : 140d; + esTT = eatingSoonTT > 0 ? Profile.toMgdl(eatingSoonTT,Constants.MMOL) : 90d; + activityTT = prefTT > 0 ? Profile.toMgdl(prefTT,Constants.MMOL) : 140d; } else { esTT = eatingSoonTT > 0 ? eatingSoonTT : 90d; activityTT = prefTT > 0 ? prefTT : 140d; 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 356c3a9b3d..0b8b263262 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 @@ -250,7 +250,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, if(currentProfile == null) return; if(currentProfile.getUnits().equals(Constants.MMOL)) - tt = prefTT > 0 ? Profile.toMgdl(prefTT, Constants.MGDL) : 80d; + tt = prefTT > 0 ? Profile.toMgdl(prefTT, Constants.MMOL) : 80d; else tt = prefTT > 0 ? prefTT : 80d; final double finalTT = tt; From 6443502808e8a21d4539ad2b6bf1b29cedbb7c8a Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Fri, 2 Mar 2018 16:41:25 +0200 Subject: [PATCH 19/23] reduced if...else to single line as Adrian suggested --- .../plugins/Overview/Dialogs/NewCarbsDialog.java | 10 +++------- 1 file changed, 3 insertions(+), 7 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 5e2a811dbb..9ecf426a72 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 @@ -260,13 +260,9 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D Profile currentProfile = MainApp.getConfigBuilder().getProfile(); if(currentProfile == null) return; - if(currentProfile.getUnits().equals(Constants.MMOL)) { - esTT = eatingSoonTT > 0 ? Profile.toMgdl(eatingSoonTT,Constants.MMOL) : 90d; - activityTT = prefTT > 0 ? Profile.toMgdl(prefTT,Constants.MMOL) : 140d; - } else { - esTT = eatingSoonTT > 0 ? eatingSoonTT : 90d; - activityTT = prefTT > 0 ? prefTT : 140d; - } + + esTT = eatingSoonTT > 0 ? Profile.toMgdl(eatingSoonTT,currentProfile.getUnits()) : 90d; + activityTT = prefTT > 0 ? Profile.toMgdl(prefTT,currentProfile.getUnits()) : 140d; if (startActivityTTCheckbox.isChecked()) { if(currentProfile.getUnits().equals(Constants.MMOL)) { From 37b96d7e31063258151204cf0523b3fac3ed519c Mon Sep 17 00:00:00 2001 From: PoweRGbg Date: Sun, 4 Mar 2018 15:59:17 +0200 Subject: [PATCH 20/23] remove unused import (RadioButton) --- .../androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java | 1 - 1 file changed, 1 deletion(-) 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 9ecf426a72..2eb7898aa1 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 @@ -18,7 +18,6 @@ import android.view.WindowManager; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; -import android.widget.RadioButton; import android.widget.TextView; import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; From ca9150ba5b5d5181d02b37307c043cdea1b87db2 Mon Sep 17 00:00:00 2001 From: PoweRGbg Date: Sun, 4 Mar 2018 16:06:54 +0200 Subject: [PATCH 21/23] more readable low TT message --- .../androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 2eb7898aa1..3367903df1 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 @@ -272,9 +272,9 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D } if (startEsTTCheckbox.isChecked() && !startActivityTTCheckbox.isChecked()) { if(currentProfile.getUnits().equals(Constants.MMOL)) { - confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT,Constants.MGDL) + " mmol/l for " + ((int) esTTDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT,Constants.MGDL) + " mmol/l for " + ((int) esTTDuration) + " min "; } else - confirmMessage += "
" + "TT: " + "" + ((int) esTT) + " mg/dl for " + ((int) esTTDuration) + " min "; + confirmMessage += "
" + "TT: " + "" + ((int) esTT) + " mg/dl for " + ((int) esTTDuration) + " min "; } final double finalTT = activityTT; From 951ad2659046d0d427565cb06cc6bbb3cb326740 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 10 Mar 2018 17:58:45 +0100 Subject: [PATCH 22/23] cleanup --- .../Overview/Dialogs/NewCarbsDialog.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 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 3367903df1..8a2d7b4eed 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 @@ -41,9 +41,7 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.OpenAPSSMB.DetermineBasalResultSMB; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DateUtil; import info.nightscout.utils.NumberPicker; @@ -257,22 +255,22 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D double activityTT = 140d; double esTT = 90d; Profile currentProfile = MainApp.getConfigBuilder().getProfile(); - if(currentProfile == null) + if (currentProfile == null) return; - esTT = eatingSoonTT > 0 ? Profile.toMgdl(eatingSoonTT,currentProfile.getUnits()) : 90d; - activityTT = prefTT > 0 ? Profile.toMgdl(prefTT,currentProfile.getUnits()) : 140d; + esTT = eatingSoonTT > 0 ? Profile.toMgdl(eatingSoonTT, currentProfile.getUnits()) : 90d; + activityTT = prefTT > 0 ? Profile.toMgdl(prefTT, currentProfile.getUnits()) : 140d; if (startActivityTTCheckbox.isChecked()) { - if(currentProfile.getUnits().equals(Constants.MMOL)) { - confirmMessage += "
" + "TT: " + "" + Profile.toMmol(activityTT,Constants.MGDL) + " mmol/l for " + ((int) activityTTDuration) + " min "; + if (currentProfile.getUnits().equals(Constants.MMOL)) { + confirmMessage += "
" + "TT: " + "" + Profile.toMmol(activityTT, Constants.MGDL) + " mmol/l for " + ((int) activityTTDuration) + " min "; } else confirmMessage += "
" + "TT: " + "" + ((int) activityTT) + " mg/dl for " + ((int) activityTTDuration) + " min "; } if (startEsTTCheckbox.isChecked() && !startActivityTTCheckbox.isChecked()) { - if(currentProfile.getUnits().equals(Constants.MMOL)) { - confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT,Constants.MGDL) + " mmol/l for " + ((int) esTTDuration) + " min "; + if (currentProfile.getUnits().equals(Constants.MMOL)) { + confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT, Constants.MGDL) + " mmol/l for " + ((int) esTTDuration) + " min "; } else confirmMessage += "
" + "TT: " + "" + ((int) esTT) + " mg/dl for " + ((int) esTTDuration) + " min "; @@ -286,7 +284,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D if (!initialEventTime.equals(eventTime)) { confirmMessage += "
Time: " + DateUtil.dateAndTimeString(eventTime); } - if(confirmMessage.length() > 0) { + if (confirmMessage.length() > 0) { final int finalCarbsAfterConstraints = carbsAfterConstraints; From ec1c43b905f17468d1c8035ed834a676685c2745 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 10 Mar 2018 19:22:31 +0100 Subject: [PATCH 23/23] carbs dialog: defaults for mmol, i18n --- .../info/nightscout/androidaps/Constants.java | 8 ++ .../info/nightscout/androidaps/MainApp.java | 4 + .../Overview/Dialogs/NewCarbsDialog.java | 97 ++++++++++--------- .../res/layout/overview_newcarbs_dialog.xml | 16 +-- app/src/main/res/values/strings.xml | 4 + 5 files changed, 74 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index e0549ab9bb..d933018790 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -38,6 +38,14 @@ public class Constants { //DanaR public static final double dailyLimitWarning = 0.95d; + // Temp targets + public static final int defaultActivityTTDuration = 90; // min + public static final double defaultActivityTTmgdl = 90d; + public static final double defaultActivityTTmmol = 5d; + public static final int defaultEatingSoonTTDuration = 45; // min + public static final double defaultEatingSoonTTmgdl = 140d; + public static final double defaultEatingSoonTTmmol = 8d; + //NSClientInternal public static final int MAX_LOG_LINES = 100; diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index bfa801cbdb..2573b57975 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -247,6 +247,10 @@ public class MainApp extends Application { return sResources.getString(id, args); } + public static int gc(int id) { + return sResources.getColor(id); + } + public static MainApp instance() { return sInstance; } 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 8a2d7b4eed..6f46a5db8a 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 @@ -44,6 +44,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DateUtil; +import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.NumberPicker; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; @@ -70,7 +71,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D private static final double FAV3_DEFAULT = 20; private CheckBox suspendLoopCheckbox; private CheckBox startActivityTTCheckbox; - private CheckBox startEsTTCheckbox; + private CheckBox startEatingSoonTTCheckbox; private Integer maxCarbs; @@ -102,7 +103,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D Integer carbs = SafeParse.stringToInt(editCarbs.getText()); if (carbs > maxCarbs) { editCarbs.setValue(0d); - ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.carbsconstraintapplied)); + ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.carbsconstraintapplied)); } } @@ -126,7 +127,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); startActivityTTCheckbox = view.findViewById(R.id.newcarbs_activity_tt); - startEsTTCheckbox = view.findViewById(R.id.carbs_eating_soon_tt); + startEatingSoonTTCheckbox = view.findViewById(R.id.carbs_eating_soon_tt); dateButton = view.findViewById(R.id.newcarbs_eventdate); timeButton = view.findViewById(R.id.newcarb_eventtime); @@ -139,7 +140,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D timeButton.setOnClickListener(this); //To be able to select only one TT at a time - startEsTTCheckbox.setOnClickListener(this); + startEatingSoonTTCheckbox.setOnClickListener(this); startActivityTTCheckbox.setOnClickListener(this); // TODO prefilling carbs, maybe @@ -151,13 +152,13 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D fav1Button = view.findViewById(R.id.newcarbs_plus1); fav1Button.setOnClickListener(this); - fav1Button.setText("+" + SP.getString(MainApp.gs(R.string.key_carbs_button_increment_1), String.valueOf(FAV1_DEFAULT))); + fav1Button.setText("+" + SP.getString(R.string.key_carbs_button_increment_1, String.valueOf(FAV1_DEFAULT))); fav2Button = view.findViewById(R.id.newcarbs_plus2); fav2Button.setOnClickListener(this); - fav2Button.setText("+" + SP.getString(MainApp.gs(R.string.key_carbs_button_increment_2), String.valueOf(FAV2_DEFAULT))); + fav2Button.setText("+" + SP.getString(R.string.key_carbs_button_increment_2, String.valueOf(FAV2_DEFAULT))); fav3Button = view.findViewById(R.id.newcarbs_plus3); fav3Button.setOnClickListener(this); - fav3Button.setText("+" + SP.getString(MainApp.gs(R.string.key_carbs_button_increment_3), String.valueOf(FAV3_DEFAULT))); + fav3Button.setText("+" + SP.getString(R.string.key_carbs_button_increment_3, String.valueOf(FAV3_DEFAULT))); suspendLoopCheckbox = view.findViewById(R.id.newcarbs_suspend_loop); @@ -201,21 +202,21 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D break; case R.id.newcarbs_plus1: editCarbs.setValue(editCarbs.getValue() - + SP.getDouble(MainApp.gs(R.string.key_carbs_button_increment_1), FAV1_DEFAULT)); + + SP.getDouble(R.string.key_carbs_button_increment_1, FAV1_DEFAULT)); validateInputs(); break; case R.id.newcarbs_plus2: editCarbs.setValue(editCarbs.getValue() - + SP.getDouble(MainApp.gs(R.string.key_carbs_button_increment_2), FAV2_DEFAULT)); + + SP.getDouble(R.string.key_carbs_button_increment_2, FAV2_DEFAULT)); validateInputs(); break; case R.id.newcarbs_plus3: editCarbs.setValue(editCarbs.getValue() - + SP.getDouble(MainApp.gs(R.string.key_carbs_button_increment_3), FAV3_DEFAULT)); + + SP.getDouble(R.string.key_carbs_button_increment_3, FAV3_DEFAULT)); validateInputs(); break; case R.id.newcarbs_activity_tt: - startEsTTCheckbox.setChecked(false); + startEatingSoonTTCheckbox.setChecked(false); break; case R.id.carbs_eating_soon_tt: startActivityTTCheckbox.setChecked(false); @@ -238,45 +239,47 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D String confirmMessage = ""; if (carbs > 0) - confirmMessage += getString(R.string.carbs) + ": " + "" + carbsAfterConstraints + "g" + ""; + confirmMessage += MainApp.gs(R.string.carbs) + ": " + "" + carbsAfterConstraints + "g" + ""; if (!carbsAfterConstraints.equals(carbs)) - confirmMessage += "
" + getString(R.string.carbsconstraintapplied) + ""; + confirmMessage += "
" + MainApp.gs(R.string.carbsconstraintapplied) + ""; if (suspendLoopCheckbox.isChecked()) { - confirmMessage += "
" + "Loop: " + "" + "Suspend for 30 min"; + confirmMessage += "
" + MainApp.gs(R.string.loop) + ": " + "" + MainApp.gs(R.string.suspendloopfor30min) + ""; } - double activityTTDurationSettings = SP.getDouble(R.string.key_activity_duration, 90d); - double eatingSoonTTDuration = SP.getDouble(R.string.key_eatingsoon_duration, 45d); - double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, 90d); - double activityTTDuration = activityTTDurationSettings > 0 ? activityTTDurationSettings : 90d; - final double esTTDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : 45d; - double prefTT = SP.getDouble(R.string.key_activity_target, 140d); - - double activityTT = 140d; - double esTT = 90d; - Profile currentProfile = MainApp.getConfigBuilder().getProfile(); + final Profile currentProfile = MainApp.getConfigBuilder().getProfile(); if (currentProfile == null) return; - esTT = eatingSoonTT > 0 ? Profile.toMgdl(eatingSoonTT, currentProfile.getUnits()) : 90d; - activityTT = prefTT > 0 ? Profile.toMgdl(prefTT, currentProfile.getUnits()) : 140d; + int activityTTDuration = SP.getInt(R.string.key_activity_duration, Constants.defaultActivityTTDuration); + activityTTDuration = activityTTDuration > 0 ? activityTTDuration : Constants.defaultActivityTTDuration; + double activityTT = SP.getDouble(R.string.key_activity_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultActivityTTmmol : Constants.defaultActivityTTmgdl); + activityTT = activityTT > 0 ? activityTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultActivityTTmmol : Constants.defaultActivityTTmgdl; + + 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 ? Profile.toMgdl(eatingSoonTT, currentProfile.getUnits()) : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl; + if (startActivityTTCheckbox.isChecked()) { if (currentProfile.getUnits().equals(Constants.MMOL)) { - confirmMessage += "
" + "TT: " + "" + Profile.toMmol(activityTT, Constants.MGDL) + " mmol/l for " + ((int) activityTTDuration) + " min "; + confirmMessage += "
" + MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(activityTT) + " mmol/l (" + ((int) activityTTDuration) + " min)"; } else - confirmMessage += "
" + "TT: " + "" + ((int) activityTT) + " mg/dl for " + ((int) activityTTDuration) + " min "; + confirmMessage += "
" + MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to0Decimal(activityTT) + " mg/dl (" + ((int) activityTTDuration) + " min)"; } - if (startEsTTCheckbox.isChecked() && !startActivityTTCheckbox.isChecked()) { + if (startEatingSoonTTCheckbox.isChecked() && !startActivityTTCheckbox.isChecked()) { if (currentProfile.getUnits().equals(Constants.MMOL)) { - confirmMessage += "
" + "TT: " + "" + Profile.toMmol(esTT, Constants.MGDL) + " mmol/l for " + ((int) esTTDuration) + " min "; + confirmMessage += "
" + MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(eatingSoonTT) + " mmol/l (" + eatingSoonTTDuration + " min)"; } else - confirmMessage += "
" + "TT: " + "" + ((int) esTT) + " mg/dl for " + ((int) esTTDuration) + " min "; + confirmMessage += "
" + MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to0Decimal(eatingSoonTT) + " mg/dl (" + eatingSoonTTDuration + " min)"; } - final double finalTT = activityTT; - final double finalEsTT = esTT; + final double finalActivityTT = activityTT; + final double finalEatigSoonTT = eatingSoonTT; + final int finalActivityTTDuration = activityTTDuration; + final int finalEatingSoonTTDuration = eatingSoonTTDuration; + if (StringUtils.isNoneEmpty(food)) { confirmMessage += "
" + "Food: " + food; } @@ -291,12 +294,12 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D final Context context = getContext(); final AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(this.getContext().getString(R.string.confirmation)); + builder.setTitle(MainApp.gs(R.string.confirmation)); if (confirmMessage.startsWith("
")) confirmMessage = confirmMessage.substring("
".length()); builder.setMessage(Html.fromHtml(confirmMessage)); - builder.setPositiveButton(getString(R.string.ok), (dialog, id) -> { + builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> { synchronized (builder) { if (accepted) { log.debug("guarding: already accepted"); @@ -311,29 +314,29 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D @Override public void run() { if (!result.success) { - ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); + ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.tempbasaldeliveryerror)); } } }); } - if (startActivityTTCheckbox.isChecked() || (startActivityTTCheckbox.isChecked() && startEsTTCheckbox.isChecked())) { + if (startActivityTTCheckbox.isChecked()) { TempTarget tempTarget = new TempTarget(); tempTarget.date = System.currentTimeMillis(); - tempTarget.durationInMinutes = (int) activityTTDuration; - tempTarget.reason = "Activity"; + tempTarget.durationInMinutes = finalActivityTTDuration; + tempTarget.reason = MainApp.gs(R.string.activity); tempTarget.source = Source.USER; - tempTarget.low = (double) finalTT; - tempTarget.high = (double) finalTT; + tempTarget.low = Profile.toMgdl(finalActivityTT, currentProfile.getUnits()); + tempTarget.high = Profile.toMgdl(finalActivityTT, currentProfile.getUnits()); MainApp.getDbHelper().createOrUpdate(tempTarget); - } else if (startEsTTCheckbox.isChecked()) { + } else if (startEatingSoonTTCheckbox.isChecked()) { TempTarget tempTarget = new TempTarget(); tempTarget.date = System.currentTimeMillis(); - tempTarget.durationInMinutes = (int) esTTDuration; - tempTarget.reason = "Eating soon"; + tempTarget.durationInMinutes = finalEatingSoonTTDuration; + tempTarget.reason = MainApp.gs(R.string.eatingsoon); tempTarget.source = Source.USER; - tempTarget.low = (double) finalEsTT; - tempTarget.high = (double) finalEsTT; + tempTarget.low = Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()); + tempTarget.high = Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()); MainApp.getDbHelper().createOrUpdate(tempTarget); } @@ -349,7 +352,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D } } }); - builder.setNegativeButton(getString(R.string.cancel), null); + builder.setNegativeButton(MainApp.gs(R.string.cancel), null); builder.show(); dismiss(); } else diff --git a/app/src/main/res/layout/overview_newcarbs_dialog.xml b/app/src/main/res/layout/overview_newcarbs_dialog.xml index 7f00891e40..74416d7b8a 100644 --- a/app/src/main/res/layout/overview_newcarbs_dialog.xml +++ b/app/src/main/res/layout/overview_newcarbs_dialog.xml @@ -37,27 +37,27 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="5dp" - android:text="Start activity TT"/> + android:text="@string/start_activity_tt" /> + android:text="@string/start_eating_soon_tt" /> + android:text="@string/suspendloopfor30min" /> + android:layout_gravity="center_horizontal" + android:padding="5dp"> + android:visibility="gone" /> + android:layout_marginBottom="5dp" + android:orientation="horizontal">