Remove personal subscriptions (service doesn't longer support it)

This commit is contained in:
Victor Shcherb 2015-09-23 13:05:03 +02:00
parent 6807052b6a
commit a386753258
7 changed files with 67 additions and 358 deletions

View file

@ -6,26 +6,7 @@
android:paddingRight="7dp"
android:stretchColumns="1">
<TableRow>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2">
<RadioButton
android:id="@+id/ConnectToDevice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/osmo_connect_to_device" />
<RadioButton
android:id="@+id/ConnectToGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/osmo_connect_to_group" />
</RadioGroup>
</TableRow>
<TableRow>

View file

@ -104,28 +104,25 @@ public abstract class DashLocationFragment extends DashBaseFragment {
boolean useCenter = !mapLinked;
LatLon loc = (useCenter ? mw : myLoc);
float h = useCenter ? -mapRotation : head;
lastUpdatedLocation = loc;
for (DashLocationView lv : distances) {
if (lv.loc != null){
lastUpdatedLocation = loc;
updateLocationView(useCenter, loc, h, lv.arrow, lv.arrowResId, lv.txt, lv.loc.getLatitude(), lv.loc.getLongitude(),
screenOrientation, getMyApplication(), getActivity(), lv.paint);
}
updateLocationView(useCenter, loc, h, lv.arrow, lv.arrowResId, lv.txt, lv.loc, screenOrientation,
getMyApplication(), getActivity(), lv.paint);
}
}
public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h,
ImageView arrow, TextView txt, double toLat, double toLon,
int screenOrientation, OsmandApplication app, Context ctx) {
updateLocationView(useCenter, fromLoc, h, arrow, 0, txt, toLat, toLon, screenOrientation, app, ctx, true);
updateLocationView(useCenter, fromLoc, h, arrow, 0, txt, new LatLon(toLat, toLon), screenOrientation, app, ctx, true);
}
public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h,
ImageView arrow, int arrowResId, TextView txt, double toLat, double toLon,
ImageView arrow, int arrowResId, TextView txt, LatLon toLoc,
int screenOrientation, OsmandApplication app, Context ctx, boolean paint) {
float[] mes = new float[2];
if (fromLoc != null) {
Location.distanceBetween(toLat, toLon, fromLoc.getLatitude(), fromLoc.getLongitude(), mes);
Location.distanceBetween(toLoc.getLatitude(), toLoc.getLongitude(), fromLoc.getLatitude(), fromLoc.getLongitude(), mes);
}
if (arrow != null) {
boolean newImage = false;
@ -140,7 +137,7 @@ public abstract class DashLocationFragment extends DashBaseFragment {
dd = (DirectionDrawable) arrow.getDrawable();
}
dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance);
if (fromLoc == null || h == null) {
if (fromLoc == null || h == null || toLoc == null) {
dd.setAngle(0);
} else {
dd.setAngle(mes[1] - h + 180 + screenOrientation);
@ -151,7 +148,7 @@ public abstract class DashLocationFragment extends DashBaseFragment {
arrow.invalidate();
}
if (txt != null) {
if (fromLoc != null) {
if (fromLoc != null && toLoc != null) {
if (paint) {
txt.setTextColor(app.getResources().getColor(
useCenter ? R.color.color_distance : R.color.color_myloc_distance));

View file

@ -198,22 +198,8 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
}
private List<OsMoGroupsStorage.OsMoDevice> getOsMoDevices(ArrayList<OsMoGroupsStorage.OsMoGroup> groups) {
OsMoGroupsStorage.OsMoGroup mainGroup = null;
for (OsMoGroupsStorage.OsMoGroup grp : groups) {
if (grp.getGroupId() == null) {
mainGroup = grp;
groups.remove(grp);
break;
}
}
if (mainGroup == null) {
return new ArrayList<>();
}
String trackerId = plugin.getService().getMyGroupTrackerId();
List<OsMoGroupsStorage.OsMoDevice> devices =
new ArrayList<>(mainGroup.getVisibleGroupUsers(trackerId));
List<OsMoGroupsStorage.OsMoDevice> devices = new ArrayList<>();
if (groups.size() > 0) {
for (OsMoGroupsStorage.OsMoGroup grp : groups) {
for (OsMoGroupsStorage.OsMoDevice device : grp.getVisibleGroupUsers(trackerId)) {
@ -313,28 +299,17 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
distances.add(dv);
final CompoundButton enableDevice = (CompoundButton) v.findViewById(R.id.check_item);
enableDevice.setVisibility(View.GONE);
ImageView icon = (ImageView) v.findViewById(R.id.icon);
if (device.isEnabled()) {
enableDevice.setVisibility(View.GONE);
icon.setImageDrawable(getMyApplication().getIconsCache().
getPaintedContentIcon(R.drawable.ic_person, device.getColor()));
} else {
enableDevice.setVisibility(View.VISIBLE);
enableDevice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.getGroups().connectDevice(device);
refreshItems();
}
});
showOnMap.setVisibility(View.GONE);
icon.setImageDrawable(getMyApplication().getIconsCache().
getContentIcon(R.drawable.ic_person));
}
if (device.isActive()) {
}
((TextView) v.findViewById(R.id.name)).setText(name);
v.setOnClickListener(new View.OnClickListener() {
@Override
@ -347,18 +322,6 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
this.distances = distances;
}
private void refreshItems() {
if (!uiHandler.hasMessages(OsMoGroupsActivity.LIST_REFRESH_MSG_ID)) {
Message msg = Message.obtain(uiHandler, new Runnable() {
@Override
public void run() {
updateConnectedDevices(getView());
}
});
msg.what = OsMoGroupsActivity.LIST_REFRESH_MSG_ID;
uiHandler.sendMessageDelayed(msg, 100);
}
}
private void launchOsMoGroupsActivity() {
Intent intent = new Intent(getActivity(), OsMoGroupsActivity.class);

View file

@ -40,8 +40,6 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
private static final String LAST_ONLINE = "last_online";
private static final String TRACK = "track";
private static final String POINT = "point";
private static final String TRACKER_ID = "tracker_id";
private static final String OK = "1";
private OsMoTracker tracker;
private OsMoService service;
@ -65,9 +63,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
service.registerReactor(this);
tracker.setTrackerListener(this);
storage = new OsMoGroupsStorage(this, app.getSettings().OSMO_GROUPS);
if (service.isLoggedIn()) {
storage.loadOnlyMainGroup();
} else {
if (!service.isLoggedIn()) {
storage.load();
}
}
@ -95,14 +91,8 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
@Override
public void onConnected() {
for(OsMoDevice d : storage.getMainGroup().getGroupUsers(null)) {
if(d.isEnabled()) {
connectDeviceImpl(d);
}
}
if (service.isLoggedIn()) {
service.pushCommand("GROUP_GET_ALL");
service.pushCommand("DEVICE_GET_ALL");
}
}
@ -123,12 +113,6 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
return op;
}
public void connectDevice(OsMoDevice model) {
connectDeviceImpl(model);
storage.save();
}
public String disconnectGroup(OsMoGroup model) {
model.enabled = false;
String operation = "GROUP_DISCONNECT:"+model.groupId;
@ -140,11 +124,6 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
return operation;
}
public void disconnectDevice(OsMoDevice model) {
model.enabled = false;
disconnectImpl(model);
storage.save();
}
private void disconnectImpl(OsMoDevice model) {
model.active = false;
@ -279,74 +258,6 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
service.showErrorMessage(e.getMessage());
return processed;
}
} else if (command.equals("DEVICE_GET_ALL")) {
try {
JSONArray arr = new JSONArray(data);
int arrLength = arr.length();
if (arrLength > 0) {
OsMoGroup mainGroup = storage.getMainGroup();
String mid = service.getMyTrackerId();
Set<String> toDelete = new HashSet<String>(mainGroup.users.keySet());
for (int i = 0; i < arrLength; i++) {
JSONObject o = arr.getJSONObject(i);
OsMoDevice device = parseDevice(o);
device.group = mainGroup;
String trackerId = device.getTrackerId();
if (!mid.equals(trackerId)) {
if (toDelete.contains(trackerId)) {
toDelete.remove(trackerId);
OsMoDevice dv = mainGroup.users.get(trackerId);
dv.serverColor = device.userColor;
dv.serverName = device.userName;
} else {
mainGroup.users.put(trackerId, device);
}
}
}
for (String id : toDelete) {
mainGroup.users.remove(id);
}
storage.save();
for(OsMoDevice d : mainGroup.getGroupUsers(null)) {
if(d.isEnabled() && !d.isActive()) {
connectDeviceImpl(d);
}
}
}
processed = true;
} catch (JSONException e) {
e.printStackTrace();
service.showErrorMessage(e.getMessage());
return processed;
}
} else if (command.equals("SUBSCRIBE")) {
OsMoGroup mainGroup = storage.getMainGroup();
OsMoDevice device = mainGroup.users.get(gid);
if (device != null) {
if (OK.equals(data)) {
connectDeviceImpl(device);
} else {
mainGroup.users.remove(gid);
storage.save();
if (obj == null) {
app.showToastMessage(app.getString(R.string.osmo_device_not_found));
}
}
}
processed = true;
} else if (command.equals("UNSUBSCRIBE")) {
OsMoGroup mainGroup = storage.getMainGroup();
OsMoDevice device = mainGroup.users.get(gid);
if (device != null) {
mainGroup.users.remove(gid);
storage.save();
}
if (!OK.equals(data)) {
if (obj == null) {
app.showToastMessage(app.getString(R.string.osmo_device_not_found));
}
}
processed = true;
}
if(processed && uiListeners != null) {
for(OsMoGroupsUIListener listener : uiListeners){
@ -381,13 +292,6 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
return groupe;
}
private OsMoDevice parseDevice(JSONObject obj) throws JSONException {
OsMoDevice device = new OsMoDevice();
device.enabled = true;
device.userName = obj.optString(USER_NAME);
device.trackerId = obj.getString(TRACKER_ID);
return device;
}
private void parseGroup(JSONObject obj, OsMoGroup gr) {
try {
@ -533,36 +437,11 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
}
public void deleteDevice(OsMoDevice device) {
if(device.isEnabled()) {
disconnectImpl(device);
}
StringBuilder unsubscribeCmd = new StringBuilder();
unsubscribeCmd.append("UNSUBSCRIBE:");
unsubscribeCmd.append(device.trackerId);
service.pushCommand(unsubscribeCmd.toString());
}
public void setGenColor(OsMoDevice device, int genColor) {
device.genColor = genColor;
storage.save();
}
public OsMoDevice addConnectedDevice(String trackerId, String nameUser, int genColor) {
OsMoDevice us = new OsMoDevice();
us.group = storage.getMainGroup();
us.trackerId = trackerId;
us.userName = nameUser;
us.genColor = genColor;
us.group.users.put(trackerId, us);
storage.save();
StringBuilder subscribeCmd = new StringBuilder();
subscribeCmd.append("SUBSCRIBE:");
subscribeCmd.append(trackerId);
subscribeCmd.append('|');
subscribeCmd.append(nameUser);
service.pushCommand(subscribeCmd.toString());
return us;
}
public String joinGroup(String groupId, String userName, String nick) {
final String op = "GROUP_JOIN:"+groupId+"|"+nick;
OsMoGroup g = storage.getGroup(groupId);

View file

@ -95,7 +95,6 @@ import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
@ -469,36 +468,32 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
group = (OsMoGroup) (o instanceof OsMoGroup ? o : null);
MenuItem mi = null;
if (device != null) {
mi = createActionModeMenuItem(actionMode, menu, ON_OFF_ACTION_ID, R.string.shared_string_ok, 0,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
// mi = createActionModeMenuItem(actionMode, menu, ON_OFF_ACTION_ID, R.string.shared_string_ok, 0,
// MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
mode.setTitle(device.getVisibleName());
}
if (device != null && device.getLastLocation() != null) {
createActionModeMenuItem(actionMode, menu, SHOW_ON_MAP_ID, R.string.shared_string_show_on_map, R.drawable.ic_action_marker_dark,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
if (device.getLastLocation() != null) {
createActionModeMenuItem(actionMode, menu, SHOW_ON_MAP_ID, R.string.shared_string_show_on_map,
R.drawable.ic_action_marker_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
MenuItem menuItem = createActionModeMenuItem(actionMode, menu, TRACK_DEV_ID,
R.string.osmo_set_moving_target, R.drawable.ic_action_flage_dark,
// // there is a bug in Android 4.2 layout
// device.getLastLocation() != null ? MenuItemCompat.SHOW_AS_ACTION_NEVER :
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
menuItem.setTitleCondensed(getString(R.string.osmo_follow));
}
createActionModeMenuItem(actionMode, menu, SETTINGS_DEV_ID, R.string.shared_string_settings,
R.drawable.ic_action_settings,
// // there is a bug in Android 4.2 layout
// device.getLastLocation() != null ? MenuItemCompat.SHOW_AS_ACTION_NEVER :
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
createActionModeMenuItem(actionMode, menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark,
// there is a bug in Android 4.2 layout
device != null && device.getLastLocation() != null ? MenuItemCompat.SHOW_AS_ACTION_NEVER : MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
///
if (device != null) {
createActionModeMenuItem(actionMode, menu, SETTINGS_DEV_ID, R.string.shared_string_settings, R.drawable.ic_action_settings,
// there is a bug in Android 4.2 layout
device.getLastLocation() != null ? MenuItemCompat.SHOW_AS_ACTION_NEVER : MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
if (device != null && device.getLastLocation() != null) {
MenuItem menuItem = createActionModeMenuItem(actionMode, menu, TRACK_DEV_ID, R.string.osmo_set_moving_target, R.drawable.ic_action_flage_dark,
// there is a bug in Android 4.2 layout
device.getLastLocation() != null ? MenuItemCompat.SHOW_AS_ACTION_NEVER : MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
menuItem.setTitleCondensed(getString(R.string.osmo_follow));
}
if (group != null) {
createActionModeMenuItem(actionMode, menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
mode.setTitle(group.getVisibleName(OsMoGroupsActivity.this));
createActionModeMenuItem(actionMode, menu, GROUP_INFO, R.string.osmo_group_info, R.drawable.ic_action_gabout_dark,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
if ((group != null && !group.isMainGroup()) || (device != null && device.getGroup().isMainGroup())) {
createActionModeMenuItem(actionMode, menu, DELETE_ACTION_ID, R.string.shared_string_delete,
R.drawable.ic_action_delete_dark,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
@ -551,18 +546,15 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
showSettingsDialog(device);
} else if (item.getItemId() == DELETE_ACTION_ID) {
Builder bld = new AlertDialog.Builder(OsMoGroupsActivity.this);
String name = (selectedObject instanceof OsMoDevice) ? ((OsMoDevice) selectedObject).getVisibleName() :
((OsMoGroup) selectedObject).getVisibleName(OsMoGroupsActivity.this);
bld.setTitle(getString(
selectedObject instanceof OsMoDevice ? R.string.delete_confirmation_msg :
R.string.osmo_leave_confirmation_msg, name));
String name = ((OsMoGroup) selectedObject).getVisibleName(OsMoGroupsActivity.this);
bld.setTitle(getString(R.string.osmo_leave_confirmation_msg, name));
bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Object obj = selectedObject;
quitSelectionMode();
deleteObject(obj);
deleteObject((OsMoGroup) obj);
}
});
bld.setNegativeButton(R.string.shared_string_no, null);
@ -570,11 +562,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
} else if (item.getItemId() == GROUP_INFO) {
showGroupInfo(group);
} else if (item.getItemId() == SHARE_ID) {
if (device != null) {
shareTrackerId(device.getVisibleName(), device.getTrackerId());
} else {
shareOsMoGroup(group.getVisibleName(app), group.getGroupId());
}
shareOsMoGroup(group.getVisibleName(app), group.getGroupId());
} else if (item.getItemId() == SHOW_ON_MAP_ID) {
if (device != null) {
Location location = device.getLastLocation();
@ -595,22 +583,13 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
private void onOffAction(CompoundButton bt) {
if ((selectedObject instanceof OsMoDevice)) {
OsMoDevice d = (OsMoDevice) selectedObject;
if (bt.isChecked()) {
osMoPlugin.getGroups().connectDevice(d);
} else {
osMoPlugin.getGroups().disconnectDevice(d);
}
OsMoGroup g = (OsMoGroup) selectedObject;
if (bt.isChecked()) {
String operation = osMoPlugin.getGroups().connectGroup(g);
startLongRunningOperation(operation);
} else {
OsMoGroup g = (OsMoGroup) selectedObject;
if (bt.isChecked()) {
String operation = osMoPlugin.getGroups().connectGroup(g);
startLongRunningOperation(operation);
} else {
String operation = osMoPlugin.getGroups().disconnectGroup(g);
startLongRunningOperation(operation);
}
String operation = osMoPlugin.getGroups().disconnectGroup(g);
startLongRunningOperation(operation);
}
quitSelectionMode();
}
@ -662,22 +641,15 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
protected void deleteObject(Object selectedObject) {
if(selectedObject instanceof OsMoDevice) {
OsMoDevice d = (OsMoDevice)selectedObject;
osMoPlugin.getGroups().deleteDevice(d);
adapter.update(d.getGroup());
adapter.notifyDataSetChanged();
} else {
if (!checkOperationIsNotRunning()) {
return;
}
String operation = osMoPlugin.getGroups().leaveGroup((OsMoGroup) selectedObject);
startLongRunningOperation(operation);
adapter.update((OsMoGroup) selectedObject);
adapter.notifyDataSetChanged();
protected void deleteObject(OsMoGroup selectedObject) {
if (!checkOperationIsNotRunning()) {
return;
}
String operation = osMoPlugin.getGroups().leaveGroup((OsMoGroup) selectedObject);
startLongRunningOperation(operation);
adapter.update((OsMoGroup) selectedObject);
adapter.notifyDataSetChanged();
}
private void quitSelectionMode() {
@ -729,24 +701,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
private void shareSession() {
Builder bld = new AlertDialog.Builder(this);
bld.setItems(new String[] {
getString(R.string.osmo_share_current_session),
getString(R.string.osmo_share_connect_device)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
shareSessionUrl(osMoPlugin, OsMoGroupsActivity.this);
} else {
OsMoService service = osMoPlugin.getService();
SessionInfo ci = service.getCurrentSessionInfo();
shareTrackerId("", ci == null ? null : ci.trackerId);
}
}
});
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.show();
shareSessionUrl(osMoPlugin, OsMoGroupsActivity.this);
}
public static void shareSessionUrl(OsMoPlugin osMoPlugin, Activity ctx) {
@ -762,22 +717,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
}
private void shareTrackerId(String name, String trackerId) {
if(trackerId == null) {
AccessibleToast.makeText(this, R.string.osmo_auth_pending, Toast.LENGTH_SHORT).show();
} else {
ShareDialog dlg = new ShareDialog(this);
String url = OsMoService.SHARE_TRACKER_URL + Uri.encode(trackerId);
if(name != null && name.length() > 0){
url += "&name="+Uri.encode(name);
}
dlg.setTitle(getString(R.string.osmo_tracker_id));
dlg.viewContent(trackerId);
dlg.shareURLOrText(url, getString(R.string.osmo_tracker_id_share, trackerId, name, url), null);
dlg.showDialog();
}
}
private void shareOsMoGroup(String name, String groupId) {
ShareDialog dlg = new ShareDialog(this);
String url = OsMoService.SHARE_GROUP_URL +Uri.encode(groupId)+"&name="+Uri.encode(name);
@ -1008,38 +947,22 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
private void connectToDevice() {
Builder builder = new AlertDialog.Builder(this);
final View v = getLayoutInflater().inflate(R.layout.osmo_connect_to_device, getExpandableListView(), false);
final RadioButton device = (RadioButton) v.findViewById(R.id.ConnectToDevice);
//final RadioButton group = (RadioButton) v.findViewById(R.id.ConnectToGroup);
final TextView labelTracker = (TextView ) v.findViewById(R.id.LabelTrackerId);
final TextView labelName = (TextView ) v.findViewById(R.id.LabelName);
final EditText tracker = (EditText) v.findViewById(R.id.TrackerId);
final EditText name = (EditText) v.findViewById(R.id.Name);
final View mgv = v.findViewById(R.id.MyGroupName);
final EditText nickname = (EditText) v.findViewById(R.id.NickName);
nickname.setText(app.getSettings().OSMO_USER_NAME.get());
device.setChecked(true);
device.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
labelTracker.setText(R.string.osmo_connect_to_device_tracker_id);
labelName.setText(R.string.osmo_connect_to_device_name);
name.setVisibility(View.VISIBLE);
labelName.setVisibility(View.VISIBLE);
mgv.setVisibility(View.GONE);
} else {
labelTracker.setText(R.string.osmo_connect_to_group_id);
labelName.setText(R.string.osmo_group_name);
name.setHint(R.string.osmo_use_server_name);
name.setVisibility(View.GONE);
labelName.setVisibility(View.GONE);
mgv.setVisibility(View.VISIBLE);
}
}
});
labelTracker.setText(R.string.osmo_connect_to_group_id);
labelName.setText(R.string.osmo_group_name);
name.setHint(R.string.osmo_use_server_name);
name.setVisibility(View.GONE);
labelName.setVisibility(View.GONE);
mgv.setVisibility(View.VISIBLE);
builder.setView(v);
builder.setNegativeButton(R.string.shared_string_cancel, null);
@ -1051,27 +974,20 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
final String id = tracker.getText().toString();
String nick = nickname.getText().toString().isEmpty() ? "user" : nickname.getText().toString();
if(id.length() == 0) {
if (id.length() == 0) {
app.showToastMessage(R.string.osmo_specify_tracker_id);
connectToDevice();
return;
}
if(device.isChecked()) {
OsMoDevice dev = osMoPlugin.getGroups().addConnectedDevice(id, nameUser,
ColorDialogs.getRandomColor());
adapter.update(dev.group);
adapter.notifyDataSetChanged();
} else {
if(!checkOperationIsNotRunning()) {
return;
}
joinGroup = true;
String op = osMoPlugin.getGroups().joinGroup(id, nameUser, nick);
if(app.getSettings().OSMO_USER_PWD.get() == null) {
app.getSettings().OSMO_USER_NAME.set(nick);
}
startLongRunningOperation(op);
if (!checkOperationIsNotRunning()) {
return;
}
joinGroup = true;
String op = osMoPlugin.getGroups().joinGroup(id, nameUser, nick);
if (app.getSettings().OSMO_USER_PWD.get() == null) {
app.getSettings().OSMO_USER_NAME.set(nick);
}
startLongRunningOperation(op);
}
});
builder.create().show();

View file

@ -43,39 +43,21 @@ public class OsMoGroupsStorage {
private OsmandPreference<String> pref;
private OsMoGroups service;
private ConcurrentHashMap<String, OsMoGroup> groups = new ConcurrentHashMap<String, OsMoGroup>();
private OsMoGroup mainGroup;
public OsMoGroupsStorage(OsMoGroups service, OsmandPreference<String> pref) {
this.service = service;
this.pref = pref;
mainGroup = new OsMoGroup();
groups.put("", mainGroup);
}
public OsMoGroup getMainGroup() {
return mainGroup;
}
public Collection<OsMoGroup> getGroups() {
return groups.values();
}
public void loadOnlyMainGroup() {
String grp = pref.get();
try {
JSONObject obj = new JSONObject(grp);
parseGroupUsers(mainGroup, obj);
} catch (JSONException e) {
e.printStackTrace();
service.showErrorMessage(e.getMessage());
}
}
public void load() {
String grp = pref.get();
try {
JSONObject obj = new JSONObject(grp);
parseGroupUsers(mainGroup, obj);
if(!obj.has(GROUPS)) {
return;
}
@ -115,7 +97,6 @@ public class OsMoGroupsStorage {
public void save() {
JSONObject mainObj = new JSONObject();
try {
saveGroupUsers(mainGroup, mainObj);
JSONArray ar = new JSONArray();
for(OsMoGroup gr : groups.values()) {
if(gr.isMainGroup()) {
@ -493,7 +474,7 @@ public class OsMoGroupsStorage {
}
for (String id: toDelete) {
OsMoGroup group = getGroup(id);
if ((group != null) && (!group.equals(mainGroup))) {
if (group != null) {
deleteGroup(group);
}
}
@ -501,7 +482,6 @@ public class OsMoGroupsStorage {
public void clearGroups() {
groups.clear();
groups.put("", mainGroup);
}
}

View file

@ -40,13 +40,6 @@ public class OsMoIntentHandler extends AsyncTask<Intent, Void, String> {
name = "";
}
plugin.getGroups().joinGroup(gid, name, app.getSettings().OSMO_USER_NAME.get());
} else if(lastPath.equals("connect")) {
String gid = data.getQueryParameter("id");
String name = data.getQueryParameter("name");
if(name == null) {
name = gid;
}
plugin.getGroups().addConnectedDevice(gid, name, 0);
}
}
return null;