Huawei: fix pace update when more than one packets received

This commit is contained in:
Me7c7 2024-10-13 20:04:58 +03:00 committed by José Rebelo
parent 0e6a3e13cc
commit 80967ce42b
3 changed files with 10 additions and 8 deletions

View File

@ -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);

View File

@ -1672,19 +1672,21 @@ public class HuaweiSupportProvider {
}
}
public void addWorkoutPaceData(Long workoutId, List<Workout.WorkoutPace.Response.Block> paceList) {
public void addWorkoutPaceData(Long workoutId, List<Workout.WorkoutPace.Response.Block> paceList, short number) {
if (workoutId == null)
return;
try (DBHandler db = GBApplication.acquireDB()) {
HuaweiWorkoutPaceSampleDao dao = db.getDaoSession().getHuaweiWorkoutPaceSampleDao();
if(number == 0) {
final DeleteQuery<HuaweiWorkoutPaceSample> 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;

View File

@ -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(