diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 89157570ed..984d92c4e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -333,7 +333,7 @@ public class Profile { public double getMaxDailyBasal() { Double max = 0d; for (Integer hour = 0; hour < 24; hour++) { - double value = getBasal((Integer)(hour * 60 * 60)); + double value = getBasal((Integer) (hour * 60 * 60)); if (value > max) max = value; } return max; @@ -378,6 +378,11 @@ public class Profile { else return value * Constants.MMOLL_TO_MGDL; } + public static Double toMmol(Double value, String units) { + if (units.equals(Constants.MGDL)) return value * Constants.MGDL_TO_MMOLL; + else return value; + } + public static Double fromMgdlToUnits(Double value, String units) { if (units.equals(Constants.MGDL)) return value; else return value * Constants.MGDL_TO_MMOLL; @@ -393,9 +398,16 @@ public class Profile { else return DecimalFormatter.to1Decimal(valueInMmol); } - // targets are stored in mg/dl - public static String toTargetRangeString(double low, double high, String units) { - if (low == high) return toUnitsString(low, Profile.fromMgdlToUnits(low, Constants.MMOL), units); - else return toUnitsString(low, Profile.fromMgdlToUnits(low, Constants.MMOL), units) + " - " + toUnitsString(high, Profile.fromMgdlToUnits(high, Constants.MMOL), units); + // targets are stored in mg/dl but profile vary + public static String toTargetRangeString(double low, double high, String sourceUnits, String units) { + double lowMgdl = toMgdl(low, sourceUnits); + double highMgdl = toMgdl(high, sourceUnits); + double lowMmol = toMmol(low, sourceUnits); + double highMmol = toMmol(high, sourceUnits); + if (low == high) + return toUnitsString(lowMgdl, lowMmol, units); + else + return toUnitsString(lowMgdl, lowMmol, units) + " - " + toUnitsString(highMgdl, highMmol, units); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 342f6bd20f..f50da429d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -952,11 +952,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, tempTargetView.setTextColor(Color.BLACK); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground)); tempTargetView.setVisibility(View.VISIBLE); - tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, units)); + tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units)); } else { tempTargetView.setTextColor(Color.WHITE); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetDisabledBackground)); - tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units)); + tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units, units)); tempTargetView.setVisibility(View.VISIBLE); } if (Config.NSCLIENT && tempTarget == null) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index a4bbd34f1c..66d673a5fb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -472,7 +472,7 @@ public class ActionStringHandler { //Check for Temp-Target: TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); if (tempTarget != null) { - ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, profile.getUnits()); + ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, profile.getUnits()); ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd()); ret += "\n\n"; }