mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-19 22:00:53 +02:00
Amazfit Bip: do not export GPX tracks if there is no point in the track
The approach ignores the activity types and only uses the presence of valid lon/lan points in the track to create the GPX file or not.
This commit is contained in:
parent
cd029e4853
commit
27caa08a1b
@ -80,6 +80,8 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
|||||||
String gpxTrack = summary.getGpxTrack();
|
String gpxTrack = summary.getGpxTrack();
|
||||||
if (gpxTrack != null) {
|
if (gpxTrack != null) {
|
||||||
showTrack(gpxTrack);
|
showTrack(gpxTrack);
|
||||||
|
} else {
|
||||||
|
GB.toast("This activity does not contain GPX tracks.", Toast.LENGTH_LONG, GB.INFO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,8 @@ public interface ActivityTrackExporter {
|
|||||||
@NonNull
|
@NonNull
|
||||||
String getDefaultFileName(@NonNull ActivityTrack track);
|
String getDefaultFileName(@NonNull ActivityTrack track);
|
||||||
|
|
||||||
void performExport(ActivityTrack track, File targetFile) throws IOException;
|
void performExport(ActivityTrack track, File targetFile) throws IOException, GPXTrackEmptyException;
|
||||||
|
|
||||||
|
class GPXTrackEmptyException extends Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performExport(ActivityTrack track, File targetFile) throws IOException {
|
public void performExport(ActivityTrack track, File targetFile) throws IOException, GPXTrackEmptyException {
|
||||||
String encoding = StandardCharsets.UTF_8.name();
|
String encoding = StandardCharsets.UTF_8.name();
|
||||||
XmlSerializer ser = Xml.newSerializer();
|
XmlSerializer ser = Xml.newSerializer();
|
||||||
try {
|
try {
|
||||||
@ -80,14 +80,19 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
return DateTimeUtils.formatIso8601(date);
|
return DateTimeUtils.formatIso8601(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportTrack(XmlSerializer ser, ActivityTrack track) throws IOException {
|
private void exportTrack(XmlSerializer ser, ActivityTrack track) throws IOException, GPXTrackEmptyException {
|
||||||
ser.startTag(NS_DEFAULT, "trk");
|
ser.startTag(NS_DEFAULT, "trk");
|
||||||
ser.startTag(NS_DEFAULT, "trkseg");
|
ser.startTag(NS_DEFAULT, "trkseg");
|
||||||
|
|
||||||
List<ActivityPoint> trackPoints = track.getTrackPoints();
|
List<ActivityPoint> trackPoints = track.getTrackPoints();
|
||||||
String source = getSource(track);
|
String source = getSource(track);
|
||||||
|
boolean atLeastOnePointExported = false;
|
||||||
for (ActivityPoint point : trackPoints) {
|
for (ActivityPoint point : trackPoints) {
|
||||||
exportTrackPoint(ser, point, source);
|
atLeastOnePointExported = exportTrackPoint(ser, point, source) | atLeastOnePointExported ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!atLeastOnePointExported) {
|
||||||
|
throw new GPXTrackEmptyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
ser.endTag(NS_DEFAULT, "trkseg");
|
ser.endTag(NS_DEFAULT, "trkseg");
|
||||||
@ -98,10 +103,10 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
return track.getDevice().getName();
|
return track.getDevice().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportTrackPoint(XmlSerializer ser, ActivityPoint point, String source) throws IOException {
|
private boolean exportTrackPoint(XmlSerializer ser, ActivityPoint point, String source) throws IOException {
|
||||||
GPSCoordinate location = point.getLocation();
|
GPSCoordinate location = point.getLocation();
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
return; // skip invalid points, that just contain hr data, for example
|
return false; // skip invalid points, that just contain hr data, for example
|
||||||
}
|
}
|
||||||
ser.startTag(NS_DEFAULT, "trkpt");
|
ser.startTag(NS_DEFAULT, "trkpt");
|
||||||
ser.attribute(NS_DEFAULT, "lon", formatLocation(location.getLongitude()));
|
ser.attribute(NS_DEFAULT, "lon", formatLocation(location.getLongitude()));
|
||||||
@ -117,6 +122,8 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
exportTrackpointExtensions(ser, point);
|
exportTrackpointExtensions(ser, point);
|
||||||
|
|
||||||
ser.endTag(NS_DEFAULT, "trkpt");
|
ser.endTag(NS_DEFAULT, "trkpt");
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportTrackpointExtensions(XmlSerializer ser, ActivityPoint point) throws IOException {
|
private void exportTrackpointExtensions(XmlSerializer ser, ActivityPoint point) throws IOException {
|
||||||
|
@ -100,12 +100,18 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
|||||||
ActivityTrackExporter exporter = createExporter();
|
ActivityTrackExporter exporter = createExporter();
|
||||||
String fileName = FileUtils.makeValidFileName("gadgetbridge-track-" + DateTimeUtils.formatIso8601(summary.getStartTime()));
|
String fileName = FileUtils.makeValidFileName("gadgetbridge-track-" + DateTimeUtils.formatIso8601(summary.getStartTime()));
|
||||||
File targetFile = new File(FileUtils.getExternalFilesDir(), fileName);
|
File targetFile = new File(FileUtils.getExternalFilesDir(), fileName);
|
||||||
exporter.performExport(track, targetFile);
|
|
||||||
|
|
||||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
try {
|
||||||
summary.setGpxTrack(targetFile.getAbsolutePath());
|
exporter.performExport(track, targetFile);
|
||||||
dbHandler.getDaoSession().getBaseActivitySummaryDao().update(summary);
|
|
||||||
|
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||||
|
summary.setGpxTrack(targetFile.getAbsolutePath());
|
||||||
|
dbHandler.getDaoSession().getBaseActivitySummaryDao().update(summary);
|
||||||
|
}
|
||||||
|
} catch (ActivityTrackExporter.GPXTrackEmptyException ex) {
|
||||||
|
GB.toast(getContext(), "This activity does not contain GPX tracks.", Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
GregorianCalendar endTime = BLETypeConversions.createCalendar();
|
GregorianCalendar endTime = BLETypeConversions.createCalendar();
|
||||||
endTime.setTime(summary.getEndTime());
|
endTime.setTime(summary.getEndTime());
|
||||||
saveLastSyncTimestamp(endTime);
|
saveLastSyncTimestamp(endTime);
|
||||||
|
Loading…
Reference in New Issue
Block a user