From acba91d3c5ca911210f0104d7e8dea99c16ceede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 21 Oct 2023 16:53:34 +0100 Subject: [PATCH] Xiaomi: Refactor daily parser slightly --- .../xiaomi/activity/impl/DailyDetailsParser.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/DailyDetailsParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/DailyDetailsParser.java index 4fb195c28..f5b7f1ad5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/DailyDetailsParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/DailyDetailsParser.java @@ -74,10 +74,14 @@ public class DailyDetailsParser extends XiaomiActivityParser { return false; } + final Calendar timestamp = Calendar.getInstance(); + timestamp.setTime(fileId.getTimestamp()); + final List samples = new ArrayList<>(); while (buf.position() < buf.limit()) { final XiaomiActivitySample sample = new XiaomiActivitySample(); + sample.setTimestamp((int) (timestamp.getTimeInMillis() / 1000)); sample.setSteps(buf.getShort()); @@ -95,12 +99,11 @@ public class DailyDetailsParser extends XiaomiActivityParser { } samples.add(sample); + + timestamp.add(Calendar.MINUTE, 1); } // save all the samples that we got - final Calendar timestamp = Calendar.getInstance(); - timestamp.setTime(fileId.getTimestamp()); - try (DBHandler handler = GBApplication.acquireDB()) { final DaoSession session = handler.getDaoSession(); @@ -113,15 +116,10 @@ public class DailyDetailsParser extends XiaomiActivityParser { for (final XiaomiActivitySample sample : samples) { sample.setDevice(device); sample.setUser(user); - sample.setTimestamp((int) (timestamp.getTimeInMillis() / 1000)); sample.setProvider(sampleProvider); - - timestamp.add(Calendar.MINUTE, 1); } sampleProvider.addGBActivitySamples(samples.toArray(new XiaomiActivitySample[0])); - timestamp.add(Calendar.MINUTE, -1); - return true; } catch (final Exception e) { GB.toast(support.getContext(), "Error saving activity samples", Toast.LENGTH_LONG, GB.ERROR);