forked from upstream-mirrors/OpenTracks
Cleanup: KMLTrackImporter doesn't need Position at first.
This commit is contained in:
@@ -137,12 +137,4 @@ public record Position(
|
|||||||
public Position withBearing(Float bearing) {
|
public Position withBearing(Float bearing) {
|
||||||
return new Position(time, latitude, longitude, horizontalAccuracy, altitude, verticalAccuracy, bearing, speed);
|
return new Position(time, latitude, longitude, horizontalAccuracy, altitude, verticalAccuracy, bearing, speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position withHorizontalAccuracy(Distance horizontalAccuracy) {
|
|
||||||
return new Position(time, latitude, longitude, horizontalAccuracy, altitude, verticalAccuracy, bearing, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Position withVerticalAccuracy(Distance verticalAccuracy) {
|
|
||||||
return new Position(time, latitude, longitude, horizontalAccuracy, altitude, verticalAccuracy, bearing, speed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.data.models.Altitude;
|
||||||
import de.dennisguse.opentracks.data.models.AltitudeGainLoss;
|
import de.dennisguse.opentracks.data.models.AltitudeGainLoss;
|
||||||
import de.dennisguse.opentracks.data.models.Cadence;
|
import de.dennisguse.opentracks.data.models.Cadence;
|
||||||
import de.dennisguse.opentracks.data.models.Distance;
|
import de.dennisguse.opentracks.data.models.Distance;
|
||||||
@@ -83,7 +84,6 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
private static final String TAG_PHOTO_OVERLAY = "PhotoOverlay";
|
private static final String TAG_PHOTO_OVERLAY = "PhotoOverlay";
|
||||||
private static final String TAG_PLACEMARK = "Placemark";
|
private static final String TAG_PLACEMARK = "Placemark";
|
||||||
private static final String TAG_STYLE_URL = "styleUrl";
|
private static final String TAG_STYLE_URL = "styleUrl";
|
||||||
// private static final String TAG_VALUE = "value"; TODO
|
|
||||||
private static final String TAG_WHEN = "when";
|
private static final String TAG_WHEN = "when";
|
||||||
private static final String TAG_UUID = "opentracks:trackid";
|
private static final String TAG_UUID = "opentracks:trackid";
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
private ZoneOffset zoneOffset;
|
private ZoneOffset zoneOffset;
|
||||||
|
|
||||||
private final ArrayList<Instant> whenList = new ArrayList<>();
|
private final ArrayList<Instant> whenList = new ArrayList<>();
|
||||||
private final ArrayList<Position> positionList = new ArrayList<>(); //TODO This is only latitude, longitude, and altitude
|
private final ArrayList<LatLngAltitude> positionList = new ArrayList<>();
|
||||||
|
|
||||||
private String dataType;
|
private String dataType;
|
||||||
|
|
||||||
@@ -260,13 +260,21 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Position position = createPosition(latitude, longitude, altitude);
|
LatLngAltitude latLngAltitude = createPosition(latitude, longitude, altitude);
|
||||||
if (position == null) {
|
if (latLngAltitude == null) {
|
||||||
Log.w(TAG, "Marker with invalid coordinates ignored: " + latitude + " " + longitude);
|
Log.w(TAG, "Marker with invalid coordinates ignored: " + latitude + " " + longitude);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
position = position.with(whenList.get(0));
|
Position position = new Position(
|
||||||
|
whenList.get(0),
|
||||||
|
latLngAltitude.latitude,
|
||||||
|
latLngAltitude.longitude,
|
||||||
|
null,
|
||||||
|
latLngAltitude.altitude,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
markers.add(new Marker(
|
markers.add(new Marker(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@@ -320,12 +328,7 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
// Close a track segment by inserting the segment locations
|
// Close a track segment by inserting the segment locations
|
||||||
for (int i = 0; i < positionList.size(); i++) {
|
for (int i = 0; i < positionList.size(); i++) {
|
||||||
Instant time = whenList.get(i);
|
Instant time = whenList.get(i);
|
||||||
Position position = positionList.get(i);
|
LatLngAltitude latLngAltitude = positionList.get(i);
|
||||||
if (position == null) {
|
|
||||||
position = Position.of(time);
|
|
||||||
} else {
|
|
||||||
position = position.with(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
TrackPoint.Type type = null;
|
TrackPoint.Type type = null;
|
||||||
Speed speed = null;
|
Speed speed = null;
|
||||||
@@ -366,6 +369,17 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
verticalAccuracy = Distance.of(accuracyVertical.get(i));
|
verticalAccuracy = Distance.of(accuracyVertical.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Position position = new Position(
|
||||||
|
time,
|
||||||
|
latLngAltitude != null ? latLngAltitude.latitude : null,
|
||||||
|
latLngAltitude != null ? latLngAltitude.longitude : null,
|
||||||
|
horizontalAccuracy,
|
||||||
|
latLngAltitude != null ? latLngAltitude.altitude : null,
|
||||||
|
verticalAccuracy,
|
||||||
|
null,
|
||||||
|
speed
|
||||||
|
);
|
||||||
|
|
||||||
// Update TrackPoint type for START / STOP.
|
// Update TrackPoint type for START / STOP.
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
//first
|
//first
|
||||||
@@ -382,10 +396,7 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
trackImporter.addTrackPoint(new TrackPoint(
|
trackImporter.addTrackPoint(new TrackPoint(
|
||||||
null,
|
null,
|
||||||
type != null ? type : TrackPoint.Type.TRACKPOINT,
|
type != null ? type : TrackPoint.Type.TRACKPOINT,
|
||||||
position
|
position,
|
||||||
.with(speed)
|
|
||||||
.withHorizontalAccuracy(horizontalAccuracy)
|
|
||||||
.withVerticalAccuracy(verticalAccuracy),
|
|
||||||
sensorDistance,
|
sensorDistance,
|
||||||
heartRate,
|
heartRate,
|
||||||
cadence,
|
cadence,
|
||||||
@@ -410,7 +421,7 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
altitude = null;
|
altitude = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Position createPosition(String latitude, String longitude, String altitude) {
|
private LatLngAltitude createPosition(String latitude, String longitude, String altitude) {
|
||||||
//TODO Do not use Location.
|
//TODO Do not use Location.
|
||||||
if (longitude != null && latitude != null) {
|
if (longitude != null && latitude != null) {
|
||||||
Location location = new Location("import");
|
Location location = new Location("import");
|
||||||
@@ -428,7 +439,7 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
throw new ParsingException(createErrorMessage(String.format(Locale.US, "Unable to parse altitude: %s", altitude)), e);
|
throw new ParsingException(createErrorMessage(String.format(Locale.US, "Unable to parse altitude: %s", altitude)), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Position.of(location, null);
|
return new LatLngAltitude(location.getLatitude(), location.getLongitude(), Altitude.WGS84.of(location.getAltitude()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -492,4 +503,11 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
public void cleanImport() {
|
public void cleanImport() {
|
||||||
trackImporter.cleanImport();
|
trackImporter.cleanImport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record LatLngAltitude(
|
||||||
|
double latitude,
|
||||||
|
double longitude,
|
||||||
|
Altitude altitude
|
||||||
|
) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user