From f8c455349ce83accbc77fe429dc8cf6dec315cb4 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Fri, 22 Dec 2017 12:23:59 +0200 Subject: [PATCH] Fix transport stops --- .../FavouritePointMenuController.java | 12 ++++- .../controllers/TransportStopController.java | 49 +++++-------------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java index 12eee1afb4..81da068960 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java @@ -20,10 +20,14 @@ import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragment; import net.osmand.util.Algorithms; +import java.util.ArrayList; +import java.util.List; + public class FavouritePointMenuController extends MenuController { private FavouritePoint fav; private MapMarker mapMarker; + private List routes = new ArrayList<>(); public FavouritePointMenuController(MapActivity mapActivity, PointDescription pointDescription, final FavouritePoint fav) { super(new FavouritePointMenuBuilder(mapActivity, fav), pointDescription, mapActivity); @@ -43,7 +47,8 @@ public class FavouritePointMenuController extends MenuController { if (getObject() instanceof TransportStop) { TransportStop stop = (TransportStop) getObject(); TransportStopController transportStopController = new TransportStopController(getMapActivity(), pointDescription, stop); - transportStopController.processTransportStop(builder); + routes = transportStopController.processTransportStop(); + builder.setRoutes(routes); } } @@ -59,6 +64,11 @@ public class FavouritePointMenuController extends MenuController { return fav; } + @Override + public List getTransportStopRoutes() { + return routes; + } + @Override public boolean handleSingleTapOnMap() { Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(FavoritePointEditor.TAG); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 30b50155d9..a0bc74cab8 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -82,14 +82,16 @@ public class TransportStopController extends MenuController { PointDescription pointDescription, TransportStop transportStop) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); this.transportStop = transportStop; - processTransportStop(builder); + routes = processTransportStop(); + builder.setRoutes(routes); } @Override protected void setObject(Object object) { if (object instanceof TransportStop) { this.transportStop = (TransportStop) object; - processTransportStop(builder); + routes = processTransportStop(); + builder.setRoutes(routes); } } @@ -127,33 +129,8 @@ public class TransportStopController extends MenuController { return getPointDescription().getTypeName(); } - public void addPlainMenuItems(MenuBuilder builder, final LatLon latLon) { - for (final TransportStopRoute r : routes) { - OnClickListener listener = new OnClickListener() { - @Override - public void onClick(View arg0) { - MapContextMenu mm = getMapActivity().getContextMenu(); - PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, - r.getDescription(getMapActivity().getMyApplication(), false)); - mm.show(latLon, pd, r); - TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); - stopsLayer.setRoute(r.route); - int cz = r.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox()); - getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom()); - } - }; - if (r.type == null) { - builder.addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.getDescription(getMapActivity().getMyApplication(), true), - false, false, listener ); - } else { - builder.addPlainMenuItem(r.type.getResourceId(), r.getDescription(getMapActivity().getMyApplication(), true), - false, false, listener); - } - } - } - - public void processTransportStop(MenuBuilder builder) { - routes.clear(); + public List processTransportStop() { + ArrayList routes = new ArrayList<>(); List reps = getMapActivity().getMyApplication() .getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude()); @@ -164,14 +141,14 @@ public class TransportStopController extends MenuController { if (t.acceptTransportStop(transportStop)) { boolean empty = transportStop.getReferencesToRoutes() == null || transportStop.getReferencesToRoutes().length == 0; if(!empty) { - addRoutes(useEnglishNames, t, transportStop, transportStop, 0); + addRoutes(routes, useEnglishNames, t, transportStop, transportStop, 0); } ArrayList ls = new ArrayList<>(); QuadRect ll = MapUtils.calculateLatLonBbox(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude(), 150); t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null); for(TransportStop tstop : ls) { if(tstop.getId().longValue() != transportStop.getId().longValue() || empty) { - addRoutes(useEnglishNames, t, tstop, transportStop, + addRoutes(routes, useEnglishNames, t, tstop, transportStop, (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation())); } } @@ -193,10 +170,10 @@ public class TransportStopController extends MenuController { } }); - builder.setRoutes(routes); + return routes; } - private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) { + private void addRoutes(List routes, boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) { Collection rts = t.getRouteForStop(s); if (rts != null) { for (TransportRoute rs : rts) { @@ -204,7 +181,7 @@ public class TransportStopController extends MenuController { if (topType == null && type != null && type.isTopType()) { topType = type; } - if (!containsRef(rs)) { + if (!containsRef(routes, rs)) { TransportStopRoute r = new TransportStopRoute(); r.type = type; r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName(); @@ -212,13 +189,13 @@ public class TransportStopController extends MenuController { r.refStop = refStop; r.stop = s; r.distance = dist; - this.routes.add(r); + routes.add(r); } } } } - private boolean containsRef(TransportRoute transportRoute) { + private boolean containsRef(List routes, TransportRoute transportRoute) { for (TransportStopRoute route : routes) { if (route.route.getRef().equals(transportRoute.getRef())) { return true;