From 92235adeb189ec91d1fd7bea2b1d10601a00e21f Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 8 Jun 2018 17:13:24 +0300 Subject: [PATCH 1/4] add link to amenity for transportStop and create TransportStopMenuBuilder for amenity tags --- .../src/net/osmand/data/TransportStop.java | 8 +++++ .../builders/TransportStopMenuBuilder.java | 34 +++++++++++++++++++ .../controllers/TransportStopController.java | 17 ++++++++-- .../osmand/plus/osmedit/OsmEditingPlugin.java | 16 ++++++++- .../osmand/plus/views/ContextMenuLayer.java | 1 + 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/TransportStopMenuBuilder.java diff --git a/OsmAnd-java/src/net/osmand/data/TransportStop.java b/OsmAnd-java/src/net/osmand/data/TransportStop.java index e08afc39b5..3cc84afc18 100644 --- a/OsmAnd-java/src/net/osmand/data/TransportStop.java +++ b/OsmAnd-java/src/net/osmand/data/TransportStop.java @@ -2,6 +2,7 @@ package net.osmand.data; public class TransportStop extends MapObject { private int[] referencesToRoutes = null; + private Amenity amenity; public int distance; public TransportStop(){ @@ -15,4 +16,11 @@ public class TransportStop extends MapObject { this.referencesToRoutes = referencesToRoutes; } + public Amenity getAmenity() { + return amenity; + } + + public void setAmenity(Amenity amenity) { + this.amenity = amenity; + } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/TransportStopMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/TransportStopMenuBuilder.java new file mode 100644 index 0000000000..a4266c1f4c --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/TransportStopMenuBuilder.java @@ -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); + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 2778b67a4d..c4bd2655f0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -1,13 +1,15 @@ package net.osmand.plus.mapcontextmenu.controllers; +import net.osmand.data.Amenity; +import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; import net.osmand.data.TransportRoute; import net.osmand.data.TransportStop; import net.osmand.plus.R; +import net.osmand.plus.mapcontextmenu.builders.TransportStopMenuBuilder; import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.resources.TransportIndexRepository; import net.osmand.plus.transport.TransportStopType; @@ -29,8 +31,8 @@ public class TransportStopController extends MenuController { private TransportStopType topType; public TransportStopController(MapActivity mapActivity, - PointDescription pointDescription, TransportStop transportStop) { - super(new MenuBuilder(mapActivity), pointDescription, mapActivity); + PointDescription pointDescription, TransportStop transportStop) { + super(new TransportStopMenuBuilder(mapActivity, transportStop), pointDescription, mapActivity); this.transportStop = transportStop; processRoutes(); } @@ -157,4 +159,13 @@ public class TransportStopController extends MenuController { 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); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index c4d30921d5..40e7c19be5 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -18,6 +18,7 @@ import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.data.Amenity; +import net.osmand.data.TransportStop; import net.osmand.osm.PoiType; import net.osmand.osm.edit.Node; import net.osmand.plus.ContextMenuAdapter; @@ -195,7 +196,8 @@ public class OsmEditingPlugin extends OsmandPlugin { } else if (resId == R.string.context_menu_item_modify_note) { modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj); } 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) { final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity(); EditPoiDialogFragment.createInstance(entity, false) @@ -222,6 +224,18 @@ public class OsmEditingPlugin extends OsmandPlugin { .setOrder(MODIFY_OSM_CHANGE_ITEM_ORDER) .setListener(listener) .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 { adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity) .setIcon(R.drawable.ic_action_plus_dark) diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 966d496de0..1fc00e95c2 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -760,6 +760,7 @@ public class ContextMenuLayer extends OsmandMapLayer { for (TransportStop transportStop : transportStops) { if (transportStop.getName().startsWith(amenity.getName())) { amenityTransportStops.add(transportStop); + transportStop.setAmenity(amenity); } } if (amenityTransportStops.size() > 0) { From 9de34ecf0c09f144f1a03da780542faceab2e212 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 8 Jun 2018 18:16:08 +0300 Subject: [PATCH 2/4] removed unnecessary changes --- .../builders/TransportStopMenuBuilder.java | 7 +------ .../controllers/TransportStopController.java | 2 +- .../osmand/plus/osmedit/OsmEditingPlugin.java | 21 +++++++------------ 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/TransportStopMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/TransportStopMenuBuilder.java index a4266c1f4c..daf43689d2 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/TransportStopMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/TransportStopMenuBuilder.java @@ -10,20 +10,15 @@ 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) { + Amenity amenity = transportStop.getAmenity(); if (amenity != null) { AmenityMenuBuilder builder = new AmenityMenuBuilder(mapActivity, amenity); builder.setLatLon(getLatLon()); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index c4bd2655f0..4de8f223c8 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -165,7 +165,7 @@ public class TransportStopController extends MenuController { if (amenity != null) { AmenityMenuController.addTypeMenuItem(amenity, builder); } else { - addMyLocationToPlainItems(latLon); + super.addPlainMenuItems(typeStr, pointDescription, latLon); } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 40e7c19be5..b4b7ba7c09 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -207,8 +207,13 @@ public class OsmEditingPlugin extends OsmandPlugin { } }; boolean isEditable = false; - if (selectedObj instanceof Amenity) { - Amenity amenity = (Amenity) selectedObj; + if (selectedObj instanceof Amenity || (selectedObj instanceof TransportStop && ((TransportStop) selectedObj).getAmenity() != null)) { + Amenity amenity; + if (selectedObj instanceof Amenity) { + amenity = (Amenity) selectedObj; + } else { + amenity = ((TransportStop) selectedObj).getAmenity(); + } final PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); isEditable = !amenity.getType().isWiki() && poiType !=null && !poiType.isNotEditableOsm(); } @@ -224,18 +229,6 @@ public class OsmEditingPlugin extends OsmandPlugin { .setOrder(MODIFY_OSM_CHANGE_ITEM_ORDER) .setListener(listener) .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 { adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity) .setIcon(R.drawable.ic_action_plus_dark) From 864f4ef7a97d985bc4f5d4cedc0a8c8351b6ef78 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 8 Jun 2018 18:22:11 +0300 Subject: [PATCH 3/4] add null check for selectedObj --- OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index b4b7ba7c09..d07d90386d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -196,8 +196,10 @@ public class OsmEditingPlugin extends OsmandPlugin { } else if (resId == R.string.context_menu_item_modify_note) { modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj); } else if (resId == R.string.poi_context_menu_modify) { - EditPoiDialogFragment.showEditInstance(selectedObj instanceof TransportStop ? - ((TransportStop) selectedObj).getAmenity() : (Amenity) selectedObj, mapActivity); + if (selectedObj != null) { + EditPoiDialogFragment.showEditInstance(selectedObj instanceof TransportStop ? + ((TransportStop) selectedObj).getAmenity() : (Amenity) selectedObj, mapActivity); + } } else if (resId == R.string.poi_context_menu_modify_osm_change) { final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity(); EditPoiDialogFragment.createInstance(entity, false) From e5503c277d74ff8870243e47d6a24191f60b1d4d Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 8 Jun 2018 18:33:02 +0300 Subject: [PATCH 4/4] removed unnecessary null check --- OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index d07d90386d..b4b7ba7c09 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -196,10 +196,8 @@ public class OsmEditingPlugin extends OsmandPlugin { } else if (resId == R.string.context_menu_item_modify_note) { modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj); } else if (resId == R.string.poi_context_menu_modify) { - if (selectedObj != null) { - EditPoiDialogFragment.showEditInstance(selectedObj instanceof TransportStop ? - ((TransportStop) selectedObj).getAmenity() : (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) { final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity(); EditPoiDialogFragment.createInstance(entity, false)