Fix transport stops

This commit is contained in:
PavelRatushnyi 2017-12-22 12:23:59 +02:00
parent c9edb3aa4a
commit f8c455349c
2 changed files with 24 additions and 37 deletions

View file

@ -20,10 +20,14 @@ import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragment; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragment;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
public class FavouritePointMenuController extends MenuController { public class FavouritePointMenuController extends MenuController {
private FavouritePoint fav; private FavouritePoint fav;
private MapMarker mapMarker; private MapMarker mapMarker;
private List<TransportStopController.TransportStopRoute> routes = new ArrayList<>();
public FavouritePointMenuController(MapActivity mapActivity, PointDescription pointDescription, final FavouritePoint fav) { public FavouritePointMenuController(MapActivity mapActivity, PointDescription pointDescription, final FavouritePoint fav) {
super(new FavouritePointMenuBuilder(mapActivity, fav), pointDescription, mapActivity); super(new FavouritePointMenuBuilder(mapActivity, fav), pointDescription, mapActivity);
@ -43,7 +47,8 @@ public class FavouritePointMenuController extends MenuController {
if (getObject() instanceof TransportStop) { if (getObject() instanceof TransportStop) {
TransportStop stop = (TransportStop) getObject(); TransportStop stop = (TransportStop) getObject();
TransportStopController transportStopController = new TransportStopController(getMapActivity(), pointDescription, stop); 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; return fav;
} }
@Override
public List<TransportStopController.TransportStopRoute> getTransportStopRoutes() {
return routes;
}
@Override @Override
public boolean handleSingleTapOnMap() { public boolean handleSingleTapOnMap() {
Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(FavoritePointEditor.TAG); Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(FavoritePointEditor.TAG);

View file

@ -82,14 +82,16 @@ public class TransportStopController extends MenuController {
PointDescription pointDescription, TransportStop transportStop) { PointDescription pointDescription, TransportStop transportStop) {
super(new MenuBuilder(mapActivity), pointDescription, mapActivity); super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
this.transportStop = transportStop; this.transportStop = transportStop;
processTransportStop(builder); routes = processTransportStop();
builder.setRoutes(routes);
} }
@Override @Override
protected void setObject(Object object) { protected void setObject(Object object) {
if (object instanceof TransportStop) { if (object instanceof TransportStop) {
this.transportStop = (TransportStop) object; this.transportStop = (TransportStop) object;
processTransportStop(builder); routes = processTransportStop();
builder.setRoutes(routes);
} }
} }
@ -127,33 +129,8 @@ public class TransportStopController extends MenuController {
return getPointDescription().getTypeName(); return getPointDescription().getTypeName();
} }
public void addPlainMenuItems(MenuBuilder builder, final LatLon latLon) { public List<TransportStopRoute> processTransportStop() {
for (final TransportStopRoute r : routes) { ArrayList<TransportStopRoute> routes = new ArrayList<>();
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();
List<TransportIndexRepository> reps = getMapActivity().getMyApplication() List<TransportIndexRepository> reps = getMapActivity().getMyApplication()
.getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(), .getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(),
transportStop.getLocation().getLongitude()); transportStop.getLocation().getLongitude());
@ -164,14 +141,14 @@ public class TransportStopController extends MenuController {
if (t.acceptTransportStop(transportStop)) { if (t.acceptTransportStop(transportStop)) {
boolean empty = transportStop.getReferencesToRoutes() == null || transportStop.getReferencesToRoutes().length == 0; boolean empty = transportStop.getReferencesToRoutes() == null || transportStop.getReferencesToRoutes().length == 0;
if(!empty) { if(!empty) {
addRoutes(useEnglishNames, t, transportStop, transportStop, 0); addRoutes(routes, useEnglishNames, t, transportStop, transportStop, 0);
} }
ArrayList<TransportStop> ls = new ArrayList<>(); ArrayList<TransportStop> ls = new ArrayList<>();
QuadRect ll = MapUtils.calculateLatLonBbox(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude(), 150); QuadRect ll = MapUtils.calculateLatLonBbox(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude(), 150);
t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null); t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
for(TransportStop tstop : ls) { for(TransportStop tstop : ls) {
if(tstop.getId().longValue() != transportStop.getId().longValue() || empty) { 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())); (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<TransportStopRoute> routes, boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) {
Collection<TransportRoute> rts = t.getRouteForStop(s); Collection<TransportRoute> rts = t.getRouteForStop(s);
if (rts != null) { if (rts != null) {
for (TransportRoute rs : rts) { for (TransportRoute rs : rts) {
@ -204,7 +181,7 @@ public class TransportStopController extends MenuController {
if (topType == null && type != null && type.isTopType()) { if (topType == null && type != null && type.isTopType()) {
topType = type; topType = type;
} }
if (!containsRef(rs)) { if (!containsRef(routes, rs)) {
TransportStopRoute r = new TransportStopRoute(); TransportStopRoute r = new TransportStopRoute();
r.type = type; r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName(); r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
@ -212,13 +189,13 @@ public class TransportStopController extends MenuController {
r.refStop = refStop; r.refStop = refStop;
r.stop = s; r.stop = s;
r.distance = dist; r.distance = dist;
this.routes.add(r); routes.add(r);
} }
} }
} }
} }
private boolean containsRef(TransportRoute transportRoute) { private boolean containsRef(List<TransportStopRoute> routes, TransportRoute transportRoute) {
for (TransportStopRoute route : routes) { for (TransportStopRoute route : routes) {
if (route.route.getRef().equals(transportRoute.getRef())) { if (route.route.getRef().equals(transportRoute.getRef())) {
return true; return true;