1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-09 03:37:03 +01:00

Huawei: Do not get GPS files in parallel

This commit is contained in:
Martin.JM 2024-09-23 03:09:46 +02:00
parent 159ebfd891
commit 69c2f12acb
4 changed files with 81 additions and 43 deletions

View File

@ -1314,23 +1314,21 @@ public class HuaweiSupportProvider {
}
getWorkoutCountRequest.setFinalizeReq(new RequestCallback() {
@Override
public void call() {
syncState.setWorkoutSync(false);
}
@Override
public void handleException(Request.ResponseParseException e) {
LOG.error("Workout parsing exception", e);
syncState.setWorkoutSync(false);
// This is propagated through the workout requests, hence the slightly generic error message
GB.toast(context, "Exception synchronizing workout", Toast.LENGTH_SHORT, GB.ERROR);
LOG.error("Exception synchronizing workout", e);
endOfWorkoutSync();
}
});
try {
getWorkoutCountRequest.doPerform();
} catch (IOException e) {
LOG.error("Exception on starting workout count request", e);
syncState.setWorkoutSync(false);
GB.toast(context, "Exception synchronizing workout", Toast.LENGTH_SHORT, GB.ERROR);
LOG.error("Error sending workout count - showing user that the workout sync failed", e);
endOfWorkoutSync();
}
}
@ -2148,7 +2146,11 @@ public class HuaweiSupportProvider {
return true;
}
public void downloadWorkoutGpsFiles(short workoutId, Long databaseId) {
public void endOfWorkoutSync() {
this.syncState.setWorkoutSync(false);
}
public void downloadWorkoutGpsFiles(short workoutId, Long databaseId, Runnable extraCallbackAction) {
syncState.startWorkoutGpsDownload();
huaweiFileDownloadManager.addToQueue(HuaweiFileDownloadManager.FileRequest.workoutGpsFileRequest(
@ -2159,6 +2161,7 @@ public class HuaweiSupportProvider {
@Override
public void downloadComplete(HuaweiFileDownloadManager.FileRequest fileRequest) {
syncState.stopWorkoutGpsDownload();
extraCallbackAction.run();
if (fileRequest.getData().length == 0) {
LOG.debug("GPS file empty");
@ -2256,6 +2259,8 @@ public class HuaweiSupportProvider {
public void downloadException(HuaweiFileDownloadManager.HuaweiFileDownloadException e) {
super.downloadException(e);
syncState.stopWorkoutGpsDownload();
extraCallbackAction.run();
}
}
), true);

View File

@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@ -113,17 +114,27 @@ public class GetWorkoutDataRequest extends Request {
this.nextRequest(nextRequest);
} else {
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId);
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId);
if (!remainder.isEmpty()) {
GetWorkoutTotalsRequest nextRequest = new GetWorkoutTotalsRequest(
this.supportProvider,
remainder.remove(0),
remainder
);
nextRequest.setFinalizeReq(this.finalizeReq);
this.nextRequest(nextRequest);
}
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() {
@Override
public void run() {
if (!remainder.isEmpty()) {
GetWorkoutTotalsRequest nextRequest = new GetWorkoutTotalsRequest(
GetWorkoutDataRequest.this.supportProvider,
remainder.remove(0),
remainder
);
nextRequest.setFinalizeReq(GetWorkoutDataRequest.this.finalizeReq);
// Cannot do this with nextRequest because it's in a callback
try {
nextRequest.doPerform();
} catch (IOException e) {
finalizeReq.handleException(new ResponseParseException("Cannot send next request", e));
}
} else {
supportProvider.endOfWorkoutSync();
}
}
});
}
}
}

View File

@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@ -90,17 +91,27 @@ public class GetWorkoutPaceRequest extends Request {
this.nextRequest(nextRequest);
} else {
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId);
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId);
if (!remainder.isEmpty()) {
GetWorkoutTotalsRequest nextRequest = new GetWorkoutTotalsRequest(
this.supportProvider,
remainder.remove(0),
remainder
);
nextRequest.setFinalizeReq(this.finalizeReq);
this.nextRequest(nextRequest);
}
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() {
@Override
public void run() {
if (!remainder.isEmpty()) {
GetWorkoutTotalsRequest nextRequest = new GetWorkoutTotalsRequest(
GetWorkoutPaceRequest.this.supportProvider,
remainder.remove(0),
remainder
);
nextRequest.setFinalizeReq(GetWorkoutPaceRequest.this.finalizeReq);
// Cannot do this with nextRequest because it's in a callback
try {
nextRequest.doPerform();
} catch (IOException e) {
finalizeReq.handleException(new ResponseParseException("Cannot send next request", e));
}
} else {
supportProvider.endOfWorkoutSync();
}
}
});
}
}
}

View File

@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
@ -104,17 +105,27 @@ public class GetWorkoutTotalsRequest extends Request {
this.nextRequest(nextRequest);
} else {
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(databaseId);
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, databaseId);
if (!remainder.isEmpty()) {
GetWorkoutTotalsRequest nextRequest = new GetWorkoutTotalsRequest(
this.supportProvider,
remainder.remove(0),
remainder
);
nextRequest.setFinalizeReq(this.finalizeReq);
this.nextRequest(nextRequest);
}
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, databaseId, new Runnable() {
@Override
public void run() {
if (!remainder.isEmpty()) {
GetWorkoutTotalsRequest nextRequest = new GetWorkoutTotalsRequest(
GetWorkoutTotalsRequest.this.supportProvider,
remainder.remove(0),
remainder
);
nextRequest.setFinalizeReq(GetWorkoutTotalsRequest.this.finalizeReq);
// Cannot do this with nextRequest because it's in a callback
try {
nextRequest.doPerform();
} catch (IOException e) {
finalizeReq.handleException(new ResponseParseException("Cannot send next request", e));
}
} else {
supportProvider.endOfWorkoutSync();
}
}
});
}
}
}