Fix transport stops
This commit is contained in:
parent
c9edb3aa4a
commit
f8c455349c
2 changed files with 24 additions and 37 deletions
|
@ -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<TransportStopController.TransportStopRoute> 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<TransportStopController.TransportStopRoute> getTransportStopRoutes() {
|
||||
return routes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSingleTapOnMap() {
|
||||
Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(FavoritePointEditor.TAG);
|
||||
|
|
|
@ -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<TransportStopRoute> processTransportStop() {
|
||||
ArrayList<TransportStopRoute> routes = new ArrayList<>();
|
||||
List<TransportIndexRepository> 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<TransportStop> 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<TransportStopRoute> routes, boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) {
|
||||
Collection<TransportRoute> 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<TransportStopRoute> routes, TransportRoute transportRoute) {
|
||||
for (TransportStopRoute route : routes) {
|
||||
if (route.route.getRef().equals(transportRoute.getRef())) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue