This commit is contained in:
Chumva 2018-09-13 16:56:53 +03:00
parent b4d79ee28c
commit 6c0895b6e9
5 changed files with 69 additions and 56 deletions

View file

@ -40,6 +40,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportRoute;
import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
@ -62,6 +63,7 @@ import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.views.controls.SingleTapConfirm;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
@ -645,7 +647,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
private TransportStopRouteAdapter createTransportStopRouteAdapter(List<TransportStopRoute> routes) {
final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getMyApplication(), routes, nightMode);
final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getMyApplication(), filterTransportRoutes(routes), nightMode);
adapter.setListener(new TransportStopRouteAdapter.OnClickListener() {
@Override
public void onClick(int position) {
@ -664,6 +666,25 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
return adapter;
}
private List<TransportStopRoute> filterTransportRoutes(List<TransportStopRoute> routes) {
List<TransportStopRoute> filteredRoutes = new ArrayList<>();
for (TransportStopRoute route : routes) {
if (!containsRef(filteredRoutes, route.route) && filteredRoutes.size() < 6) {
filteredRoutes.add(route);
}
}
return filteredRoutes;
}
private boolean containsRef(List<TransportStopRoute> routes, TransportRoute transportRoute) {
for (TransportStopRoute route : routes) {
if (route.route.getRef().equals(transportRoute.getRef())) {
return true;
}
}
return false;
}
private float getToolbarAlpha(int y) {
float a = 0;
if (menu != null && !menu.isLandscapeLayout()) {

View file

@ -554,17 +554,6 @@ public abstract class MenuController extends BaseMenuController implements Colla
@Nullable
protected List<TransportStopRoute> getSubTransportStopRoutes(boolean nearby) {
List<TransportStopRoute> allRoutes = getTransportStopRoutes();
if (allRoutes != null) {
List<TransportStopRoute> res = new ArrayList<>();
for (TransportStopRoute route : allRoutes) {
boolean isCurrentRouteNearby = route.refStop != null && !route.refStop.getName().equals(route.stop.getName());
if ((nearby && isCurrentRouteNearby) || (!nearby && !isCurrentRouteNearby)) {
res.add(route);
}
}
return res;
}
return null;
}

View file

@ -311,32 +311,21 @@ public class AmenityMenuController extends MenuController {
Collection<TransportRoute> rts = t.getRouteForStop(s);
if (rts != null) {
for (TransportRoute rs : rts) {
if (!containsRef(rs)) {
TransportStopType type = TransportStopType.findType(rs.getType());
if (isSubwayEntrance && type != TransportStopType.SUBWAY && dist > 150) {
continue;
}
TransportStopRoute r = new TransportStopRoute();
r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs;
r.stop = s;
if (amenity.getLocation().equals(s.getLocation()) || (isSubwayEntrance && type == TransportStopType.SUBWAY)) {
r.refStop = s;
}
r.distance = dist;
this.routes.add(r);
TransportStopType type = TransportStopType.findType(rs.getType());
if (isSubwayEntrance && type != TransportStopType.SUBWAY && dist > 150) {
continue;
}
TransportStopRoute r = new TransportStopRoute();
r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs;
r.stop = s;
if (amenity.getLocation().equals(s.getLocation()) || (isSubwayEntrance && type == TransportStopType.SUBWAY)) {
r.refStop = s;
}
r.distance = dist;
this.routes.add(r);
}
}
}
private boolean containsRef(TransportRoute transportRoute) {
for (TransportStopRoute route : routes) {
if (route.route.getRef().equals(transportRoute.getRef())) {
return true;
}
}
return false;
}
}

View file

@ -29,6 +29,7 @@ public class FavouritePointMenuController extends MenuController {
private FavouritePoint fav;
private MapMarker mapMarker;
private List<TransportStopRoute> routes = new ArrayList<>();
private TransportStopController transportStopController;
public FavouritePointMenuController(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, final @NonNull FavouritePoint fav) {
super(new FavouritePointMenuBuilder(mapActivity, fav), pointDescription, mapActivity);
@ -47,7 +48,7 @@ public class FavouritePointMenuController extends MenuController {
}
if (getObject() instanceof TransportStop) {
TransportStop stop = (TransportStop) getObject();
TransportStopController transportStopController = new TransportStopController(getMapActivity(), pointDescription, stop);
transportStopController = new TransportStopController(mapActivity, pointDescription, stop);
routes = transportStopController.processTransportStop();
builder.setRoutes(routes);
}
@ -75,6 +76,14 @@ public class FavouritePointMenuController extends MenuController {
return routes;
}
@Override
protected List<TransportStopRoute> getSubTransportStopRoutes(boolean nearby) {
if (transportStopController != null) {
return transportStopController.getSubTransportStopRoutes(nearby);
}
return null;
}
@Override
public boolean handleSingleTapOnMap() {
MapActivity mapActivity = getMapActivity();

View file

@ -72,6 +72,22 @@ public class TransportStopController extends MenuController {
return routes;
}
@Override
protected List<TransportStopRoute> getSubTransportStopRoutes(boolean nearby) {
List<TransportStopRoute> allRoutes = getTransportStopRoutes();
if (allRoutes != null) {
List<TransportStopRoute> res = new ArrayList<>();
for (TransportStopRoute route : allRoutes) {
boolean isCurrentRouteNearby = route.stop != null && !route.stop.equals(transportStop);
if ((nearby && isCurrentRouteNearby) || (!nearby && !isCurrentRouteNearby)) {
res.add(route);
}
}
return res;
}
return null;
}
@Override
public boolean needStreetName() {
return Algorithms.isEmpty(getNameStr());
@ -151,29 +167,18 @@ public class TransportStopController extends MenuController {
if (topType == null && type != null && type.isTopType()) {
topType = type;
}
if (!containsRef(routes, rs)) {
TransportStopRoute r = new TransportStopRoute();
r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs;
r.refStop = refStop;
r.stop = s;
r.distance = dist;
routes.add(r);
}
TransportStopRoute r = new TransportStopRoute();
r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs;
r.refStop = refStop;
r.stop = s;
r.distance = dist;
routes.add(r);
}
}
}
private boolean containsRef(List<TransportStopRoute> routes, TransportRoute transportRoute) {
for (TransportStopRoute route : routes) {
if (route.route.getRef().equals(transportRoute.getRef())) {
return true;
}
}
return false;
}
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
Amenity amenity = transportStop.getAmenity();