From 742c1b01bb8baab2cbc00e3d6bbfd66704c0b34b Mon Sep 17 00:00:00 2001 From: vshcherb Date: Wed, 28 May 2014 18:47:28 +0200 Subject: [PATCH] Fix conenct --- .../src/net/osmand/plus/osmo/OsMoGroups.java | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java index 240da69429..ddfbc34d7d 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java @@ -150,7 +150,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { for(OsMoDevice d : delta) { if(d.getDeletedTimestamp() != 0 && d.isEnabled()) { disconnectImpl(d); - } else if(d.isEnabled() && !d.isActive()) { + } else if(!d.isActive()) { connectDeviceImpl(d); } } @@ -244,35 +244,37 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { if(obj.has("group")) { parseGroup(obj.getJSONObject("group"), gr); } - JSONArray arr = obj.getJSONArray(USERS); Map toDelete = new HashMap(gr.users); - for (int i = 0; i < arr.length(); i++) { - JSONObject o = (JSONObject) arr.get(i); - String tid = o.getString(GROUP_TRACKER_ID); - OsMoDevice device = toDelete.remove(tid); - if (device == null) { - device = new OsMoDevice(); - device.group = gr; - device.trackerId = tid; - device.enabled = true; - gr.users.put(tid, device); + if (obj.has(USERS)) { + JSONArray arr = obj.getJSONArray(USERS); + for (int i = 0; i < arr.length(); i++) { + JSONObject o = (JSONObject) arr.get(i); + String tid = o.getString(GROUP_TRACKER_ID); + OsMoDevice device = toDelete.remove(tid); + if (device == null) { + device = new OsMoDevice(); + device.group = gr; + device.trackerId = tid; + device.enabled = true; + gr.users.put(tid, device); + } + if (o.has(USER_NAME)) { + device.serverName = o.getString(USER_NAME); + } + if (o.has(DELETED) && o.getBoolean(DELETED)) { + device.deleted = System.currentTimeMillis(); + } else { + device.deleted = 0; + } + + if (o.has(LAST_ONLINE)) { + device.lastOnline = o.getLong(LAST_ONLINE); + } + if (o.has(USER_COLOR)) { + device.serverColor = o.getInt(USER_COLOR); + } + delta.add(device); } - if (o.has(USER_NAME)) { - device.serverName = o.getString(USER_NAME); - } - if (o.has(DELETED) && o.getBoolean(DELETED)) { - device.deleted = System.currentTimeMillis(); - } else { - device.deleted = 0; - } - - if (o.has(LAST_ONLINE)) { - device.lastOnline = o.getLong(LAST_ONLINE); - } - if (o.has(USER_COLOR)) { - device.serverColor = o.getInt(USER_COLOR); - } - delta.add(device); } if(deleteUsers) { for(OsMoDevice s : toDelete.values()) {