Load groups
This commit is contained in:
parent
505c0ff4b7
commit
62e402a4ff
2 changed files with 13 additions and 9 deletions
|
@ -20,6 +20,9 @@ import android.content.Context;
|
||||||
|
|
||||||
public class OsMoGroups implements OsMoReactor {
|
public class OsMoGroups implements OsMoReactor {
|
||||||
|
|
||||||
|
private static final String GROUPS = "groups";
|
||||||
|
private static final String USERS = "users";
|
||||||
|
private static final String SERVER_NAME = "serverName";
|
||||||
private static final String TRACKER_ID = "trackerId";
|
private static final String TRACKER_ID = "trackerId";
|
||||||
private static final String GROUP_TRACKERS = "group_trackers";
|
private static final String GROUP_TRACKERS = "group_trackers";
|
||||||
private static final String GROUP_ID = "group_id";
|
private static final String GROUP_ID = "group_id";
|
||||||
|
@ -100,10 +103,10 @@ public class OsMoGroups implements OsMoReactor {
|
||||||
for(String connectedDevice : mainGroup.users.keySet()) {
|
for(String connectedDevice : mainGroup.users.keySet()) {
|
||||||
tracker.startTrackingId(connectedDevice);
|
tracker.startTrackingId(connectedDevice);
|
||||||
}
|
}
|
||||||
if(!obj.has("groups")) {
|
if(!obj.has(GROUPS)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONArray groups = obj.getJSONArray("groups");
|
JSONArray groups = obj.getJSONArray(GROUPS);
|
||||||
for (int i = 0; i < groups.length(); i++) {
|
for (int i = 0; i < groups.length(); i++) {
|
||||||
JSONObject o = (JSONObject) groups.get(i);
|
JSONObject o = (JSONObject) groups.get(i);
|
||||||
OsMoGroup group = new OsMoGroup();
|
OsMoGroup group = new OsMoGroup();
|
||||||
|
@ -142,6 +145,7 @@ public class OsMoGroups implements OsMoReactor {
|
||||||
obj.put(GROUP_ID, gr.groupId);
|
obj.put(GROUP_ID, gr.groupId);
|
||||||
ar.put(obj);
|
ar.put(obj);
|
||||||
}
|
}
|
||||||
|
mainObj.put(GROUPS, ar);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
service.showErrorMessage(e.getMessage());
|
service.showErrorMessage(e.getMessage());
|
||||||
|
@ -157,31 +161,32 @@ public class OsMoGroups implements OsMoReactor {
|
||||||
obj.put(USER_NAME, u.userName);
|
obj.put(USER_NAME, u.userName);
|
||||||
}
|
}
|
||||||
if (u.serverName != null) {
|
if (u.serverName != null) {
|
||||||
obj.put("serverName", u.serverName);
|
obj.put(SERVER_NAME, u.serverName);
|
||||||
}
|
}
|
||||||
obj.put(TRACKER_ID, u.trackerId);
|
obj.put(TRACKER_ID, u.trackerId);
|
||||||
|
|
||||||
ar.put(obj);
|
ar.put(obj);
|
||||||
}
|
}
|
||||||
grObj.put("users", ar);
|
grObj.put(USERS, ar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseGroupUsers(OsMoGroup gr, JSONObject obj) throws JSONException {
|
private void parseGroupUsers(OsMoGroup gr, JSONObject obj) throws JSONException {
|
||||||
if(!obj.has("users")) {
|
if(!obj.has(USERS)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONArray users = obj.getJSONArray("users");
|
JSONArray users = obj.getJSONArray(USERS);
|
||||||
for (int i = 0; i < users.length(); i++) {
|
for (int i = 0; i < users.length(); i++) {
|
||||||
JSONObject o = (JSONObject) users.get(i);
|
JSONObject o = (JSONObject) users.get(i);
|
||||||
OsMoUser user = new OsMoUser();
|
OsMoUser user = new OsMoUser();
|
||||||
user.group = gr;
|
user.group = gr;
|
||||||
if(o.has("serverName")) {
|
if(o.has(SERVER_NAME)) {
|
||||||
user.serverName = o.getString("serverName");
|
user.serverName = o.getString(SERVER_NAME);
|
||||||
}
|
}
|
||||||
if(o.has(USER_NAME)) {
|
if(o.has(USER_NAME)) {
|
||||||
user.userName = o.getString(USER_NAME);
|
user.userName = o.getString(USER_NAME);
|
||||||
}
|
}
|
||||||
user.trackerId = o.getString(TRACKER_ID);
|
user.trackerId = o.getString(TRACKER_ID);
|
||||||
|
gr.users.put(user.trackerId, user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
||||||
private static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30;
|
private static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30;
|
||||||
private static final long RECENT_THRESHOLD = 60000;
|
private static final long RECENT_THRESHOLD = 60000;
|
||||||
|
|
||||||
private Set<String> groupsToDelete = new LinkedHashSet<String>();
|
|
||||||
private OsMoPlugin osMoPlugin;
|
private OsMoPlugin osMoPlugin;
|
||||||
private OsMoGroupsAdapter adapter;
|
private OsMoGroupsAdapter adapter;
|
||||||
private LatLon mapLocation;
|
private LatLon mapLocation;
|
||||||
|
|
Loading…
Reference in a new issue