fix decorator TrackExporter interface

This commit is contained in:
thrillfall
2020-08-09 13:37:10 +02:00
committed by Dennis Guse
parent ca8814c478
commit 2655d3e773
7 changed files with 16 additions and 14 deletions
@@ -111,7 +111,7 @@ public class ExportImportTest {
// when
// 1. export
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
trackExporter.writeTrack(context, outputStream);
trackExporter.writeTrack(outputStream);
contentProviderUtils.deleteTrack(context, trackId);
// 2. import
@@ -147,7 +147,7 @@ public class ExportImportTest {
// when
// 1. export
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
trackExporter.writeTrack(context, outputStream);
trackExporter.writeTrack(outputStream);
contentProviderUtils.deleteTrack(context, trackId);
// 2. import
@@ -183,7 +183,7 @@ public class ExportImportTest {
// when
// 1. export
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
trackExporter.writeTrack(context, outputStream);
trackExporter.writeTrack(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(context, outputStream);
trackExporter.writeTrack(outputStream);
contentProviderUtils.deleteTrack(context, trackId);
// 2. import
@@ -272,7 +272,7 @@ public class ExportImportTest {
// when
// 1. export
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
trackExporter.writeTrack(context, outputStream);
trackExporter.writeTrack(outputStream);
// 2. import
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) -> {
try (FileOutputStream fileOutputStream = new FileOutputStream(output.getFileDescriptor())) {
trackExporter.writeTrack(getContext(), fileOutputStream);
trackExporter.writeTrack(fileOutputStream);
} catch (IOException 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())) {
if (trackExporter.writeTrack(context, outputStream)) {
if (trackExporter.writeTrack(outputStream)) {
return true;
} else {
if (!file.delete()) {
@@ -201,7 +201,7 @@ public enum TrackFileFormat {
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
public boolean writeTrack(@NonNull Context context, @NonNull OutputStream outputStream) {
public boolean writeTrack(@NonNull OutputStream outputStream) {
try {
trackWriter.prepare(outputStream);
trackWriter.writeHeader(tracks);
@@ -54,15 +54,18 @@ public class KmzTrackExporter implements TrackExporter {
private final Track[] tracks;
private final boolean exportPhotos;
private Context context;
/**
* Constructor.
*
* @param context the context
* @param contentProviderUtils the content provider utils
* @param trackExporter the file track exporter
* @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.fileTrackExporter = trackExporter;
this.tracks = tracks;
@@ -70,7 +73,7 @@ public class KmzTrackExporter implements TrackExporter {
}
@Override
public boolean writeTrack(@NonNull Context context, @NonNull OutputStream outputStream) {
public boolean writeTrack(@NonNull OutputStream outputStream) {
ZipOutputStream zipOutputStream = null;
try {
zipOutputStream = new ZipOutputStream(outputStream);
@@ -79,7 +82,7 @@ public class KmzTrackExporter implements TrackExporter {
ZipEntry zipEntry = new ZipEntry(KMZ_KML_FILE);
zipOutputStream.putNextEntry(zipEntry);
boolean success = fileTrackExporter.writeTrack(context, zipOutputStream);
boolean success = fileTrackExporter.writeTrack(zipOutputStream);
zipOutputStream.closeEntry();
if (!success) {
Log.e(TAG, "Unable to write kml in kmz");
@@ -33,8 +33,7 @@ public interface TrackExporter {
* Write track to an output stream.
* Depending on the implementation a context might be required.
*
* @param context the context
* @param outputStream the output stream
*/
boolean writeTrack(@NonNull Context context, @NonNull OutputStream outputStream);
boolean writeTrack(@NonNull OutputStream outputStream);
}