fix of fix :(

This commit is contained in:
Milos Kozak 2017-08-20 19:42:41 +02:00
parent 86d791d93f
commit a18e2b4641
3 changed files with 20 additions and 8 deletions

View file

@ -333,7 +333,7 @@ public class Profile {
public double getMaxDailyBasal() { public double getMaxDailyBasal() {
Double max = 0d; Double max = 0d;
for (Integer hour = 0; hour < 24; hour++) { 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; if (value > max) max = value;
} }
return max; return max;
@ -378,6 +378,11 @@ public class Profile {
else return value * Constants.MMOLL_TO_MGDL; 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) { public static Double fromMgdlToUnits(Double value, String units) {
if (units.equals(Constants.MGDL)) return value; if (units.equals(Constants.MGDL)) return value;
else return value * Constants.MGDL_TO_MMOLL; else return value * Constants.MGDL_TO_MMOLL;
@ -393,9 +398,16 @@ public class Profile {
else return DecimalFormatter.to1Decimal(valueInMmol); else return DecimalFormatter.to1Decimal(valueInMmol);
} }
// targets are stored in mg/dl // targets are stored in mg/dl but profile vary
public static String toTargetRangeString(double low, double high, String units) { public static String toTargetRangeString(double low, double high, String sourceUnits, String units) {
if (low == high) return toUnitsString(low, Profile.fromMgdlToUnits(low, Constants.MMOL), units); double lowMgdl = toMgdl(low, sourceUnits);
else return toUnitsString(low, Profile.fromMgdlToUnits(low, Constants.MMOL), units) + " - " + toUnitsString(high, Profile.fromMgdlToUnits(high, Constants.MMOL), units); 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);
} }
} }

View file

@ -952,11 +952,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
tempTargetView.setTextColor(Color.BLACK); tempTargetView.setTextColor(Color.BLACK);
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground)); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground));
tempTargetView.setVisibility(View.VISIBLE); 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 { } else {
tempTargetView.setTextColor(Color.WHITE); tempTargetView.setTextColor(Color.WHITE);
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetDisabledBackground)); 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); tempTargetView.setVisibility(View.VISIBLE);
} }
if (Config.NSCLIENT && tempTarget == null) { if (Config.NSCLIENT && tempTarget == null) {

View file

@ -472,7 +472,7 @@ public class ActionStringHandler {
//Check for Temp-Target: //Check for Temp-Target:
TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis());
if (tempTarget != null) { 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 += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd());
ret += "\n\n"; ret += "\n\n";
} }