diff --git a/OsmAnd/res/layout/transport_stop_route_item.xml b/OsmAnd/res/layout/transport_stop_route_item.xml index 8d186872a8..2e0440c0a8 100644 --- a/OsmAnd/res/layout/transport_stop_route_item.xml +++ b/OsmAnd/res/layout/transport_stop_route_item.xml @@ -7,6 +7,7 @@ android:layout_height="wrap_content"> transportStopRoutes = menu.getTransportStopRoutes(); if (transportStopRoutes != null && transportStopRoutes.size() > 0) { - TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getContext(), transportStopRoutes, nightMode); + final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getContext(), transportStopRoutes, nightMode); + adapter.setListener(new TransportStopRouteAdapter.OnClickListener() { + @Override + public void onClick(int position) { + TransportStopRoute route = adapter.getItem(position); + if (route != null) { + PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, + route.getDescription(getMapActivity().getMyApplication(), false)); + menu.show(menu.getLatLon(), pd, route); + TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); + stopsLayer.setRoute(route.route); + int cz = route.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox()); + getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom()); + } + } + }); transportStopRoutesGrid.setAdapter(adapter); transportStopRoutesGrid.setVisibility(View.VISIBLE); } else { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java index 84a95d3d0d..3136684905 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java @@ -19,15 +19,20 @@ import java.util.List; public class TransportStopRouteAdapter extends ArrayAdapter { private boolean nightMode; + private OnClickListener listener; public TransportStopRouteAdapter(@NonNull Context context, @NonNull List objects, boolean nightMode) { super(context, 0, objects); this.nightMode = nightMode; } + public void setListener(OnClickListener listener) { + this.listener = listener; + } + @NonNull @Override - public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.transport_stop_route_item, parent, false); } @@ -40,6 +45,15 @@ public class TransportStopRouteAdapter extends ArrayAdapter gradientDrawableBg.setColor(ContextCompat.getColor(getContext(), getColor(transportStopRoute))); } + convertView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onClick(position); + } + } + }); + return convertView; } @@ -76,4 +90,8 @@ public class TransportStopRouteAdapter extends ArrayAdapter } return color; } + + public interface OnClickListener { + void onClick(int position); + } }