Fix tracks

This commit is contained in:
Victor Shcherb 2014-06-01 14:51:43 +02:00
parent 2676542d5e
commit 662425fe09
2 changed files with 19 additions and 8 deletions

View file

@ -8,6 +8,7 @@ import java.util.Map;
import net.osmand.Location;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup;
import net.osmand.plus.osmo.OsMoTracker.OsmoTrackerListener;
@ -16,6 +17,8 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.AsyncTask;
public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
private static final String GROUP_NAME = "name";
@ -29,7 +32,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
private static final String DELETED = "deleted";
private static final String GROUP_TRACKER_ID = "group_tracker_id";
private static final String LAST_ONLINE = "last_online";
private static final String TRACK = "track";
private static final String TRACKS = "tracks";
private OsMoTracker tracker;
private OsMoService service;
@ -285,8 +288,13 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
delta.add(device);
}
}
if(obj.has(TRACK)){
plugin.getDownloadGpxTask(true).execute(obj.getJSONObject(TRACK));
if(obj.has(TRACKS)){
JSONArray ar = obj.getJSONArray(TRACKS);
JSONObject[] a = new JSONObject[ar.length()];
for(int i = 0; i < a.length; i++) {
a[i] = (JSONObject) ar.get(i);
}
plugin.getDownloadGpxTask(true).execute(a);
}
if(deleteUsers) {
for(OsMoDevice s : toDelete.values()) {

View file

@ -5,10 +5,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
@ -32,6 +32,7 @@ import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.BaseMapWidget;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import org.apache.commons.logging.Log;
import org.json.JSONException;
import org.json.JSONObject;
@ -56,8 +57,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
private OsMoPositionLayer olayer;
protected MapActivity mapActivity;
// 2014-05-27 23:11:40
public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private final static Log log = PlatformUtil.getLog(OsMoPlugin.class);
public OsMoPlugin(final OsmandApplication app) {
service = new OsMoService(app, this);
@ -348,6 +348,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
} else {
changed = true;
String url = obj.getString("url");
log.info("Download gpx " + url);
DownloadFileHelper df = new DownloadFileHelper(app);
InputStream is = df.getInputStreamToDownload(new URL(url), false);
FileOutputStream fout = new FileOutputStream(f);
@ -358,7 +359,9 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
}
fout.close();
is.close();
f.setLastModified(timestamp);
if(!f.setLastModified(timestamp)) {
log.error("Timestamp updates are not supported");
}
}
}
if(visible && (changed || makeVisible)) {