diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/BarChartStackedTimeValueFormatter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/BarChartStackedTimeValueFormatter.java index a2736b928..3392ba8c4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/BarChartStackedTimeValueFormatter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/BarChartStackedTimeValueFormatter.java @@ -8,11 +8,13 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils; public class BarChartStackedTimeValueFormatter extends StackedValueFormatter { private float[] processedValues; private BarEntry lastEntry; + private int ignoreLast; private int lastNonZeroIndex; private int index = 0; - public BarChartStackedTimeValueFormatter(boolean drawWholeStack, String suffix, int decimals) { + public BarChartStackedTimeValueFormatter(boolean drawWholeStack, String suffix, int decimals, int ignoreLast) { super(drawWholeStack, suffix, decimals); + this.ignoreLast = ignoreLast; } private int getLastNonZeroIndex(float[] array) { @@ -44,7 +46,7 @@ public class BarChartStackedTimeValueFormatter extends StackedValueFormatter { String getFormattedValue(float[] values) { float sum = 0; - for (int i = 0; i < values.length - 1; i++) { + for (int i = 0; i < values.length - ignoreLast; i++) { sum += values[i]; } return DateTimeUtils.minutesToHHMM((int) sum); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java index f51d29bd7..274fd785b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java @@ -152,7 +152,10 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment { mWeekChart.setData(mcd.getWeekBeforeData().getData()); mWeekChart.getXAxis().setValueFormatter(mcd.getWeekBeforeData().getXValueFormatter()); mWeekChart.getBarData().setValueTextSize(10f); - mWeekChart.getBarData().setValueFormatter(new BarChartStackedTimeValueFormatter(false, "", 0)); + + // The last value is for awake time, which we do not want to include in the "total sleep time" + final int barIgnoreLast = supportsAwakeSleep(getChartsHost().getDevice()) ? 1 : 0; + mWeekChart.getBarData().setValueFormatter(new BarChartStackedTimeValueFormatter(false, "", 0, barIgnoreLast)); if (TOTAL_DAYS_FOR_AVERAGE > 0) { float avgDeep = Math.abs(this.mySleepWeeklyData.getTotalDeep() / TOTAL_DAYS_FOR_AVERAGE);