Skip to content

Commit f82a6f3

Browse files
committed
change in the way OSM upload works
now upload a zip file with the track, instead of a gpx file.
1 parent 09f77db commit f82a6f3

2 files changed

Lines changed: 28 additions & 3 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: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static File zipCacheFiles(Context context, long trackId, File fileGPX) {
6464
}
6565
}
6666
}
67-
// Adds the original gpx file
67+
// Add gpx file
6868
addFileToZip(fileGPX, zos);
6969

7070
Log.d(TAG, "ZIP file created: " + zipFile.getAbsolutePath());
@@ -75,7 +75,27 @@ public static File zipCacheFiles(Context context, long trackId, File fileGPX) {
7575
return null;
7676
}
7777
}
78-
78+
/***
79+
* Compresses file gpx into a zip file.
80+
* @param context Application context.
81+
* @param trackId Track ID.
82+
* @param fileGPX GPX file.
83+
* @return The created ZIP file or null if an error occurred.
84+
*/
85+
public static File zipFile(Context context, long trackId, File fileGPX) {
86+
String name = fileGPX.getName();
87+
File zipFile = new File(context.getCacheDir(), name.substring(0, name.length() - 3)+"zip");
88+
try (FileOutputStream fos = new FileOutputStream(zipFile);
89+
ZipOutputStream zos = new ZipOutputStream(fos)) {
90+
// Add the gpx file
91+
addFileToZip(fileGPX, zos);
92+
return zipFile;
93+
} catch (FileNotFoundException e) {
94+
throw new RuntimeException(e);
95+
} catch (IOException e) {
96+
throw new RuntimeException(e);
97+
}
98+
}
7999

80100
/**
81101
* Adds a file to the ZIP archive.

0 commit comments

Comments
 (0)