Fix sleep charts for devices without REM sleep

This commit is contained in:
José Rebelo 2024-09-07 13:41:30 +01:00
parent fc450882cb
commit 3a778a9f2a
3 changed files with 15 additions and 10 deletions

View File

@ -54,17 +54,17 @@ public abstract class AbstractActivityChartFragment<D extends ChartsData> extend
public boolean supportsHeartrate(GBDevice device) { public boolean supportsHeartrate(GBDevice device) {
DeviceCoordinator coordinator = device.getDeviceCoordinator(); DeviceCoordinator coordinator = device.getDeviceCoordinator();
return coordinator != null && coordinator.supportsHeartRateMeasurement(device); return coordinator.supportsHeartRateMeasurement(device);
} }
public boolean supportsRemSleep(GBDevice device) { public boolean supportsRemSleep(GBDevice device) {
DeviceCoordinator coordinator = device.getDeviceCoordinator(); DeviceCoordinator coordinator = device.getDeviceCoordinator();
return coordinator != null && coordinator.supportsRemSleep(); return coordinator.supportsRemSleep();
} }
public boolean supportsAwakeSleep(GBDevice device) { public boolean supportsAwakeSleep(GBDevice device) {
DeviceCoordinator coordinator = device.getDeviceCoordinator(); DeviceCoordinator coordinator = device.getDeviceCoordinator();
return coordinator != null && coordinator.supportsAwakeSleep(); return coordinator.supportsAwakeSleep();
} }
protected static final class ActivityConfig { protected static final class ActivityConfig {

View File

@ -189,7 +189,7 @@ public abstract class AbstractWeekChartFragment extends AbstractActivityChartFra
PieDataSet set = new PieDataSet(entries, ""); PieDataSet set = new PieDataSet(entries, "");
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device); ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
float totalValues[] = getTotalsForActivityAmounts(amounts); float[] totalValues = getTotalsForActivityAmounts(amounts);
String[] pieLabels = getPieLabels(); String[] pieLabels = getPieLabels();
float totalValue = 0; float totalValue = 0;
for (int i = 0; i < totalValues.length; i++) { for (int i = 0; i < totalValues.length; i++) {

View File

@ -91,12 +91,14 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
} }
float[] totalAmounts = getTotalsForActivityAmounts(amounts); float[] totalAmounts = getTotalsForActivityAmounts(amounts);
deepWeeklyTotal += (long) totalAmounts[0]; int i = 0;
lightWeeklyTotal += (long) totalAmounts[1]; deepWeeklyTotal += (long) totalAmounts[i++];
remWeeklyTotal += (long) totalAmounts[2]; lightWeeklyTotal += (long) totalAmounts[i++];
if (supportsRemSleep(getChartsHost().getDevice())) {
remWeeklyTotal += (long) totalAmounts[i++];
}
if (supportsAwakeSleep(getChartsHost().getDevice())) { if (supportsAwakeSleep(getChartsHost().getDevice())) {
awakeWeeklyTotal += (long) totalAmounts[3]; awakeWeeklyTotal += (long) totalAmounts[i++];
} }
day.add(Calendar.DATE, 1); day.add(Calendar.DATE, 1);
@ -273,7 +275,10 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
int totalMinutesRemSleep = (int) (totalSecondsRemSleep / 60); int totalMinutesRemSleep = (int) (totalSecondsRemSleep / 60);
int totalMinutesAwakeSleep = (int) (totalSecondsAwakeSleep / 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())) { if (supportsAwakeSleep(getChartsHost().getDevice())) {
activityAmountsTotals = ArrayUtils.add(activityAmountsTotals, totalMinutesAwakeSleep); activityAmountsTotals = ArrayUtils.add(activityAmountsTotals, totalMinutesAwakeSleep);
} }