Fix small issues

This commit is contained in:
Victor Shcherb 2014-06-01 14:25:51 +02:00
parent a6dadcc4c8
commit 2676542d5e
4 changed files with 24 additions and 22 deletions

View file

@ -100,7 +100,7 @@ public class OsMoControlDevice implements OsMoReactor {
} }
return true; return true;
} else if(command.equals("GPX_GET")) { } else if(command.equals("GPX_GET")) {
plugin.getDownloadGpxTask().execute(obj); plugin.getDownloadGpxTask(true).execute(obj);
} }
return false; return false;
} }

View file

@ -286,7 +286,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
} }
} }
if(obj.has(TRACK)){ if(obj.has(TRACK)){
plugin.getDownloadGpxTask().execute(obj.getJSONObject(TRACK)); plugin.getDownloadGpxTask(true).execute(obj.getJSONObject(TRACK));
} }
if(deleteUsers) { if(deleteUsers) {
for(OsMoDevice s : toDelete.values()) { for(OsMoDevice s : toDelete.values()) {

View file

@ -324,7 +324,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
return service; return service;
} }
public AsyncTask<JSONObject, GPXFile, String> getDownloadGpxTask() { public AsyncTask<JSONObject, GPXFile, String> getDownloadGpxTask(final boolean makeVisible) {
return new AsyncTask<JSONObject, GPXFile, String> (){ return new AsyncTask<JSONObject, GPXFile, String> (){
@ -338,31 +338,33 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
for(JSONObject obj : params) { for(JSONObject obj : params) {
try { try {
File f = new File(fl, obj.getString("name")); 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 visible = obj.has("visible");
boolean changed = false;
if(!f.exists() || (fl.lastModified() != timestamp) ) { if(!f.exists() || (fl.lastModified() != timestamp) ) {
boolean sizeEqual = f.exists() && obj.has("size") && obj.getLong("size") == f.length(); boolean sizeEqual = f.exists() && obj.has("size") && obj.getLong("size") == f.length();
if(sizeEqual && !f.setLastModified(timestamp - 1)){ if(sizeEqual && !f.setLastModified(timestamp - 1)){
// false alarm // false alarm
continue; } else {
} changed = true;
String url = obj.getString("url"); String url = obj.getString("url");
DownloadFileHelper df = new DownloadFileHelper(app); DownloadFileHelper df = new DownloadFileHelper(app);
InputStream is = df.getInputStreamToDownload(new URL(url), false); InputStream is = df.getInputStreamToDownload(new URL(url), false);
FileOutputStream fout = new FileOutputStream(f); FileOutputStream fout = new FileOutputStream(f);
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int k; int k;
while((k = is.read(buf)) >= 0) { while ((k = is.read(buf)) >= 0) {
fout.write(buf, 0, k); fout.write(buf, 0, k);
} }
fout.close(); fout.close();
is.close(); is.close();
f.setLastModified(timestamp); f.setLastModified(timestamp);
if(visible) {
GPXFile selectGPXFile = GPXUtilities.loadGPXFile(app, f);
app.setGpxFileToDisplay(selectGPXFile, app.getSettings().SHOW_CURRENT_GPX_TRACK.get());
} }
} }
if(visible && (changed || makeVisible)) {
GPXFile selectGPXFile = GPXUtilities.loadGPXFile(app, f);
app.setGpxFileToDisplay(selectGPXFile, app.getSettings().SHOW_CURRENT_GPX_TRACK.get());
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
errors += e.getMessage() +"\n"; errors += e.getMessage() +"\n";

View file

@ -276,7 +276,7 @@ public class OsMoService implements OsMoReactor {
} else if(command.equals("GET_MY_TRACKS")) { } else if(command.equals("GET_MY_TRACKS")) {
try { try {
JSONArray ar = new JSONArray(data); JSONArray ar = new JSONArray(data);
AsyncTask<JSONObject, GPXFile, String> task = plugin.getDownloadGpxTask(); AsyncTask<JSONObject, GPXFile, String> task = plugin.getDownloadGpxTask(false);
JSONObject[] a = new JSONObject[ar.length()]; JSONObject[] a = new JSONObject[ar.length()];
for(int i = 0; i < a.length; i++) { for(int i = 0; i < a.length; i++) {
a[i] = (JSONObject) ar.get(i); a[i] = (JSONObject) ar.get(i);