From 80967ce42bfbf93f9cd482762218273eea189874 Mon Sep 17 00:00:00 2001 From: Me7c7 Date: Sun, 13 Oct 2024 20:04:58 +0300 Subject: [PATCH] Huawei: fix pace update when more than one packets received --- .../database/schema/GadgetbridgeUpdate_83.java | 2 +- .../devices/huawei/HuaweiSupportProvider.java | 14 ++++++++------ .../huawei/requests/GetWorkoutPaceRequest.java | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_83.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_83.java index defa85732..17c995baf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_83.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_83.java @@ -32,7 +32,7 @@ public class GadgetbridgeUpdate_83 implements DBUpdateScript { + HuaweiWorkoutPaceSampleDao.Properties.Pace.columnName + "," + HuaweiWorkoutPaceSampleDao.Properties.PointIndex.columnName + "," + HuaweiWorkoutPaceSampleDao.Properties.Correction.columnName + ") " - + " SELECT WORKOUT_ID, 0, DISTANCE, TYPE, PACE, 0, CORRECTION FROM " +HuaweiWorkoutPaceSampleDao.TABLENAME + "_temp;"; + + " SELECT WORKOUT_ID, -1, DISTANCE, TYPE, PACE, 0, CORRECTION FROM " +HuaweiWorkoutPaceSampleDao.TABLENAME + "_temp;"; db.execSQL(MIGATE_DATA); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java index 8cce53cd1..9acb23186 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java @@ -1672,19 +1672,21 @@ public class HuaweiSupportProvider { } } - public void addWorkoutPaceData(Long workoutId, List paceList) { + public void addWorkoutPaceData(Long workoutId, List paceList, short number) { if (workoutId == null) return; try (DBHandler db = GBApplication.acquireDB()) { HuaweiWorkoutPaceSampleDao dao = db.getDaoSession().getHuaweiWorkoutPaceSampleDao(); - final DeleteQuery tableDeleteQuery = dao.queryBuilder() - .where(HuaweiWorkoutPaceSampleDao.Properties.WorkoutId.eq(workoutId)) - .buildDelete(); - tableDeleteQuery.executeDeleteWithoutDetachingEntities(); + if(number == 0) { + final DeleteQuery tableDeleteQuery = dao.queryBuilder() + .where(HuaweiWorkoutPaceSampleDao.Properties.WorkoutId.eq(workoutId)) + .buildDelete(); + tableDeleteQuery.executeDeleteWithoutDetachingEntities(); + } - int paceIndex = 0; + int paceIndex = (int) dao.queryBuilder().where(HuaweiWorkoutPaceSampleDao.Properties.WorkoutId.eq(workoutId)).count(); for (Workout.WorkoutPace.Response.Block block : paceList) { Integer correction = block.hasCorrection ? (int) block.correction : null; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutPaceRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutPaceRequest.java index e8b1ab8bd..b9e3fa596 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutPaceRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutPaceRequest.java @@ -77,7 +77,7 @@ public class GetWorkoutPaceRequest extends Request { LOG.info("Block num: " + packet.blocks.size()); LOG.info("Blocks : " + Arrays.toString(packet.blocks.toArray())); - supportProvider.addWorkoutPaceData(this.databaseId, packet.blocks); + supportProvider.addWorkoutPaceData(this.databaseId, packet.blocks, packet.paceNumber); if (this.workoutNumbers.paceCount > this.number + 1) { GetWorkoutPaceRequest nextRequest = new GetWorkoutPaceRequest(