From bd3b7467a40477e804fbeb5c37106e81c3eed481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 12 Oct 2024 13:21:20 +0100 Subject: [PATCH] Garmin/Zepp OS: Display resting HR --- .../charts/HeartRateDailyFragment.java | 34 +++++++++++++------ .../devices/AbstractDeviceCoordinator.java | 5 +++ .../devices/DeviceCoordinator.java | 5 +++ .../devices/garmin/GarminCoordinator.java | 5 +++ .../devices/huami/HuamiCoordinator.java | 5 +++ .../main/res/layout/fragment_heart_rate.xml | 8 ++--- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/HeartRateDailyFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/HeartRateDailyFragment.java index dc4be93d5..6c58a14c3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/HeartRateDailyFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/HeartRateDailyFragment.java @@ -12,7 +12,6 @@ import androidx.core.content.ContextCompat; import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.charts.LineChart; -import com.github.mikephil.charting.components.Legend; import com.github.mikephil.charting.components.LegendEntry; import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.YAxis; @@ -23,6 +22,7 @@ import com.github.mikephil.charting.data.LineDataSet; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Comparator; import java.util.Date; import java.util.List; @@ -35,6 +35,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; +import nodomain.freeyourgadget.gadgetbridge.model.HeartRateSample; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; public class HeartRateDailyFragment extends AbstractChartFragment { @@ -50,7 +51,6 @@ public class HeartRateDailyFragment extends AbstractChartFragment getActivitySamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) { @@ -124,7 +125,19 @@ public class HeartRateDailyFragment extends AbstractChartFragment samples = getActivitySamples(db, device, startTs, endTs); - return new HeartRateData(samples); + + int restingHeartRate = -1; + if (supportsHeartRateRestingMeasurement()) { + restingHeartRate = device.getDeviceCoordinator() + .getHeartRateRestingSampleProvider(device, db.getDaoSession()) + .getAllSamples(startTs * 1000L, endTs * 1000L) + .stream() + .max(Comparator.comparingLong(HeartRateSample::getTimestamp)) + .map(HeartRateSample::getHeartRate) + .orElse(-1); + } + + return new HeartRateData(samples, restingHeartRate); } @Override @@ -186,7 +199,6 @@ public class HeartRateDailyFragment extends AbstractChartFragment lineEntries = new ArrayList<>(); List samples = data.samples; int average = 0; - int resting = 0; int minimum = 0; int maximum = 0; int sum = 0; @@ -233,7 +245,7 @@ public class HeartRateDailyFragment extends AbstractChartFragment 0 ? getString(R.string.bpm_value_unit, average) : "-"); hrMinimum.setText(minimum > 0 ? getString(R.string.bpm_value_unit, minimum) : "-"); hrMaximum.setText(maximum > 0 ? getString(R.string.bpm_value_unit, maximum) : "-"); - hrResting.setText(resting > 0 ? getString(R.string.bpm_value_unit, resting) : "-"); + hrResting.setText(data.restingHeartRate > 0 ? getString(R.string.bpm_value_unit, data.restingHeartRate) : "-"); if (minimum > 0) { @@ -251,9 +263,11 @@ public class HeartRateDailyFragment extends AbstractChartFragment samples; + public int restingHeartRate; - protected HeartRateData(List samples) { + protected HeartRateData(List samples, int restingHeartRate) { this.samples = samples; + this.restingHeartRate = restingHeartRate; } } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java index 9ac9cffc5..78201df3f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java @@ -643,6 +643,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator { return false; } + @Override + public boolean supportsHeartRateRestingMeasurement(final GBDevice device) { + return false; + } + @Override public boolean supportsManualHeartRateMeasurement(final GBDevice device) { return supportsHeartRateMeasurement(device); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java index 76f90cf85..19e218866 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java @@ -462,6 +462,11 @@ public interface DeviceCoordinator { */ boolean supportsHeartRateMeasurement(GBDevice device); + /** + * Returns true if the given device supports resting heart rate measurements. + */ + boolean supportsHeartRateRestingMeasurement(GBDevice device); + /** * Returns true if the device supports triggering manual one-shot heart rate measurements. */ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminCoordinator.java index d3eeef484..e2ea0f3c3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminCoordinator.java @@ -259,6 +259,11 @@ public abstract class GarminCoordinator extends AbstractBLEDeviceCoordinator { return true; } + @Override + public boolean supportsHeartRateRestingMeasurement(final GBDevice device) { + return true; + } + @Override public boolean supportsRealtimeData() { return true; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java index acb3e8069..33ac9983d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java @@ -120,6 +120,11 @@ public abstract class HuamiCoordinator extends AbstractBLEDeviceCoordinator { return true; } + @Override + public boolean supportsHeartRateRestingMeasurement(final GBDevice device) { + return true; + } + @Override public int[] getSupportedDeviceSpecificAuthenticationSettings() { return new int[]{R.xml.devicesettings_pairingkey}; diff --git a/app/src/main/res/layout/fragment_heart_rate.xml b/app/src/main/res/layout/fragment_heart_rate.xml index 736970798..b46910ec2 100644 --- a/app/src/main/res/layout/fragment_heart_rate.xml +++ b/app/src/main/res/layout/fragment_heart_rate.xml @@ -45,7 +45,7 @@ android:id="@+id/hr_minimum" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="0" + android:text="@string/stats_empty_value" android:textSize="20sp" />