From b40749d53c7e70b270bd643e62de6889d1a6054e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Thu, 19 Sep 2024 00:30:17 +0100 Subject: [PATCH] Identify device in realtime samples --- .../activities/ControlCenterv2.java | 21 ++++++++++--------- .../activities/DevicesFragment.java | 12 +++++++---- .../activities/HeartRateDialog.java | 11 ++++++++-- .../adapter/GBDeviceAdapterv2.java | 4 ++-- .../devices/colmi/ColmiR0xPacketHandler.java | 1 + .../banglejs/BangleJSDeviceSupport.java | 1 + .../support/CyclingSensorSupport.java | 1 + .../devices/fitpro/FitProDeviceSupport.java | 1 + .../devices/hplus/HPlusHandlerThread.java | 1 + .../service/devices/huami/HuamiSupport.java | 1 + .../service/devices/jyou/y5/Y5Support.java | 2 ++ .../devices/lefun/LefunDeviceSupport.java | 2 ++ .../makibeshr3/MakibesHR3DeviceSupport.java | 1 + .../service/devices/miband/MiBandSupport.java | 1 + .../devices/pinetime/PineTimeJFSupport.java | 2 ++ .../sonyswr12/SonySWR12HandlerThread.java | 1 + .../conversation/HeartRateHandler.java | 2 ++ .../incoming/LiveHeartrateHandler.java | 2 ++ .../xiaomi/services/XiaomiHealthService.java | 1 + 19 files changed, 50 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java index de7daf623..631ffeff1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java @@ -77,9 +77,11 @@ import org.slf4j.LoggerFactory; import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Objects; import java.util.Set; @@ -88,11 +90,9 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.discovery.DiscoveryActivityV2; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; -import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService; import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils; import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -135,7 +135,8 @@ public class ControlCenterv2 extends AppCompatActivity finish(); break; case DeviceService.ACTION_REALTIME_SAMPLES: - handleRealtimeSample(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE)); + final GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE); + handleRealtimeSample(device, intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE)); break; case ACTION_REQUEST_PERMISSIONS: checkAndRequestPermissions(); @@ -153,22 +154,22 @@ public class ControlCenterv2 extends AppCompatActivity } }; private boolean pesterWithPermissions = true; - private ActivitySample currentHRSample; + private final Map currentHRSample = new HashMap<>(); - public ActivitySample getCurrentHRSample() { - return currentHRSample; + public ActivitySample getCurrentHRSample(final GBDevice device) { + return currentHRSample.get(device); } - private void setCurrentHRSample(ActivitySample sample) { + private void setCurrentHRSample(final GBDevice device, ActivitySample sample) { if (HeartRateUtils.getInstance().isValidHeartRateValue(sample.getHeartRate())) { - currentHRSample = sample; + currentHRSample.put(device, sample); } } - private void handleRealtimeSample(Serializable extra) { + private void handleRealtimeSample(final GBDevice device, Serializable extra) { if (extra instanceof ActivitySample) { ActivitySample sample = (ActivitySample) extra; - setCurrentHRSample(sample); + setCurrentHRSample(device, sample); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java index 7cf65a11b..66e10f36f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java @@ -72,10 +72,10 @@ public class DevicesFragment extends Fragment { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); + final GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE); switch (Objects.requireNonNull(action)) { case DeviceManager.ACTION_DEVICES_CHANGED: case GBApplication.ACTION_NEW_DATA: - final GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE); if (action.equals(GBApplication.ACTION_NEW_DATA)) { createRefreshTask("get activity data", requireContext(), device).execute(); } @@ -88,17 +88,21 @@ public class DevicesFragment extends Fragment { break; case DeviceService.ACTION_REALTIME_SAMPLES: - handleRealtimeSample(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE)); + handleRealtimeSample(device, intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE)); break; } } }; - private void handleRealtimeSample(Serializable extra) { + private void handleRealtimeSample(GBDevice device, Serializable extra) { if (extra instanceof ActivitySample) { ActivitySample sample = (ActivitySample) extra; if (HeartRateUtils.getInstance().isValidHeartRateValue(sample.getHeartRate())) { - refreshPairedDevices(); + if (device != null) { + refreshSingleDevice(device); + } else { + refreshPairedDevices(); + } } } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/HeartRateDialog.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/HeartRateDialog.java index 6e03852e4..56380dfde 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/HeartRateDialog.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/HeartRateDialog.java @@ -38,11 +38,14 @@ import java.io.Serializable; import java.util.Objects; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; import nodomain.freeyourgadget.gadgetbridge.model.HeartRateSample; public class HeartRateDialog extends Dialog { + private final GBDevice device; + protected static final Logger LOG = LoggerFactory.getLogger(HeartRateDialog.class); LinearLayout heart_rate_dialog_results_layout; RelativeLayout heart_rate_dialog_loading_layout; @@ -62,7 +65,10 @@ public class HeartRateDialog extends Dialog { public void onReceive(Context context, Intent intent) { switch (Objects.requireNonNull(intent.getAction())) { case DeviceService.ACTION_REALTIME_SAMPLES: - setMeasurementResults(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE)); + final GBDevice incomingDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE); + if (device.equals(incomingDevice)) { + setMeasurementResults(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE)); + } break; default: LOG.info("ignoring intent action {}", intent.getAction()); @@ -71,8 +77,9 @@ public class HeartRateDialog extends Dialog { } }; - public HeartRateDialog(@NonNull Context context) { + public HeartRateDialog(final GBDevice device, @NonNull Context context) { super(context); + this.device = device; } private void setMeasurementResults(Serializable result) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java index ac1ba0ff4..dbd260592 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java @@ -411,7 +411,7 @@ public class GBDeviceAdapterv2 extends ListAdapter