diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java index a2de4118a..eb2158b6c 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java @@ -111,7 +111,7 @@ public class ExportImportTest { // when // 1. export ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - trackExporter.writeTrack(outputStream); + trackExporter.writeTrack(new Track[]{track}, outputStream); contentProviderUtils.deleteTrack(context, trackId); // 2. import @@ -147,7 +147,7 @@ public class ExportImportTest { // when // 1. export ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - trackExporter.writeTrack(outputStream); + trackExporter.writeTrack(new Track[]{track}, outputStream); contentProviderUtils.deleteTrack(context, trackId); // 2. import @@ -183,7 +183,7 @@ public class ExportImportTest { // when // 1. export ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - trackExporter.writeTrack(outputStream); + trackExporter.writeTrack(new Track[]{track}, outputStream); // 2. import InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); @@ -234,7 +234,7 @@ public class ExportImportTest { // when // 1. export ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - trackExporter.writeTrack(outputStream); + trackExporter.writeTrack(new Track[]{track}, outputStream); contentProviderUtils.deleteTrack(context, trackId); // 2. import @@ -272,7 +272,7 @@ public class ExportImportTest { // when // 1. export ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - trackExporter.writeTrack(outputStream); + trackExporter.writeTrack(new Track[]{track}, outputStream); // 2. import InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); diff --git a/src/main/java/de/dennisguse/opentracks/content/provider/ShareContentProvider.java b/src/main/java/de/dennisguse/opentracks/content/provider/ShareContentProvider.java index 688143d84..e6d47ff09 100644 --- a/src/main/java/de/dennisguse/opentracks/content/provider/ShareContentProvider.java +++ b/src/main/java/de/dennisguse/opentracks/content/provider/ShareContentProvider.java @@ -212,7 +212,7 @@ public class ShareContentProvider extends CustomContentProvider implements ICont PipeDataWriter pipeDataWriter = (output, uri1, mimeType, opts, args) -> { try (FileOutputStream fileOutputStream = new FileOutputStream(output.getFileDescriptor())) { - trackExporter.writeTrack(fileOutputStream); + trackExporter.writeTrack(tracks, fileOutputStream); } catch (IOException e) { Log.w(TAG, "there occurred an error while sharing a file: " + e); } diff --git a/src/main/java/de/dennisguse/opentracks/fragments/ExportProgressDialogFragment.java b/src/main/java/de/dennisguse/opentracks/fragments/ExportProgressDialogFragment.java index a9812db27..e2f834d94 100644 --- a/src/main/java/de/dennisguse/opentracks/fragments/ExportProgressDialogFragment.java +++ b/src/main/java/de/dennisguse/opentracks/fragments/ExportProgressDialogFragment.java @@ -218,7 +218,7 @@ public class ExportProgressDialogFragment extends DialogFragment { } try (OutputStream outputStream = context.getContentResolver().openOutputStream(file.getUri())) { - if (trackExporter.writeTrack(outputStream)) { + if (trackExporter.writeTrack(new Track[]{track}, outputStream)) { return true; } else { if (!file.delete()) { diff --git a/src/main/java/de/dennisguse/opentracks/io/file/TrackFileFormat.java b/src/main/java/de/dennisguse/opentracks/io/file/TrackFileFormat.java index ea51fd60c..5ff2917ac 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/TrackFileFormat.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/TrackFileFormat.java @@ -74,7 +74,7 @@ public enum TrackFileFormat { } public TrackExporter newTrackExporter(Context context, Track[] tracks) { - return newKmzTrackExporter(context, this.newTrackWriter(context, tracks.length > 1), tracks, exportPhotos); + return newKmzTrackExporter(context, this.newTrackWriter(context, tracks.length > 1), exportPhotos); } @Override @@ -101,7 +101,7 @@ public enum TrackFileFormat { } public TrackExporter newTrackExporter(Context context, Track[] tracks) { - return newKmzTrackExporter(context, this.newTrackWriter(context, tracks.length > 1), tracks, exportPhotos); + return newKmzTrackExporter(context, this.newTrackWriter(context, tracks.length > 1), exportPhotos); } @Override @@ -134,7 +134,7 @@ public enum TrackFileFormat { } public TrackExporter newTrackExporter(Context context, Track[] tracks) { - return newKmzTrackExporter(context, this.newTrackWriter(context, tracks.length > 1), tracks, exportPhotos); + return newKmzTrackExporter(context, this.newTrackWriter(context, tracks.length > 1), exportPhotos); } public String getExtension() { @@ -163,7 +163,7 @@ public enum TrackFileFormat { } public TrackExporter newTrackExporter(Context context, Track[] tracks) { - return newKmzTrackExporter(context, newTrackWriter(context, tracks.length > 1), tracks, exportPhotos); + return newKmzTrackExporter(context, newTrackWriter(context, tracks.length > 1), exportPhotos); } public String getExtension() { @@ -196,10 +196,10 @@ public enum TrackFileFormat { private static final String MIME_KML = "application/vnd.google-earth.kml+xml"; - private static TrackExporter newKmzTrackExporter(Context context, TrackWriter trackWriter, Track[] tracks, boolean exportPhotos) { + private static TrackExporter newKmzTrackExporter(Context context, TrackWriter trackWriter, boolean exportPhotos) { ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context); - FileTrackExporter fileTrackExporter = new FileTrackExporter(contentProviderUtils, trackWriter, tracks); + FileTrackExporter fileTrackExporter = new FileTrackExporter(contentProviderUtils, trackWriter); return new KmzTrackExporter(context, contentProviderUtils, fileTrackExporter, exportPhotos); } @@ -212,7 +212,7 @@ public enum TrackFileFormat { public TrackExporter newTrackExporter(Context context, Track[] tracks) { ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context); TrackWriter trackWriter = newTrackWriter(context, tracks.length > 1); - return new FileTrackExporter(contentProviderUtils, trackWriter, tracks); + return new FileTrackExporter(contentProviderUtils, trackWriter); } /** diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/FileTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/FileTrackExporter.java index a9ecd6f3d..c9335155d 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/FileTrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/FileTrackExporter.java @@ -16,7 +16,6 @@ package de.dennisguse.opentracks.io.file.exporter; -import android.content.Context; import android.database.Cursor; import android.util.Log; @@ -42,7 +41,6 @@ public class FileTrackExporter implements TrackExporter { private static final String TAG = FileTrackExporter.class.getSimpleName(); private final ContentProviderUtils contentProviderUtils; - private final Track[] tracks; private final TrackWriter trackWriter; /** @@ -50,16 +48,14 @@ public class FileTrackExporter implements TrackExporter { * * @param contentProviderUtils the content provider utils * @param trackWriter the track writer - * @param tracks the tracks */ - public FileTrackExporter(ContentProviderUtils contentProviderUtils, TrackWriter trackWriter, Track[] tracks) { + public FileTrackExporter(ContentProviderUtils contentProviderUtils, TrackWriter trackWriter) { this.contentProviderUtils = contentProviderUtils; - this.tracks = tracks; this.trackWriter = trackWriter; } @Override - public boolean writeTrack(@NonNull OutputStream outputStream) { + public boolean writeTrack(Track[] tracks, @NonNull OutputStream outputStream) { try { trackWriter.prepare(outputStream); trackWriter.writeHeader(tracks); @@ -126,7 +122,6 @@ public class FileTrackExporter implements TrackExporter { boolean wroteTrack = false; boolean wroteSegment = false; boolean isLastLocationValid = false; - int locationNumber = 0; TrackPoint lastTrackPoint = null; try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false)) { @@ -138,7 +133,6 @@ public class FileTrackExporter implements TrackExporter { TrackPoint trackPoint = trackPointIterator.next(); setLocationTime(trackPoint, offset); - locationNumber++; boolean isLocationValid = LocationUtils.isValidLocation(trackPoint.getLocation()); boolean isSegmentValid = isLocationValid && isLastLocationValid; diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmzTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmzTrackExporter.java index 0c63aadfa..3e1896834 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmzTrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KmzTrackExporter.java @@ -51,7 +51,6 @@ public class KmzTrackExporter implements TrackExporter { private final ContentProviderUtils contentProviderUtils; private final FileTrackExporter fileTrackExporter; - private final Track[] tracks; private final boolean exportPhotos; private Context context; @@ -62,18 +61,16 @@ public class KmzTrackExporter implements TrackExporter { * @param context the context * @param contentProviderUtils the content provider utils * @param trackExporter the file track exporter - * @param tracks the tracks to export */ - public KmzTrackExporter(Context context, ContentProviderUtils contentProviderUtils, FileTrackExporter trackExporter, Track[] tracks, boolean exportPhotos) { + public KmzTrackExporter(Context context, ContentProviderUtils contentProviderUtils, FileTrackExporter trackExporter, boolean exportPhotos) { this.context = context; this.contentProviderUtils = contentProviderUtils; this.fileTrackExporter = trackExporter; - this.tracks = tracks; this.exportPhotos = exportPhotos; } @Override - public boolean writeTrack(@NonNull OutputStream outputStream) { + public boolean writeTrack(Track[] tracks, @NonNull OutputStream outputStream) { ZipOutputStream zipOutputStream = null; try { zipOutputStream = new ZipOutputStream(outputStream); @@ -82,7 +79,7 @@ public class KmzTrackExporter implements TrackExporter { ZipEntry zipEntry = new ZipEntry(KMZ_KML_FILE); zipOutputStream.putNextEntry(zipEntry); - boolean success = fileTrackExporter.writeTrack(zipOutputStream); + boolean success = fileTrackExporter.writeTrack(tracks, zipOutputStream); zipOutputStream.closeEntry(); if (!success) { Log.e(TAG, "Unable to write kml in kmz"); @@ -90,7 +87,7 @@ public class KmzTrackExporter implements TrackExporter { } // Add photos - if (exportPhotos) addImages(context, zipOutputStream); + if (exportPhotos) addImages(context, tracks ,zipOutputStream); return true; } catch (InterruptedException | IOException e) { Log.e(TAG, "Unable to write track", e); @@ -106,7 +103,7 @@ public class KmzTrackExporter implements TrackExporter { } } - private void addImages(Context context, ZipOutputStream zipOutputStream) throws InterruptedException, IOException { + private void addImages(Context context, Track[] tracks, ZipOutputStream zipOutputStream) throws InterruptedException, IOException { for (Track track : tracks) { try (Cursor cursor = contentProviderUtils.getWaypointCursor(track.getId(), -1L, -1)) { if (cursor != null && cursor.moveToFirst()) { diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/TrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/TrackExporter.java index 6553f4640..c87365f5f 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/TrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/TrackExporter.java @@ -16,12 +16,12 @@ package de.dennisguse.opentracks.io.file.exporter; -import android.content.Context; - import androidx.annotation.NonNull; import java.io.OutputStream; +import de.dennisguse.opentracks.content.data.Track; + /** * Track exporting for exporting track to an {@link OutputStream}. * @@ -33,7 +33,8 @@ public interface TrackExporter { * Write track to an output stream. * Depending on the implementation a context might be required. * + * @param tracks * @param outputStream the output stream */ - boolean writeTrack(@NonNull OutputStream outputStream); + boolean writeTrack(Track[] tracks, @NonNull OutputStream outputStream); }