From 04237b77276cbc7970d899b20ea27de8ea91f17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 4 May 2024 23:51:16 +0100 Subject: [PATCH] Prevent query for devices that have activity card disabled Even if the activity card was disabled, all devices would be queried for data. This slows down the UI when there are a lot of devices, especially if multiple of them have data and only a few have the card enabled. --- .../gadgetbridge/activities/DevicesFragment.java | 4 +++- .../activities/dashboard/DashboardTodayWidget.java | 4 ++-- .../gadgetbridge/adapter/GBDeviceAdapterv2.java | 9 +++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) 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 b91cc658f..45e07e823 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java @@ -46,6 +46,7 @@ import java.util.Objects; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.activities.discovery.DiscoveryActivityV2; import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2; import nodomain.freeyourgadget.gadgetbridge.database.DBAccess; @@ -233,7 +234,8 @@ public class DevicesFragment extends Fragment { protected void doInBackground(DBHandler db) { for (GBDevice gbDevice : deviceList) { final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); - if (coordinator.supportsActivityTracking()) { + boolean showActivityCard = GBApplication.getDevicePrefs(gbDevice.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD, true); + if (coordinator.supportsActivityTracking() && showActivityCard) { long[] stepsAndSleepData = getSteps(gbDevice, db); deviceActivityHashMap.put(gbDevice.getAddress(), stepsAndSleepData); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java index 833fb425c..9ef89a782 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java @@ -395,7 +395,7 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { if (firstTimestamp == 0) firstTimestamp = sample.getTimestamp(); if (lastTimestamp == 0) lastTimestamp = sample.getTimestamp(); if ((sample.getHeartRate() < 10 || sample.getTimestamp() > lastTimestamp + dashboardData.hrIntervalSecs) && firstTimestamp != lastTimestamp) { - LOG.info("Registered worn session from " + firstTimestamp + " to " + lastTimestamp); + LOG.debug("Registered worn session from {} to {}", firstTimestamp, lastTimestamp); addActivity(firstTimestamp, lastTimestamp, ActivityKind.TYPE_NOT_MEASURED); if (sample.getHeartRate() < 10) { firstTimestamp = 0; @@ -409,7 +409,7 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { lastTimestamp = sample.getTimestamp(); } if (firstTimestamp != lastTimestamp) { - LOG.info("Registered worn session from " + firstTimestamp + " to " + lastTimestamp); + LOG.debug("Registered worn session from {} to {}", firstTimestamp, lastTimestamp); addActivity(firstTimestamp, lastTimestamp, ActivityKind.TYPE_NOT_MEASURED); } } 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 6bb683604..eee67de01 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java @@ -1316,6 +1316,13 @@ public class GBDeviceAdapterv2 extends ListAdapter