1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 12:26:48 +01:00

Zepp OS: Start new GPX segments on pause/resume

This commit is contained in:
José Rebelo 2023-05-14 16:22:32 +01:00
parent a8b9d22313
commit 76d99f1c33
5 changed files with 43 additions and 22 deletions

View File

@ -114,20 +114,26 @@ public class GPXExporter implements ActivityTrackExporter {
ser.startTag(NS_GPX_URI, OPENTRACKS_PREFIX + ":trackid").text(uuid).endTag(NS_GPX_URI, OPENTRACKS_PREFIX + ":trackid");
ser.endTag(NS_GPX_URI, "extensions");
ser.startTag(NS_GPX_URI, "trkseg");
List<ActivityPoint> trackPoints = track.getTrackPoints();
List<List<ActivityPoint>> segments = track.getSegments();
String source = getSource(track);
boolean atLeastOnePointExported = false;
for (ActivityPoint point : trackPoints) {
atLeastOnePointExported |= exportTrackPoint(ser, point, source, trackPoints);
for (List<ActivityPoint> segment : segments) {
if (segment.isEmpty()) {
// Skip empty segments
continue;
}
ser.startTag(NS_GPX_URI, "trkseg");
for (ActivityPoint point : segment) {
atLeastOnePointExported |= exportTrackPoint(ser, point, source, segment);
}
ser.endTag(NS_GPX_URI, "trkseg");
}
if(!atLeastOnePointExported) {
if (!atLeastOnePointExported) {
throw new GPXTrackEmptyException();
}
ser.endTag(NS_GPX_URI, "trkseg");
ser.endTag(NS_GPX_URI, "trk");
}

View File

@ -28,7 +28,10 @@ public class ActivityTrack {
private Device device;
private User user;
private String name;
private List<ActivityPoint> currentSegment = new ArrayList<>();
private List<List<ActivityPoint>> segments = new ArrayList<List<ActivityPoint>>() {{
add(currentSegment);
}};
public void setBaseTime(Date baseTime) {
this.baseTime = baseTime;
@ -50,18 +53,23 @@ public class ActivityTrack {
this.user = user;
}
public void setTrackPoints(List<ActivityPoint> trackPoints) {
this.trackPoints = trackPoints;
/**
* Add a track point to the current segment.
*/
public void addTrackPoint(final ActivityPoint point) {
currentSegment.add(point);
}
private List<ActivityPoint> trackPoints = new ArrayList<>();
public void addTrackPoint(ActivityPoint point) {
trackPoints.add(point);
public void startNewSegment() {
// Only really start a new segment if the current one is not empty
if (!currentSegment.isEmpty()) {
currentSegment = new ArrayList<>();
segments.add(currentSegment);
}
}
public List<ActivityPoint> getTrackPoints() {
return trackPoints;
public List<List<ActivityPoint>> getSegments() {
return segments;
}
public Date getBaseTime() {

View File

@ -207,9 +207,11 @@ public class Huami2021ActivityDetailsParser extends AbstractHuamiActivityDetails
break;
case 4:
status = "pause";
activityTrack.startNewSegment();
break;
case 5:
status = "resume";
activityTrack.startNewSegment();
break;
case 6:
status = "stop";

View File

@ -135,7 +135,11 @@ public class HuamiActivityDetailsParser extends AbstractHuamiActivityDetailsPars
private void fixupMissingTimestamps(ActivityTrack activityTrack) {
try {
int pointer = 0;
List<ActivityPoint> activityPointList = activityTrack.getTrackPoints();
List<ActivityPoint> activityPointList = new ArrayList<>();
for (List<ActivityPoint> segment : activityTrack.getSegments()) {
activityPointList.addAll(segment);
}
Date gpsStartTime = null;
List<ActivityPoint> entriesToFixUp = new ArrayList<>();
while (pointer < activityPointList.size() - 1) {

View File

@ -45,8 +45,9 @@ public class HuamiActivityDetailsParserTest extends TestBase {
assertEquals("SuperBand 2000", track.getDevice().getName());
assertEquals("Elvis", track.getUser().getName());
List<ActivityPoint> trackPoints = track.getTrackPoints();
assertEquals(972, trackPoints.size());
List<List<ActivityPoint>> segments = track.getSegments();
assertEquals(1, segments.size());
assertEquals(972, segments.get(0).size());
}
}
@ -84,9 +85,9 @@ public class HuamiActivityDetailsParserTest extends TestBase {
try (InputStream in = getContents(DETAILS_1)) {
ActivityTrack track = parser.parse(FileUtils.readAll(in, MAX_DETAILS));
List<ActivityPoint> trackPoints = track.getTrackPoints();
assertEquals(972, trackPoints.size());
List<List<ActivityPoint>> segments = track.getSegments();
assertEquals(1, segments.size());
assertEquals(972, segments.get(0).size());
GPXExporter exporter = new GPXExporter();
exporter.setIncludeHeartRate(false);