This commit is contained in:
Chumva 2018-06-08 17:13:24 +03:00 committed by crimean
parent 3892f944ac
commit 6854d9e690
5 changed files with 72 additions and 4 deletions

View file

@ -2,6 +2,7 @@ package net.osmand.data;
public class TransportStop extends MapObject { public class TransportStop extends MapObject {
private int[] referencesToRoutes = null; private int[] referencesToRoutes = null;
private Amenity amenity;
public int distance; public int distance;
public TransportStop(){ public TransportStop(){
@ -15,4 +16,11 @@ public class TransportStop extends MapObject {
this.referencesToRoutes = referencesToRoutes; this.referencesToRoutes = referencesToRoutes;
} }
public Amenity getAmenity() {
return amenity;
}
public void setAmenity(Amenity amenity) {
this.amenity = amenity;
}
} }

View file

@ -0,0 +1,34 @@
package net.osmand.plus.mapcontextmenu.builders;
import android.view.View;
import net.osmand.data.Amenity;
import net.osmand.data.TransportStop;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
public class TransportStopMenuBuilder extends MenuBuilder {
private final TransportStop transportStop;
private Amenity amenity;
public TransportStopMenuBuilder(MapActivity mapActivity, final TransportStop transportStop) {
super(mapActivity);
this.transportStop = transportStop;
acquireOriginObject();
}
private void acquireOriginObject() {
amenity = transportStop.getAmenity();
}
@Override
public void buildInternal(View view) {
if (amenity != null) {
AmenityMenuBuilder builder = new AmenityMenuBuilder(mapActivity, amenity);
builder.setLatLon(getLatLon());
builder.setLight(light);
builder.buildInternal(view);
}
}
}

View file

@ -2,16 +2,18 @@ package net.osmand.plus.mapcontextmenu.controllers;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.TransportRoute; import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.mapcontextmenu.builders.TransportStopMenuBuilder;
import net.osmand.plus.resources.TransportIndexRepository; import net.osmand.plus.resources.TransportIndexRepository;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.transport.TransportStopType; import net.osmand.plus.transport.TransportStopType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -33,7 +35,7 @@ public class TransportStopController extends MenuController {
public TransportStopController(@NonNull MapActivity mapActivity, public TransportStopController(@NonNull MapActivity mapActivity,
@NonNull PointDescription pointDescription, @NonNull PointDescription pointDescription,
@NonNull TransportStop transportStop) { @NonNull TransportStop transportStop) {
super(new MenuBuilder(mapActivity), pointDescription, mapActivity); super(new TransportStopMenuBuilder(mapActivity, transportStop), pointDescription, mapActivity);
this.transportStop = transportStop; this.transportStop = transportStop;
processRoutes(); processRoutes();
} }
@ -163,4 +165,13 @@ public class TransportStopController extends MenuController {
return false; return false;
} }
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
Amenity amenity = transportStop.getAmenity();
if (amenity != null) {
AmenityMenuController.addTypeMenuItem(amenity, builder);
} else {
addMyLocationToPlainItems(latLon);
}
}
} }

View file

@ -19,6 +19,7 @@ import android.widget.Toast;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.TransportStop;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
@ -196,7 +197,8 @@ public class OsmEditingPlugin extends OsmandPlugin {
} else if (resId == R.string.context_menu_item_modify_note) { } else if (resId == R.string.context_menu_item_modify_note) {
modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj); modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj);
} else if (resId == R.string.poi_context_menu_modify) { } else if (resId == R.string.poi_context_menu_modify) {
EditPoiDialogFragment.showEditInstance((Amenity) selectedObj, mapActivity); EditPoiDialogFragment.showEditInstance(selectedObj instanceof TransportStop ?
((TransportStop) selectedObj).getAmenity() : (Amenity) selectedObj, mapActivity);
} else if (resId == R.string.poi_context_menu_modify_osm_change) { } else if (resId == R.string.poi_context_menu_modify_osm_change) {
final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity(); final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity();
EditPoiDialogFragment.createInstance(entity, false) EditPoiDialogFragment.createInstance(entity, false)
@ -223,6 +225,18 @@ public class OsmEditingPlugin extends OsmandPlugin {
.setOrder(MODIFY_OSM_CHANGE_ITEM_ORDER) .setOrder(MODIFY_OSM_CHANGE_ITEM_ORDER)
.setListener(listener) .setListener(listener)
.createItem()); .createItem());
} else if (selectedObj instanceof TransportStop && ((TransportStop) selectedObj).getAmenity() != null) {
TransportStop transportStop = (TransportStop) selectedObj;
Amenity amenity = transportStop.getAmenity();
final PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
isEditable = !amenity.getType().isWiki() && poiType != null && !poiType.isNotEditableOsm();
if (isEditable) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity)
.setIcon(R.drawable.ic_action_edit_dark)
.setOrder(MODIFY_POI_ITEM_ORDER)
.setListener(listener)
.createItem());
}
} else { } else {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity)
.setIcon(R.drawable.ic_action_plus_dark) .setIcon(R.drawable.ic_action_plus_dark)

View file

@ -760,6 +760,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
for (TransportStop transportStop : transportStops) { for (TransportStop transportStop : transportStops) {
if (transportStop.getName().startsWith(amenity.getName())) { if (transportStop.getName().startsWith(amenity.getName())) {
amenityTransportStops.add(transportStop); amenityTransportStops.add(transportStop);
transportStop.setAmenity(amenity);
} }
} }
if (amenityTransportStops.size() > 0) { if (amenityTransportStops.size() > 0) {