Fix small issues

This commit is contained in:
vshcherb 2014-05-28 19:00:49 +02:00
parent fbd3476483
commit ebee46c5d8
3 changed files with 21 additions and 12 deletions

View file

@ -68,7 +68,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
@Override
public void reconnect() {
for(OsMoDevice d : storage.getMainGroup().getGroupUsers()) {
for(OsMoDevice d : storage.getMainGroup().getGroupUsers(null)) {
if(d.isEnabled()) {
connectDeviceImpl(d);
}
@ -103,8 +103,8 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
model.enabled = false;
String operation = "GROUP_DISCONNECT:"+model.groupId;
service.pushCommand(operation);
for(OsMoDevice d : model.getGroupUsers()) {
tracker.startTrackingId(d);
for(OsMoDevice d : model.getGroupUsers(null)) {
tracker.stopTrackingId(d);
}
storage.save();
return operation;
@ -169,7 +169,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
mergeGroup(group, obj, true);
group.active = true;
// connect to all devices in group
for(OsMoDevice d : group.getGroupUsers()) {
for(OsMoDevice d : group.getGroupUsers(null)) {
connectDeviceImpl(d);
}
storage.save();
@ -232,7 +232,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
private void disconnectAllGroupUsers(OsMoGroup gr) {
gr.active = false;
for(OsMoDevice d : gr.getGroupUsers()) {
for(OsMoDevice d : gr.getGroupUsers(null)) {
disconnectImpl(d);
}
}

View file

@ -154,7 +154,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
// getSupportActionBar().setIcon(R.drawable.tab_search_favorites_icon);
osMoPlugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class);
adapter = new OsMoGroupsAdapter(osMoPlugin.getGroups(), osMoPlugin.getTracker());
adapter = new OsMoGroupsAdapter(osMoPlugin.getGroups(), osMoPlugin.getTracker(),
osMoPlugin.getService());
getExpandableListView().setAdapter(adapter);
app = (OsmandApplication) getApplication();
@ -713,7 +714,9 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
@Override
public void run() {
Toast.makeText(OsMoGroupsActivity.this, R.string.osmo_server_operation_failed, Toast.LENGTH_LONG).show();
if(OsMoGroupsActivity.this.operation != null) {
Toast.makeText(OsMoGroupsActivity.this, R.string.osmo_server_operation_failed, Toast.LENGTH_LONG).show();
}
hideProgressBar();
}
}, 15000);
@ -757,10 +760,12 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
private Map<OsMoGroup, List<OsMoDevice>> users = new LinkedHashMap<OsMoGroup, List<OsMoDevice>>();
private OsMoGroups grs;
private OsMoTracker tracker;
private OsMoService srv;
public OsMoGroupsAdapter(OsMoGroups grs, OsMoTracker tracker) {
public OsMoGroupsAdapter(OsMoGroups grs, OsMoTracker tracker, OsMoService srv) {
this.grs = grs;
this.tracker = tracker;
this.srv = srv;
synchronizeGroups();
}
@ -769,7 +774,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
sortedGroups.remove(group);
users.remove(group);
} else {
List<OsMoDevice> us = !group.isEnabled() && !group.isMainGroup() ? new ArrayList<OsMoDevice>(0) : group.getVisibleGroupUsers();
List<OsMoDevice> us = !group.isEnabled() && !group.isMainGroup() ? new ArrayList<OsMoDevice>(0) :
group.getVisibleGroupUsers(srv.getMyGroupTrackerId());
final Collator ci = Collator.getInstance();
Collections.sort(us, new Comparator<OsMoDevice>() {

View file

@ -207,10 +207,13 @@ public class OsMoGroupsStorage {
protected Map<String, OsMoDevice> users = new ConcurrentHashMap<String, OsMoDevice>();
public List<OsMoDevice> getGroupUsers() {
public List<OsMoDevice> getGroupUsers(String mygid) {
// filter deleted
List<OsMoDevice> dvs = new ArrayList<OsMoDevice>(users.size());
for(OsMoDevice d : users.values()) {
if(mygid != null && mygid.equals(d.trackerId)) {
continue;
}
if(d.getDeletedTimestamp() == 0) {
dvs.add(d);
}
@ -218,11 +221,11 @@ public class OsMoGroupsStorage {
return dvs;
}
public List<OsMoDevice> getVisibleGroupUsers() {
public List<OsMoDevice> getVisibleGroupUsers(String mygid) {
if(!isActive() && !isMainGroup()) {
return Collections.emptyList();
}
return getGroupUsers();
return getGroupUsers(mygid);
}
public boolean isDeleted() {