From 2676542d5e8bbbb937842c79751051e2bf54bc96 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 1 Jun 2014 14:25:51 +0200 Subject: [PATCH] Fix small issues --- .../osmand/plus/osmo/OsMoControlDevice.java | 2 +- .../src/net/osmand/plus/osmo/OsMoGroups.java | 2 +- .../src/net/osmand/plus/osmo/OsMoPlugin.java | 40 ++++++++++--------- .../src/net/osmand/plus/osmo/OsMoService.java | 2 +- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoControlDevice.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoControlDevice.java index eb0a179a40..a9b898506c 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoControlDevice.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoControlDevice.java @@ -100,7 +100,7 @@ public class OsMoControlDevice implements OsMoReactor { } return true; } else if(command.equals("GPX_GET")) { - plugin.getDownloadGpxTask().execute(obj); + plugin.getDownloadGpxTask(true).execute(obj); } return false; } diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java index 3477bc025a..b2c9e69eac 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java @@ -286,7 +286,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { } } if(obj.has(TRACK)){ - plugin.getDownloadGpxTask().execute(obj.getJSONObject(TRACK)); + plugin.getDownloadGpxTask(true).execute(obj.getJSONObject(TRACK)); } if(deleteUsers) { for(OsMoDevice s : toDelete.values()) { diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java index 87b113e0fb..09e997550d 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java @@ -324,7 +324,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer return service; } - public AsyncTask getDownloadGpxTask() { + public AsyncTask getDownloadGpxTask(final boolean makeVisible) { return new AsyncTask (){ @@ -338,31 +338,33 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer for(JSONObject obj : params) { try { File f = new File(fl, obj.getString("name")); - long timestamp = obj.getLong("timestamp") * 1000; + long timestamp = obj.getLong("created") * 1000; boolean visible = obj.has("visible"); + boolean changed = false; if(!f.exists() || (fl.lastModified() != timestamp) ) { boolean sizeEqual = f.exists() && obj.has("size") && obj.getLong("size") == f.length(); if(sizeEqual && !f.setLastModified(timestamp - 1)){ // false alarm - continue; - } - String url = obj.getString("url"); - DownloadFileHelper df = new DownloadFileHelper(app); - InputStream is = df.getInputStreamToDownload(new URL(url), false); - FileOutputStream fout = new FileOutputStream(f); - byte[] buf = new byte[1024]; - int k; - while((k = is.read(buf)) >= 0) { - fout.write(buf, 0, k); - } - fout.close(); - is.close(); - f.setLastModified(timestamp); - if(visible) { - GPXFile selectGPXFile = GPXUtilities.loadGPXFile(app, f); - app.setGpxFileToDisplay(selectGPXFile, app.getSettings().SHOW_CURRENT_GPX_TRACK.get()); + } else { + changed = true; + String url = obj.getString("url"); + DownloadFileHelper df = new DownloadFileHelper(app); + InputStream is = df.getInputStreamToDownload(new URL(url), false); + FileOutputStream fout = new FileOutputStream(f); + byte[] buf = new byte[1024]; + int k; + while ((k = is.read(buf)) >= 0) { + fout.write(buf, 0, k); + } + fout.close(); + is.close(); + f.setLastModified(timestamp); } } + if(visible && (changed || makeVisible)) { + GPXFile selectGPXFile = GPXUtilities.loadGPXFile(app, f); + app.setGpxFileToDisplay(selectGPXFile, app.getSettings().SHOW_CURRENT_GPX_TRACK.get()); + } } catch (JSONException e) { e.printStackTrace(); errors += e.getMessage() +"\n"; diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java index 1a6eb14b43..e611faf800 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java @@ -276,7 +276,7 @@ public class OsMoService implements OsMoReactor { } else if(command.equals("GET_MY_TRACKS")) { try { JSONArray ar = new JSONArray(data); - AsyncTask task = plugin.getDownloadGpxTask(); + AsyncTask task = plugin.getDownloadGpxTask(false); JSONObject[] a = new JSONObject[ar.length()]; for(int i = 0; i < a.length; i++) { a[i] = (JSONObject) ar.get(i);