mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-11 13:33:07 +02:00
fix decorator TrackExporter interface
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(context, outputStream);
|
trackExporter.writeTrack(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(context, outputStream);
|
trackExporter.writeTrack(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(context, outputStream);
|
trackExporter.writeTrack(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(context, outputStream);
|
trackExporter.writeTrack(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(context, outputStream);
|
trackExporter.writeTrack(outputStream);
|
||||||
|
|
||||||
// 2. import
|
// 2. import
|
||||||
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ public class ShareContentProvider extends CustomContentProvider implements ICont
|
|||||||
|
|
||||||
PipeDataWriter<String> pipeDataWriter = (output, uri1, mimeType, opts, args) -> {
|
PipeDataWriter<String> pipeDataWriter = (output, uri1, mimeType, opts, args) -> {
|
||||||
try (FileOutputStream fileOutputStream = new FileOutputStream(output.getFileDescriptor())) {
|
try (FileOutputStream fileOutputStream = new FileOutputStream(output.getFileDescriptor())) {
|
||||||
trackExporter.writeTrack(getContext(), fileOutputStream);
|
trackExporter.writeTrack(fileOutputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, "there occurred an error while sharing a file: " + e);
|
Log.w(TAG, "there occurred an error while sharing a file: " + e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(context, outputStream)) {
|
if (trackExporter.writeTrack(outputStream)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (!file.delete()) {
|
if (!file.delete()) {
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ public enum TrackFileFormat {
|
|||||||
|
|
||||||
FileTrackExporter fileTrackExporter = new FileTrackExporter(contentProviderUtils, trackWriter, tracks);
|
FileTrackExporter fileTrackExporter = new FileTrackExporter(contentProviderUtils, trackWriter, tracks);
|
||||||
|
|
||||||
return new KmzTrackExporter(contentProviderUtils, fileTrackExporter, tracks, exportPhotos);
|
return new KmzTrackExporter(context, contentProviderUtils, fileTrackExporter, tracks, exportPhotos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class FileTrackExporter implements TrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean writeTrack(@NonNull Context context, @NonNull OutputStream outputStream) {
|
public boolean writeTrack(@NonNull OutputStream outputStream) {
|
||||||
try {
|
try {
|
||||||
trackWriter.prepare(outputStream);
|
trackWriter.prepare(outputStream);
|
||||||
trackWriter.writeHeader(tracks);
|
trackWriter.writeHeader(tracks);
|
||||||
|
|||||||
@@ -54,15 +54,18 @@ public class KmzTrackExporter implements TrackExporter {
|
|||||||
private final Track[] tracks;
|
private final Track[] tracks;
|
||||||
|
|
||||||
private final boolean exportPhotos;
|
private final boolean exportPhotos;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
* @param context the context
|
||||||
* @param contentProviderUtils the content provider utils
|
* @param contentProviderUtils the content provider utils
|
||||||
* @param trackExporter the file track exporter
|
* @param trackExporter the file track exporter
|
||||||
* @param tracks the tracks to export
|
* @param tracks the tracks to export
|
||||||
*/
|
*/
|
||||||
public KmzTrackExporter(ContentProviderUtils contentProviderUtils, FileTrackExporter trackExporter, Track[] tracks, boolean exportPhotos) {
|
public KmzTrackExporter(Context context, ContentProviderUtils contentProviderUtils, FileTrackExporter trackExporter, Track[] tracks, boolean exportPhotos) {
|
||||||
|
this.context = context;
|
||||||
this.contentProviderUtils = contentProviderUtils;
|
this.contentProviderUtils = contentProviderUtils;
|
||||||
this.fileTrackExporter = trackExporter;
|
this.fileTrackExporter = trackExporter;
|
||||||
this.tracks = tracks;
|
this.tracks = tracks;
|
||||||
@@ -70,7 +73,7 @@ public class KmzTrackExporter implements TrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean writeTrack(@NonNull Context context, @NonNull OutputStream outputStream) {
|
public boolean writeTrack(@NonNull OutputStream outputStream) {
|
||||||
ZipOutputStream zipOutputStream = null;
|
ZipOutputStream zipOutputStream = null;
|
||||||
try {
|
try {
|
||||||
zipOutputStream = new ZipOutputStream(outputStream);
|
zipOutputStream = new ZipOutputStream(outputStream);
|
||||||
@@ -79,7 +82,7 @@ public class KmzTrackExporter implements TrackExporter {
|
|||||||
ZipEntry zipEntry = new ZipEntry(KMZ_KML_FILE);
|
ZipEntry zipEntry = new ZipEntry(KMZ_KML_FILE);
|
||||||
zipOutputStream.putNextEntry(zipEntry);
|
zipOutputStream.putNextEntry(zipEntry);
|
||||||
|
|
||||||
boolean success = fileTrackExporter.writeTrack(context, zipOutputStream);
|
boolean success = fileTrackExporter.writeTrack(zipOutputStream);
|
||||||
zipOutputStream.closeEntry();
|
zipOutputStream.closeEntry();
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Log.e(TAG, "Unable to write kml in kmz");
|
Log.e(TAG, "Unable to write kml in kmz");
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ public interface TrackExporter {
|
|||||||
* Write track to an output stream.
|
* Write track to an output stream.
|
||||||
* Depending on the implementation a context might be required.
|
* Depending on the implementation a context might be required.
|
||||||
*
|
*
|
||||||
* @param context the context
|
|
||||||
* @param outputStream the output stream
|
* @param outputStream the output stream
|
||||||
*/
|
*/
|
||||||
boolean writeTrack(@NonNull Context context, @NonNull OutputStream outputStream);
|
boolean writeTrack(@NonNull OutputStream outputStream);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user