Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
63ef931a96
4 changed files with 98 additions and 36 deletions
|
@ -27,6 +27,7 @@ public class GpxSelectionHelper {
|
|||
|
||||
private static final String CURRENT_TRACK = "currentTrack";
|
||||
private static final String FILE = "file";
|
||||
private static final String COLOR = "color";
|
||||
private OsmandApplication app;
|
||||
// save into settings
|
||||
// public final CommonPreference<Boolean> SHOW_CURRENT_GPX_TRACK =
|
||||
|
@ -307,6 +308,10 @@ public class GpxSelectionHelper {
|
|||
p.startTask(getString(R.string.loading_smth, fl.getName()), -1);
|
||||
}
|
||||
GPXFile gpx = GPXUtilities.loadGPXFile(app, fl);
|
||||
if(obj.has(COLOR)) {
|
||||
int clr = Algorithms.parseColor(obj.getString(COLOR));
|
||||
gpx.setColor(clr);
|
||||
}
|
||||
if(gpx.warning != null) {
|
||||
save = true;
|
||||
} else {
|
||||
|
@ -336,6 +341,9 @@ public class GpxSelectionHelper {
|
|||
obj.put(CURRENT_TRACK, true);
|
||||
} else if(!Algorithms.isEmpty(s.gpxFile.path)) {
|
||||
obj.put(FILE, s.gpxFile.path);
|
||||
if(s.gpxFile.getColor(0) != 0) {
|
||||
obj.put(COLOR, Algorithms.colorToString(s.gpxFile.getColor(0)));
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
package net.osmand.plus.osmo;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
|
||||
|
@ -15,14 +24,6 @@ import org.json.JSONArray;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
||||
|
||||
private static final String GROUP_NAME = "name";
|
||||
|
@ -206,6 +207,8 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
group = storage.getGroup(gid);
|
||||
if(group != null) {
|
||||
disconnectAllGroupUsers(group);
|
||||
disableGroupTracks(group, group.groupTracks);
|
||||
disableGroupTracks(group, Collections.singleton(group.name + " points.gpx"));
|
||||
}
|
||||
processed = true;
|
||||
} else if(command.equalsIgnoreCase("GROUP_CONNECT")) {
|
||||
|
@ -354,6 +357,19 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
return processed;
|
||||
}
|
||||
|
||||
private void disableGroupTracks(OsMoGroup group, Collection<String> tracks) {
|
||||
if(!tracks.isEmpty()) {
|
||||
GpxSelectionHelper helper = app.getSelectedGpxHelper();
|
||||
for(String t : tracks) {
|
||||
SelectedGpxFile sg = helper.getSelectedFileByName("osmo/"+t);
|
||||
if(sg != null && sg.getGpxFile() != null) {
|
||||
helper.selectGpxFile(sg.getGpxFile(), false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private OsMoGroup parseGroup(JSONObject obj) throws JSONException {
|
||||
OsMoGroup groupe = new OsMoGroup();
|
||||
groupe.enabled = !(obj.has(ACTIVE) && ("0".equals(obj.getString(ACTIVE)) ||
|
||||
|
@ -444,10 +460,16 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
if (obj.has(TRACK)) {
|
||||
JSONArray ar = obj.getJSONArray(TRACK);
|
||||
JSONObject[] a = new JSONObject[ar.length()];
|
||||
Set<String> toDeleteT = new HashSet<String>(gr.groupTracks);
|
||||
gr.groupTracks.clear();
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
a[i] = (JSONObject) ar.get(i);
|
||||
String track = a[i].getString("name") + ".gpx";
|
||||
gr.groupTracks.add(track);
|
||||
toDeleteT.remove(track);
|
||||
}
|
||||
plugin.getDownloadGpxTask(true).execute(a);
|
||||
disableGroupTracks(gr, toDeleteT);
|
||||
}
|
||||
|
||||
if (obj.has(POINT)) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.graphics.Color;
|
|||
public class OsMoGroupsStorage {
|
||||
private static final String GROUPS = "groups";
|
||||
private static final String USERS = "users";
|
||||
private static final String TRACKS = "tracks";
|
||||
private static final String SERVER_NAME = "serverName";
|
||||
private static final String GROUP_ID = "group_id";
|
||||
private static final String TRACKER_ID = "trackerId";
|
||||
|
@ -102,6 +103,7 @@ public class OsMoGroupsStorage {
|
|||
group.enabled = true;
|
||||
}
|
||||
parseGroupUsers(group, o);
|
||||
// parseGroupTracks(group, obj);
|
||||
this.groups.put(group.groupId, group);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
@ -141,6 +143,7 @@ public class OsMoGroupsStorage {
|
|||
obj.put(GROUP_ID, gr.groupId);
|
||||
ar.put(obj);
|
||||
saveGroupUsers(gr, obj);
|
||||
saveGroupTracks(gr, obj);
|
||||
}
|
||||
mainObj.put(GROUPS, ar);
|
||||
} catch (JSONException e) {
|
||||
|
@ -182,7 +185,19 @@ public class OsMoGroupsStorage {
|
|||
grObj.put(USERS, ar);
|
||||
}
|
||||
|
||||
private void parseGroupUsers(OsMoGroup gr, JSONObject obj) throws JSONException {
|
||||
private void saveGroupTracks(OsMoGroup gr, JSONObject grObj) throws JSONException {
|
||||
if (gr.groupTracks.size() > 0) {
|
||||
JSONArray ar = new JSONArray();
|
||||
for (String u : gr.groupTracks) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put(NAME, u);
|
||||
ar.put(obj);
|
||||
}
|
||||
grObj.put(TRACKS, ar);
|
||||
}
|
||||
}
|
||||
|
||||
protected void parseGroupUsers(OsMoGroup gr, JSONObject obj) throws JSONException {
|
||||
if(!obj.has(USERS)) {
|
||||
return;
|
||||
}
|
||||
|
@ -217,6 +232,19 @@ public class OsMoGroupsStorage {
|
|||
}
|
||||
}
|
||||
|
||||
protected void parseGroupTracks(OsMoGroup gr, JSONObject obj) throws JSONException {
|
||||
if(!obj.has(TRACKS)) {
|
||||
return;
|
||||
}
|
||||
JSONArray tracks = obj.getJSONArray(TRACKS);
|
||||
for (int i = 0; i < tracks.length(); i++) {
|
||||
JSONObject o = (JSONObject) tracks.get(i);
|
||||
if(o.has(NAME)) {
|
||||
gr.groupTracks.add(NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class OsMoGroup {
|
||||
protected String name;
|
||||
protected String userName;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus.osmo;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -400,8 +401,10 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
|
|||
boolean visible = obj.has("visible");
|
||||
boolean changed = false;
|
||||
if(!f.exists() || (f.lastModified() != timestamp) ) {
|
||||
boolean sizeEqual = f.exists() && obj.has("size") && obj.getLong("size") == f.length();
|
||||
if(sizeEqual && !f.setLastModified(timestamp - 1)){
|
||||
long len = !f.exists() ? -1 : f.length();
|
||||
boolean sizeEqual = obj.has("size") && obj.getLong("size") == len;
|
||||
boolean modifySupported = f.setLastModified(timestamp - 1);
|
||||
if(sizeEqual && !modifySupported){
|
||||
// false alarm
|
||||
} else {
|
||||
changed = true;
|
||||
|
@ -409,35 +412,21 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
|
|||
log.info("Download gpx " + 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();
|
||||
int av = is.available();
|
||||
if(av > 0 && !modifySupported && len == av) {
|
||||
// ignore
|
||||
is.close();
|
||||
if(color != 0) {
|
||||
try {
|
||||
GPXFile loaded = GPXUtilities.loadGPXFile(app, f);
|
||||
if(loaded.tracks.size() > 0) {
|
||||
for(Track t : loaded.tracks) {
|
||||
t.setColor(color);
|
||||
}
|
||||
GPXUtilities.writeGpxFile(f, loaded, app);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(!f.setLastModified(timestamp)) {
|
||||
log.error("Timestamp updates are not supported");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
redownloadFile(f, timestamp, color, is);
|
||||
publishProgress(app.getString(R.string.osmo_gpx_track_downloaded, obj.getString("name")));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(visible && (changed || makeVisible)) {
|
||||
GPXFile selectGPXFile = GPXUtilities.loadGPXFile(app, f);
|
||||
if(color != 0) {
|
||||
selectGPXFile.setColor(color);
|
||||
}
|
||||
app.getSelectedGpxHelper().setGpxFileToDisplay(selectGPXFile);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
@ -451,6 +440,21 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
|
|||
return errors;
|
||||
}
|
||||
|
||||
private void redownloadFile(File f, long timestamp, int color, InputStream is)
|
||||
throws FileNotFoundException, IOException {
|
||||
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();
|
||||
if(!f.setLastModified(timestamp)) {
|
||||
log.error("Timestamp updates are not supported");
|
||||
}
|
||||
}
|
||||
|
||||
protected void onProgressUpdate(String... values) {
|
||||
if (values != null) {
|
||||
String t = "";
|
||||
|
|
Loading…
Reference in a new issue