From c61503a43a7fd9c41e31b5619243db5f5bfd4f35 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Wed, 28 May 2014 01:34:10 +0200 Subject: [PATCH] Fix groups --- .../src/net/osmand/plus/osmo/OsMoGroups.java | 1 + .../osmand/plus/osmo/OsMoGroupsActivity.java | 36 ++++++++++--------- .../osmand/plus/osmo/OsMoGroupsStorage.java | 8 +++++ .../src/net/osmand/plus/osmo/OsMoPlugin.java | 5 +++ 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java index e0f519d9b5..49b245e876 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java @@ -333,6 +333,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { storage.save(); service.pushCommand(op); if(group.isEnabled()) { + group.enabled = false; disconnectAllGroupUsers(group); } return op; diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java index bd2ee0bfc3..4283d9e712 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java @@ -327,8 +327,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements selectedObject = o; device = (OsMoDevice) (o instanceof OsMoDevice ?o : null); group = (OsMoGroup) (o instanceof OsMoGroup ?o : null); - MenuItem mi = createMenuItem(menu, ON_OFF_ACTION_ID, R.string.default_buttons_ok, 0, 0, - MenuItem.SHOW_AS_ACTION_ALWAYS); + MenuItem mi = null; + if(device == null || device.getGroup().isMainGroup()) { + mi = createMenuItem(menu, ON_OFF_ACTION_ID, R.string.default_buttons_ok, 0, 0, + MenuItem.SHOW_AS_ACTION_ALWAYS); + } if(device != null && device.getLastLocation() != null) { createMenuItem(menu, SHOW_ON_MAP_ID, R.string.show_poi_on_map, R.drawable.ic_action_marker_light, R.drawable.ic_action_marker_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM); @@ -351,19 +354,20 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements MenuItem.SHOW_AS_ACTION_IF_ROOM); - - final LayoutInflater inflater = LayoutInflater.from(OsMoGroupsActivity.this); - View view = inflater.inflate(R.layout.check_item_rel, null); - final CompoundButton check = (CompoundButton) view.findViewById(R.id.check_item); - check.setChecked((device != null && device.isEnabled()) || (group != null && group.isEnabled())); - check.setOnCheckedChangeListener(new OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - onOffAction(check); - } - }); - mi.setActionView(view); + if (mi != null) { + final LayoutInflater inflater = LayoutInflater.from(OsMoGroupsActivity.this); + View view = inflater.inflate(R.layout.check_item_rel, null); + final CompoundButton check = (CompoundButton) view.findViewById(R.id.check_item); + check.setChecked((device != null && device.isEnabled()) || (group != null && group.isEnabled())); + check.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + onOffAction(check); + } + }); + mi.setActionView(view); + } return true; } @@ -743,7 +747,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements sortedGroups.remove(group); users.remove(group); } else { - List us = !group.isEnabled() && !group.isMainGroup() ? new ArrayList(0) : group.getGroupUsers(); + List us = !group.isEnabled() && !group.isMainGroup() ? new ArrayList(0) : group.getVisibleGroupUsers(); final Collator ci = Collator.getInstance(); Collections.sort(us, new Comparator() { diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsStorage.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsStorage.java index 5ddebb3f8e..ed9a579f4b 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsStorage.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsStorage.java @@ -2,6 +2,7 @@ package net.osmand.plus.osmo; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -218,6 +219,13 @@ public class OsMoGroupsStorage { return dvs; } + public List getVisibleGroupUsers() { + if(!isActive()) { + return Collections.emptyList(); + } + return getGroupUsers(); + } + public boolean isDeleted() { return deleted; } diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java index d68e7dbfc1..75631b54ed 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java @@ -1,5 +1,7 @@ package net.osmand.plus.osmo; +import java.text.SimpleDateFormat; + import net.osmand.Location; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; @@ -35,6 +37,9 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer private OsMoGroups groups; private BaseMapWidget osmoControl; + // 2014-05-27 23:11:40 + public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + public OsMoPlugin(final OsmandApplication app) { service = new OsMoService(app); tracker = new OsMoTracker(service, app.getSettings().OSMO_SAVE_TRACK_INTERVAL);