forked from upstream-mirrors/OpenTracks
Marker is now a record.
This commit is contained in:
@@ -250,14 +250,14 @@ public class GPXTrackExporter implements TrackExporter {
|
||||
}
|
||||
|
||||
private void writeMarker(ZoneOffset zoneOffset, Marker marker) {
|
||||
printWriter.println("<wpt " + formatLocation(marker.getPosition()) + ">");
|
||||
if (marker.hasAltitude()) {
|
||||
printWriter.println("<ele>" + ALTITUDE_FORMAT.format(marker.getAltitude().toM()) + "</ele>");
|
||||
printWriter.println("<wpt " + formatLocation(marker.position()) + ">");
|
||||
if (marker.position().hasAltitude()) {
|
||||
printWriter.println("<ele>" + ALTITUDE_FORMAT.format(marker.position().altitude().toM()) + "</ele>");
|
||||
}
|
||||
printWriter.println("<time>" + StringUtils.formatDateTimeIso8601(marker.getTime(), zoneOffset) + "</time>");
|
||||
printWriter.println("<name>" + StringUtils.formatCData(marker.getName()) + "</name>");
|
||||
printWriter.println("<desc>" + StringUtils.formatCData(marker.getDescription()) + "</desc>");
|
||||
printWriter.println("<type>" + StringUtils.formatCData(marker.getCategory()) + "</type>"); //TODO This is localized; may be better to export in English only. See #1608
|
||||
printWriter.println("<time>" + StringUtils.formatDateTimeIso8601(marker.position().time(), zoneOffset) + "</time>");
|
||||
printWriter.println("<name>" + StringUtils.formatCData(marker.name()) + "</name>");
|
||||
printWriter.println("<desc>" + StringUtils.formatCData(marker.description()) + "</desc>");
|
||||
printWriter.println("<type>" + StringUtils.formatCData(marker.category()) + "</type>"); //TODO This is localized; may be better to export in English only. See #1608
|
||||
printWriter.println("</wpt>");
|
||||
}
|
||||
|
||||
|
||||
@@ -266,11 +266,11 @@ public class KMLTrackExporter implements TrackExporter {
|
||||
}
|
||||
|
||||
private void writeMarker(Marker marker, ZoneOffset zoneOffset) {
|
||||
boolean existsPhoto = MarkerUtils.buildInternalPhotoFile(context, marker.getTrackId(), marker.getPhotoUrl()) != null;
|
||||
if (marker.hasPhoto() && exportPhotos && existsPhoto) {
|
||||
boolean existsPhoto = MarkerUtils.buildInternalPhotoFile(context, marker.trackId(), marker.photoUrl()) != null;
|
||||
if (marker.photoUrl() != null && exportPhotos && existsPhoto) {
|
||||
writePhotoOverlay(marker, zoneOffset);
|
||||
} else {
|
||||
writePlacemark(marker.getName(), marker.getCategory(), marker.getDescription(), marker.getPosition(), marker.getTime(), zoneOffset);
|
||||
writePlacemark(marker.name(), marker.category(), marker.description(), marker.position(), marker.position().time(), zoneOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,17 +428,17 @@ public class KMLTrackExporter implements TrackExporter {
|
||||
|
||||
private void writePhotoOverlay(Marker marker, ZoneOffset zoneOffset) {
|
||||
printWriter.println("<PhotoOverlay>");
|
||||
printWriter.println("<name>" + StringUtils.formatCData(marker.getName()) + "</name>");
|
||||
printWriter.println("<description>" + StringUtils.formatCData(marker.getDescription()) + "</description>");
|
||||
printWriter.println("<name>" + StringUtils.formatCData(marker.name()) + "</name>");
|
||||
printWriter.println("<description>" + StringUtils.formatCData(marker.description()) + "</description>");
|
||||
printWriter.print("<Camera>");
|
||||
printWriter.print("<longitude>" + marker.getPosition().longitude() + "</longitude>");
|
||||
printWriter.print("<latitude>" + marker.getPosition().latitude() + "</latitude>");
|
||||
printWriter.print("<longitude>" + marker.position().longitude() + "</longitude>");
|
||||
printWriter.print("<latitude>" + marker.position().latitude() + "</latitude>");
|
||||
printWriter.print("<altitude>20</altitude>");
|
||||
printWriter.print("<tilt>90</tilt>");
|
||||
printWriter.println("</Camera>");
|
||||
printWriter.println("<TimeStamp><when>" + getTime(zoneOffset, marker.getTime()) + "</when></TimeStamp>");
|
||||
printWriter.println("<TimeStamp><when>" + getTime(zoneOffset, marker.position().time()) + "</when></TimeStamp>");
|
||||
printWriter.println("<styleUrl>#" + MARKER_STYLE + "</styleUrl>");
|
||||
writeTypeLocalized(marker.getCategory());
|
||||
writeTypeLocalized(marker.category());
|
||||
|
||||
if (exportPhotos) {
|
||||
printWriter.println("<Icon><href>" + KMZTrackExporter.buildKmzImageFilePath(marker) + "</href></Icon>");
|
||||
@@ -452,7 +452,7 @@ public class KMLTrackExporter implements TrackExporter {
|
||||
printWriter.print("<topFov>45</topFov>");
|
||||
printWriter.println("</ViewVolume>");
|
||||
printWriter.println("<Point>");
|
||||
printWriter.println("<coordinates>" + getCoordinates(marker.getPosition(), ",") + "</coordinates>");
|
||||
printWriter.println("<coordinates>" + getCoordinates(marker.position(), ",") + "</coordinates>");
|
||||
printWriter.println("</Point>");
|
||||
printWriter.println("</PhotoOverlay>");
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ public class KMZTrackExporter implements TrackExporter {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
Marker marker = markerIterator.next();
|
||||
if (marker.hasPhoto()) {
|
||||
Uri uriPhoto = marker.getPhotoUrl();
|
||||
if (marker.photoUrl() != null) {
|
||||
Uri uriPhoto = marker.photoUrl();
|
||||
boolean existsPhoto = MarkerUtils.buildInternalPhotoFile(context, track.id(), uriPhoto) != null;
|
||||
if (existsPhoto) {
|
||||
addImage(context, zipOutputStream, uriPhoto, marker);
|
||||
@@ -135,8 +135,8 @@ public class KMZTrackExporter implements TrackExporter {
|
||||
* Builds and returns the path for the image that will be saved inside KMZ_IMAGES_DIR for the marker.
|
||||
*/
|
||||
public static String buildKmzImageFilePath(Marker marker) {
|
||||
String ext = FileUtils.getExtension(marker.getPhotoUrl());
|
||||
String ext = FileUtils.getExtension(marker.photoUrl());
|
||||
ext = ext == null ? "" : "." + ext;
|
||||
return KMZ_IMAGES_DIR + File.separatorChar + FileUtils.sanitizeFileName(marker.getId().id() + ext);
|
||||
return KMZ_IMAGES_DIR + File.separatorChar + FileUtils.sanitizeFileName(marker.id().id() + ext);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import java.util.Locale;
|
||||
import de.dennisguse.opentracks.data.models.Altitude;
|
||||
import de.dennisguse.opentracks.data.models.Distance;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.MarkerBuilder;
|
||||
import de.dennisguse.opentracks.data.models.Position;
|
||||
import de.dennisguse.opentracks.data.models.Speed;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
@@ -429,22 +430,16 @@ public class GPXTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
||||
Log.w(TAG, "Marker with invalid coordinates ignored: " + trackPoint.getPosition());
|
||||
return;
|
||||
}
|
||||
Marker marker = new Marker(null, trackPoint);
|
||||
|
||||
if (name != null) {
|
||||
marker.setName(name);
|
||||
}
|
||||
if (description != null) {
|
||||
marker.setDescription(description);
|
||||
}
|
||||
if (markerType != null) {
|
||||
marker.setCategory(markerType);
|
||||
}
|
||||
|
||||
if (photoUrl != null) {
|
||||
marker.setPhotoUrl(photoUrl);
|
||||
}
|
||||
markers.add(marker);
|
||||
markers.add(new Marker(
|
||||
null,
|
||||
null,
|
||||
name != null ? name : "",
|
||||
description != null ? description : "",
|
||||
markerType != null ? markerType : "",
|
||||
null,
|
||||
trackPoint.getPosition(),
|
||||
photoUrl
|
||||
));
|
||||
}
|
||||
|
||||
private String createErrorMessage(String message) {
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.Locale;
|
||||
|
||||
import de.dennisguse.opentracks.data.models.Distance;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.MarkerBuilder;
|
||||
import de.dennisguse.opentracks.data.models.Position;
|
||||
import de.dennisguse.opentracks.data.models.Speed;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
@@ -263,12 +264,16 @@ public class KMLTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
||||
}
|
||||
position = position.with(whenList.get(0));
|
||||
|
||||
Marker marker = new Marker(null, new TrackPoint(TrackPoint.Type.TRACKPOINT, position)); //TODO Creating marker without need
|
||||
marker.setName(name != null ? name : "");
|
||||
marker.setDescription(description != null ? description : "");
|
||||
marker.setCategory(activityTypeLocalized != null ? activityTypeLocalized : "");
|
||||
marker.setPhotoUrl(photoUrl);
|
||||
markers.add(marker);
|
||||
markers.add(new Marker(
|
||||
null,
|
||||
null,
|
||||
name != null ? name : "",
|
||||
description != null ? description : "",
|
||||
activityTypeLocalized != null ? activityTypeLocalized : "",
|
||||
null,
|
||||
position,
|
||||
photoUrl
|
||||
));
|
||||
|
||||
name = null;
|
||||
description = null;
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.zip.ZipInputStream;
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.data.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.MarkerBuilder;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.util.AutoCloseableIterator;
|
||||
import de.dennisguse.opentracks.util.FileUtils;
|
||||
@@ -191,8 +192,8 @@ public class KMZTrackImporter {
|
||||
List<String> photosName = new ArrayList<>();
|
||||
try (AutoCloseableIterator<Marker> markerIterator = new ContentProviderUtils(context).getMarkerIterator(trackId)) {
|
||||
markerIterator.forEachRemaining(marker -> {
|
||||
if (marker.hasPhoto()) {
|
||||
String photoUrl = Uri.decode(marker.getPhotoUrl().toString()); //TODO Why Uri.decode()?
|
||||
if (marker.photoUrl() != null) {
|
||||
String photoUrl = Uri.decode(marker.photoUrl().toString()); //TODO Why Uri.decode()?
|
||||
photosName.add(photoUrl.substring(photoUrl.lastIndexOf(File.separatorChar) + 1));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -23,6 +23,7 @@ import de.dennisguse.opentracks.data.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.data.models.ActivityType;
|
||||
import de.dennisguse.opentracks.data.models.Distance;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.MarkerBuilder;
|
||||
import de.dennisguse.opentracks.data.models.Speed;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.data.models.TrackBuilder;
|
||||
@@ -58,7 +59,7 @@ public class TrackImporter {
|
||||
// Current track
|
||||
private TrackData trackData;
|
||||
private final List<TrackPoint> trackPoints = new LinkedList<>();
|
||||
private final List<Marker> markers = new LinkedList<>();
|
||||
private final List<MarkerBuilder> markers = new LinkedList<>();
|
||||
|
||||
public TrackImporter(Context context, ContentProviderUtils contentProviderUtils, Distance maxRecordingDistance, boolean preventReimport) {
|
||||
this.context = context;
|
||||
@@ -86,7 +87,7 @@ public class TrackImporter {
|
||||
}
|
||||
|
||||
void addMarkers(List<Marker> markers) {
|
||||
this.markers.addAll(markers);
|
||||
this.markers.addAll(markers.stream().map(MarkerBuilder::new).toList());
|
||||
}
|
||||
|
||||
void setTrackData(Context context, String name, String uuid, String description, String activityTypeLocalized, String activityTypeId, @Nullable ZoneOffset zoneOffset) {
|
||||
@@ -165,10 +166,8 @@ public class TrackImporter {
|
||||
|
||||
// Store Markers
|
||||
updateMarkers(trackId);
|
||||
for (Marker marker : markers)
|
||||
marker.setTrackId(trackId); //TODO Should happen in bulkInsertMarkers
|
||||
|
||||
contentProviderUtils.bulkInsertMarkers(markers, trackId);
|
||||
contentProviderUtils.bulkInsertMarkers(markers.stream().map(it -> it.getMarker()).toList(), trackId);
|
||||
|
||||
//Clear up.
|
||||
trackPoints.clear();
|
||||
|
||||
Reference in New Issue
Block a user