From fe5ec74ca1a2dd3202e531d717070f97d1ac45ed Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 9 Aug 2016 11:56:05 +0200 Subject: [PATCH] Pebble Health: read overlay data in sample provider and patch in raw kind completely untested --- .../pebble/PebbleHealthSampleProvider.java | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleHealthSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleHealthSampleProvider.java index 84be37125..c34b19d99 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleHealthSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleHealthSampleProvider.java @@ -1,10 +1,17 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble; +import java.util.Collections; +import java.util.List; + import de.greenrobot.dao.AbstractDao; import de.greenrobot.dao.Property; +import de.greenrobot.dao.query.QueryBuilder; +import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; +import nodomain.freeyourgadget.gadgetbridge.entities.Device; +import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay; import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample; import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -21,6 +28,37 @@ public class PebbleHealthSampleProvider extends AbstractSampleProvider getAllActivitySamples(int timestamp_from, int timestamp_to) { + List samples = super.getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL); + + Device dbDevice = DBHelper.findDevice(getmDevice(), getSession()); + if (dbDevice == null) { + // no device, no samples + return Collections.emptyList(); + } + Property timestampProperty = getTimestampSampleProperty(); + Property deviceProperty = getDeviceIdentifierSampleProperty(); + + QueryBuilder qb = getSession().getPebbleHealthActivityOverlayDao().queryBuilder(); + + // I assume it returns the records by id ascending ... (last overlay is dominant) + qb.where(deviceProperty.eq(dbDevice.getId()), timestampProperty.ge(timestamp_from)) + .where(timestampProperty.le(timestamp_to)); + List overlayRecords = qb.build().list(); + + for (PebbleHealthActivitySample sample : samples) { + for (PebbleHealthActivityOverlay overlay : overlayRecords) { + if (overlay.getTimestampFrom() <= sample.getTimestamp() && overlay.getTimestampTo() >= sample.getTimestamp()) { + // patch in the raw kind + sample.setRawKind(overlay.getRawKind()); + } + } + } + + return samples; + } + @Override public AbstractDao getSampleDao() { return getSession().getPebbleHealthActivitySampleDao(); @@ -33,7 +71,9 @@ public class PebbleHealthSampleProvider extends AbstractSampleProvider