diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java index a9a6723d7..ebad62807 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java @@ -54,17 +54,17 @@ public abstract class AbstractActivityChartFragment extend public boolean supportsHeartrate(GBDevice device) { DeviceCoordinator coordinator = device.getDeviceCoordinator(); - return coordinator != null && coordinator.supportsHeartRateMeasurement(device); + return coordinator.supportsHeartRateMeasurement(device); } public boolean supportsRemSleep(GBDevice device) { DeviceCoordinator coordinator = device.getDeviceCoordinator(); - return coordinator != null && coordinator.supportsRemSleep(); + return coordinator.supportsRemSleep(); } public boolean supportsAwakeSleep(GBDevice device) { DeviceCoordinator coordinator = device.getDeviceCoordinator(); - return coordinator != null && coordinator.supportsAwakeSleep(); + return coordinator.supportsAwakeSleep(); } protected static final class ActivityConfig { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java index 546f03ca3..28d09bee0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java @@ -189,7 +189,7 @@ public abstract class AbstractWeekChartFragment extends AbstractActivityChartFra PieDataSet set = new PieDataSet(entries, ""); ActivityAmounts amounts = getActivityAmountsForDay(db, day, device); - float totalValues[] = getTotalsForActivityAmounts(amounts); + float[] totalValues = getTotalsForActivityAmounts(amounts); String[] pieLabels = getPieLabels(); float totalValue = 0; for (int i = 0; i < totalValues.length; i++) { 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 7d8b88bca..f51d29bd7 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 @@ -91,12 +91,14 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment { } float[] totalAmounts = getTotalsForActivityAmounts(amounts); - deepWeeklyTotal += (long) totalAmounts[0]; - lightWeeklyTotal += (long) totalAmounts[1]; - remWeeklyTotal += (long) totalAmounts[2]; - + int i = 0; + deepWeeklyTotal += (long) totalAmounts[i++]; + lightWeeklyTotal += (long) totalAmounts[i++]; + if (supportsRemSleep(getChartsHost().getDevice())) { + remWeeklyTotal += (long) totalAmounts[i++]; + } if (supportsAwakeSleep(getChartsHost().getDevice())) { - awakeWeeklyTotal += (long) totalAmounts[3]; + awakeWeeklyTotal += (long) totalAmounts[i++]; } day.add(Calendar.DATE, 1); @@ -273,7 +275,10 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment { int totalMinutesRemSleep = (int) (totalSecondsRemSleep / 60); int totalMinutesAwakeSleep = (int) (totalSecondsAwakeSleep / 60); - float[] activityAmountsTotals = {totalMinutesDeepSleep, totalMinutesLightSleep, totalMinutesRemSleep}; + float[] activityAmountsTotals = {totalMinutesDeepSleep, totalMinutesLightSleep}; + if (supportsRemSleep(getChartsHost().getDevice())) { + activityAmountsTotals = ArrayUtils.add(activityAmountsTotals, totalMinutesRemSleep); + } if (supportsAwakeSleep(getChartsHost().getDevice())) { activityAmountsTotals = ArrayUtils.add(activityAmountsTotals, totalMinutesAwakeSleep); }