Skip to content

Commit a2f5d59

Browse files
authored
Merge branch 'issue-64' into share_zip
2 parents 2448dba + f82a6f3 commit a2f5d59

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

app/src/main/java/net/osmtracker/activity/OpenStreetMapUpload.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626
import net.osmtracker.db.TrackContentProvider;
2727
import net.osmtracker.db.model.Track;
2828
import net.osmtracker.gpx.ExportToTempFileTask;
29+
import net.osmtracker.gpx.ZipHelper;
2930
import net.osmtracker.osm.OpenStreetMapConstants;
3031
import net.osmtracker.osm.UploadToOpenStreetMapTask;
3132

33+
import java.io.File;
34+
3235
/**
3336
* <p>Uploads a track on OSM using the API and
3437
* OAuth authentication.</p>
@@ -205,8 +208,10 @@ public void uploadToOsm(String accessToken) {
205208
new ExportToTempFileTask(this, trackId) {
206209
@Override
207210
protected void executionCompleted() {
211+
File filezip = ZipHelper.zipFile(context,trackId,getTmpFile());
212+
String nameFile = this.getFilename().substring(0, this.getFilename().length() - 3)+"zip";
208213
new UploadToOpenStreetMapTask(OpenStreetMapUpload.this, accessToken,
209-
trackId, this.getTmpFile(), this.getFilename(),
214+
trackId, filezip, nameFile,
210215
etDescription.getText().toString(), etTags.getText().toString(),
211216
Track.OSMVisibility.fromPosition(
212217
OpenStreetMapUpload.this.spVisibility.getSelectedItemPosition())

app/src/main/java/net/osmtracker/gpx/ZipHelper.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,27 @@ public static File zipCacheFiles(Context context, long trackId, File fileGPX) {
6363
return null;
6464
}
6565
}
66-
66+
/***
67+
* Compresses file gpx into a zip file.
68+
* @param context Application context.
69+
* @param trackId Track ID.
70+
* @param fileGPX GPX file.
71+
* @return The created ZIP file or null if an error occurred.
72+
*/
73+
public static File zipFile(Context context, long trackId, File fileGPX) {
74+
String name = fileGPX.getName();
75+
File zipFile = new File(context.getCacheDir(), name.substring(0, name.length() - 3)+"zip");
76+
try (FileOutputStream fos = new FileOutputStream(zipFile);
77+
ZipOutputStream zos = new ZipOutputStream(fos)) {
78+
// Add the gpx file
79+
addFileToZip(fileGPX, zos);
80+
return zipFile;
81+
} catch (FileNotFoundException e) {
82+
throw new RuntimeException(e);
83+
} catch (IOException e) {
84+
throw new RuntimeException(e);
85+
}
86+
}
6787

6888
/**
6989
* Adds a file to the ZIP archive.

0 commit comments

Comments
 (0)