forked from upstream-mirrors/OpenTracks
add overload for exporter that takes single track
This commit is contained in:
+5
-5
@@ -111,7 +111,7 @@ public class ExportImportTest {
|
|||||||
// when
|
// when
|
||||||
// 1. export
|
// 1. export
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
trackExporter.writeTrack(new Track[]{track}, outputStream);
|
trackExporter.writeTrack(track, outputStream);
|
||||||
contentProviderUtils.deleteTrack(context, trackId);
|
contentProviderUtils.deleteTrack(context, trackId);
|
||||||
|
|
||||||
// 2. import
|
// 2. import
|
||||||
@@ -147,7 +147,7 @@ public class ExportImportTest {
|
|||||||
// when
|
// when
|
||||||
// 1. export
|
// 1. export
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
trackExporter.writeTrack(new Track[]{track}, outputStream);
|
trackExporter.writeTrack(track, outputStream);
|
||||||
contentProviderUtils.deleteTrack(context, trackId);
|
contentProviderUtils.deleteTrack(context, trackId);
|
||||||
|
|
||||||
// 2. import
|
// 2. import
|
||||||
@@ -183,7 +183,7 @@ public class ExportImportTest {
|
|||||||
// when
|
// when
|
||||||
// 1. export
|
// 1. export
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
trackExporter.writeTrack(new Track[]{track}, outputStream);
|
trackExporter.writeTrack(track, outputStream);
|
||||||
|
|
||||||
// 2. import
|
// 2. import
|
||||||
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
@@ -234,7 +234,7 @@ public class ExportImportTest {
|
|||||||
// when
|
// when
|
||||||
// 1. export
|
// 1. export
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
trackExporter.writeTrack(new Track[]{track}, outputStream);
|
trackExporter.writeTrack(track, outputStream);
|
||||||
contentProviderUtils.deleteTrack(context, trackId);
|
contentProviderUtils.deleteTrack(context, trackId);
|
||||||
|
|
||||||
// 2. import
|
// 2. import
|
||||||
@@ -272,7 +272,7 @@ public class ExportImportTest {
|
|||||||
// when
|
// when
|
||||||
// 1. export
|
// 1. export
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
trackExporter.writeTrack(new Track[]{track}, outputStream);
|
trackExporter.writeTrack(track, outputStream);
|
||||||
|
|
||||||
// 2. import
|
// 2. import
|
||||||
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ public class ExportProgressDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try (OutputStream outputStream = context.getContentResolver().openOutputStream(file.getUri())) {
|
try (OutputStream outputStream = context.getContentResolver().openOutputStream(file.getUri())) {
|
||||||
if (trackExporter.writeTrack(new Track[]{track}, outputStream)) {
|
if (trackExporter.writeTrack(track, outputStream)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (!file.delete()) {
|
if (!file.delete()) {
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ public class FileTrackExporter implements TrackExporter {
|
|||||||
this.trackWriter = trackWriter;
|
this.trackWriter = trackWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean writeTrack(Track track, @NonNull OutputStream outputStream) {
|
||||||
|
return writeTrack(new Track[]{track}, outputStream);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean writeTrack(Track[] tracks, @NonNull OutputStream outputStream) {
|
public boolean writeTrack(Track[] tracks, @NonNull OutputStream outputStream) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ public class KmzTrackExporter implements TrackExporter {
|
|||||||
this.exportPhotos = exportPhotos;
|
this.exportPhotos = exportPhotos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean writeTrack(Track track, @NonNull OutputStream outputStream) {
|
||||||
|
return writeTrack(new Track[]{track}, outputStream);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean writeTrack(Track[] tracks, @NonNull OutputStream outputStream) {
|
public boolean writeTrack(Track[] tracks, @NonNull OutputStream outputStream) {
|
||||||
ZipOutputStream zipOutputStream = null;
|
ZipOutputStream zipOutputStream = null;
|
||||||
|
|||||||
@@ -29,12 +29,7 @@ import de.dennisguse.opentracks.content.data.Track;
|
|||||||
*/
|
*/
|
||||||
public interface TrackExporter {
|
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(Track[] tracks, @NonNull OutputStream outputStream);
|
boolean writeTrack(Track[] tracks, @NonNull OutputStream outputStream);
|
||||||
|
|
||||||
|
boolean writeTrack(Track track, @NonNull OutputStream outputStream);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user