forked from upstream-mirrors/OpenTracks
Implemented MarkerIterator.
This commit is contained in:
@@ -238,17 +238,12 @@ public class GPXTrackExporter implements TrackExporter {
|
||||
}
|
||||
|
||||
private void writeMarkers(Track track) throws InterruptedException {
|
||||
try (Cursor cursor = contentProviderUtils.getMarkerCursor(track.getId())) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
for (int i = 0; i < cursor.getCount(); i++) {
|
||||
if (Thread.interrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
Marker marker = contentProviderUtils.createMarker(cursor);
|
||||
writeMarker(track.getZoneOffset(), marker);
|
||||
try (AutoCloseableIterator<Marker> markerIterator = contentProviderUtils.getMarkerIterator(track.getId())) {
|
||||
while (markerIterator.hasNext()) {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
cursor.moveToNext();
|
||||
}
|
||||
|
||||
writeMarker(track.getZoneOffset(), markerIterator.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,21 +136,16 @@ public class KMLTrackExporter implements TrackExporter {
|
||||
|
||||
private void writeMarkers(Track track) throws InterruptedException {
|
||||
boolean hasMarkers = false;
|
||||
try (Cursor cursor = contentProviderUtils.getMarkerCursor(track.getId())) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
for (int i = 0; i < cursor.getCount(); i++) {
|
||||
if (Thread.interrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
if (!hasMarkers) {
|
||||
writeBeginMarkers(track);
|
||||
hasMarkers = true;
|
||||
}
|
||||
Marker marker = contentProviderUtils.createMarker(cursor);
|
||||
writeMarker(marker, track.getZoneOffset());
|
||||
try (AutoCloseableIterator<Marker> markerIterator = contentProviderUtils.getMarkerIterator(track.getId())) {
|
||||
while (markerIterator.hasNext()) {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
cursor.moveToNext();
|
||||
if (!hasMarkers) {
|
||||
writeBeginMarkers(track);
|
||||
hasMarkers = true;
|
||||
}
|
||||
|
||||
writeMarker(markerIterator.next(), track.getZoneOffset());
|
||||
}
|
||||
}
|
||||
if (hasMarkers) {
|
||||
|
||||
@@ -36,6 +36,7 @@ import de.dennisguse.opentracks.data.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.ui.markers.MarkerUtils;
|
||||
import de.dennisguse.opentracks.util.AutoCloseableIterator;
|
||||
import de.dennisguse.opentracks.util.FileUtils;
|
||||
|
||||
/**
|
||||
@@ -89,22 +90,17 @@ public class KMZTrackExporter implements TrackExporter {
|
||||
|
||||
private void addImages(Context context, List<Track> tracks, ZipOutputStream zipOutputStream) throws InterruptedException, IOException {
|
||||
for (Track track : tracks) {
|
||||
try (Cursor cursor = contentProviderUtils.getMarkerCursor(track.getId())) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
for (int i = 0; i < cursor.getCount(); i++) {
|
||||
if (Thread.interrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
Marker marker = contentProviderUtils.createMarker(cursor);
|
||||
if (marker.hasPhoto()) {
|
||||
Uri uriPhoto = marker.getPhotoUrl();
|
||||
boolean existsPhoto = MarkerUtils.buildInternalPhotoFile(context, track.getId(), uriPhoto) != null;
|
||||
if (existsPhoto) {
|
||||
addImage(context, zipOutputStream, uriPhoto, marker);
|
||||
}
|
||||
}
|
||||
try (AutoCloseableIterator<Marker> markerIterator = contentProviderUtils.getMarkerIterator(track.getId())) {
|
||||
while (markerIterator.hasNext()) {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
cursor.moveToNext();
|
||||
Marker marker = markerIterator.next();
|
||||
if (marker.hasPhoto()) {
|
||||
Uri uriPhoto = marker.getPhotoUrl();
|
||||
boolean existsPhoto = MarkerUtils.buildInternalPhotoFile(context, track.getId(), uriPhoto) != null;
|
||||
if (existsPhoto) {
|
||||
addImage(context, zipOutputStream, uriPhoto, marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@@ -38,6 +39,7 @@ import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.data.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.util.AutoCloseableIterator;
|
||||
import de.dennisguse.opentracks.util.FileUtils;
|
||||
|
||||
/**
|
||||
@@ -188,13 +190,14 @@ public class KMZTrackImporter {
|
||||
private void deleteOrphanImages(Track.Id trackId) {
|
||||
// 1.- Gets all photo names in the markers of the track identified by id.
|
||||
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
|
||||
List<Marker> markers = contentProviderUtils.getMarkers(trackId);
|
||||
List<String> photosName = new ArrayList<>();
|
||||
for (Marker marker : markers) {
|
||||
if (marker.hasPhoto()) {
|
||||
String photoUrl = Uri.decode(marker.getPhotoUrl().toString()); //TODO Why Uri.decode()?
|
||||
photosName.add(photoUrl.substring(photoUrl.lastIndexOf(File.separatorChar) + 1));
|
||||
}
|
||||
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()?
|
||||
photosName.add(photoUrl.substring(photoUrl.lastIndexOf(File.separatorChar) + 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 2.- Deletes all orphan photos from external storage.
|
||||
|
||||
Reference in New Issue
Block a user