Divided routes into two arraylists and refactored code
This commit is contained in:
parent
6463239b69
commit
9f18f996ba
3 changed files with 70 additions and 66 deletions
|
@ -93,7 +93,6 @@
|
|||
android:gravity="top"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:paddingLeft="@dimen/context_menu_padding_margin_default"
|
||||
android:paddingRight="@dimen/context_menu_padding_margin_default">
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
|
@ -104,7 +103,7 @@
|
|||
android:layout_marginEnd="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_marginRight="@dimen/context_menu_padding_margin_small"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="emm------"/>
|
||||
/>
|
||||
<GridView
|
||||
android:id="@+id/transport_stop_nearby_routes_grid"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -491,43 +491,29 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
zoomButtonsView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
GridView localTransportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_routes_grid);
|
||||
GridView nearbyTransportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_nearby_routes_grid);
|
||||
TextView nearbRoutesWithinTv = (TextView) view.findViewById(R.id.nearby_routes_within);
|
||||
List<TransportStopRoute> allTransportStopRoutes = menu.getTransportStopRoutes();
|
||||
List<TransportStopRoute> localTransportStopRoutes = new ArrayList<>();
|
||||
List<TransportStopRoute> nearbyTransportStopRoutes = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
|
||||
GridView transportStopRoutesGrid2 = (GridView) view.findViewById(R.id.transport_stop_nearby_routes_grid);
|
||||
GridView transportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_routes_grid);
|
||||
|
||||
List<TransportStopRoute> transportStopRoutes = menu.getTransportStopRoutes();
|
||||
List<TransportStopRoute> transportStopRoutes2=new ArrayList<>();
|
||||
|
||||
if (transportStopRoutes != null && transportStopRoutes.size() > 0) {
|
||||
|
||||
Iterator<TransportStopRoute> iter = transportStopRoutes.iterator();
|
||||
int distance=0;
|
||||
while (iter.hasNext()) {
|
||||
TransportStopRoute r = iter.next();
|
||||
boolean emm = r.refStop != null && !r.refStop.getName().equals(r.stop.getName());
|
||||
if (emm) {
|
||||
distance=r.distance;
|
||||
transportStopRoutes2.add(r);
|
||||
iter.remove();
|
||||
if (allTransportStopRoutes != null && allTransportStopRoutes.size() > 0) {
|
||||
int distance = 0;
|
||||
for (TransportStopRoute route:allTransportStopRoutes) {
|
||||
boolean isCurrentRouteNearby = route.refStop != null && !route.refStop.getName().equals(route.stop.getName());
|
||||
if (isCurrentRouteNearby) {
|
||||
distance = route.distance;
|
||||
nearbyTransportStopRoutes.add(route);
|
||||
} else {
|
||||
localTransportStopRoutes.add(route);
|
||||
}
|
||||
}
|
||||
if(transportStopRoutes2.size()>0){
|
||||
TextView nearbRoutesWithinTv = (TextView) view.findViewById(R.id.nearby_routes_within);
|
||||
nearbRoutesWithinTv.setText("NEAR IN "+distance+ " M:");
|
||||
}
|
||||
|
||||
|
||||
final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getMyApplication(), transportStopRoutes, nightMode);
|
||||
|
||||
final TransportStopRouteAdapter adapter2 = new TransportStopRouteAdapter(getMyApplication(), transportStopRoutes2, nightMode);
|
||||
|
||||
adapter.setListener(new TransportStopRouteAdapter.OnClickListener() {
|
||||
final TransportStopRouteAdapter localAdapter = new TransportStopRouteAdapter(getMyApplication(), localTransportStopRoutes, nightMode);
|
||||
localAdapter.setListener(new TransportStopRouteAdapter.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(int position) {
|
||||
TransportStopRoute route = adapter.getItem(position);
|
||||
TransportStopRoute route = localAdapter.getItem(position);
|
||||
if (route != null) {
|
||||
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE,
|
||||
route.getDescription(getMapActivity().getMyApplication(), false));
|
||||
|
@ -539,28 +525,37 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
}
|
||||
});
|
||||
transportStopRoutesGrid.setAdapter(adapter);
|
||||
transportStopRoutesGrid.setVisibility(View.VISIBLE);
|
||||
localTransportStopRoutesGrid.setAdapter(localAdapter);
|
||||
localTransportStopRoutesGrid.setVisibility(View.VISIBLE);
|
||||
|
||||
adapter2.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);
|
||||
int cz = route.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
||||
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
||||
if (nearbyTransportStopRoutes.size() > 0) {
|
||||
nearbRoutesWithinTv.setText("NEAR IN " + distance + " M:");
|
||||
final TransportStopRouteAdapter nearbyAdapter = new TransportStopRouteAdapter(getMyApplication(), nearbyTransportStopRoutes, nightMode);
|
||||
nearbyAdapter.setListener(new TransportStopRouteAdapter.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(int position) {
|
||||
TransportStopRoute route = nearbyAdapter.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);
|
||||
int cz = route.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
||||
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
transportStopRoutesGrid2.setAdapter(adapter2);
|
||||
transportStopRoutesGrid2.setVisibility(View.VISIBLE);
|
||||
});
|
||||
nearbyTransportStopRoutesGrid.setAdapter(nearbyAdapter);
|
||||
nearbyTransportStopRoutesGrid.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
nearbyTransportStopRoutesGrid.setVisibility(View.GONE);
|
||||
nearbRoutesWithinTv.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
transportStopRoutesGrid2.setVisibility(View.GONE);
|
||||
localTransportStopRoutesGrid.setVisibility(View.GONE);
|
||||
nearbyTransportStopRoutesGrid.setVisibility(View.GONE);
|
||||
nearbRoutesWithinTv.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
View buttonsBottomBorder = view.findViewById(R.id.buttons_bottom_border);
|
||||
|
|
|
@ -64,6 +64,7 @@ import net.osmand.util.MapUtils;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -843,23 +844,32 @@ public class MenuBuilder {
|
|||
|
||||
private CollapsableView getCollapsableTransportStopRoutesView(final Context context, boolean collapsed, boolean isNearbyRoutes) {
|
||||
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, false);
|
||||
boolean hasNearByRoutes = false;
|
||||
for (int i = 0; i < routes.size(); i++) {
|
||||
boolean isCurrentRouteNearby = routes.get(i).refStop != null && !routes.get(i).refStop.getName().equals(routes.get(i).stop.getName());
|
||||
final TransportStopRoute r = routes.get(i);
|
||||
if (isNearbyRoutes && isCurrentRouteNearby) {
|
||||
hasNearByRoutes = true;
|
||||
boolean showDivider = i < routes.size() - 1;
|
||||
buildTransportRouteRow(view, r, createClickListenerForCollapsableTransportStopRoutersView(r), showDivider);
|
||||
} else if (!isNearbyRoutes) {
|
||||
List<TransportStopRoute> localTransportStopRoutes = new ArrayList<>();
|
||||
List<TransportStopRoute> nearbyTransportStopRoutes = new ArrayList<>();
|
||||
if (routes != null && routes.size() > 0) {
|
||||
for (TransportStopRoute route:routes) {
|
||||
boolean isCurrentRouteNearby = route.refStop != null && !route.refStop.getName().equals(route.stop.getName());
|
||||
if (isCurrentRouteNearby) {
|
||||
continue;
|
||||
nearbyTransportStopRoutes.add(route);
|
||||
} else {
|
||||
localTransportStopRoutes.add(route);
|
||||
}
|
||||
}
|
||||
if (!isNearbyRoutes) {
|
||||
for (int i = 0; i < localTransportStopRoutes.size(); i++) {
|
||||
final TransportStopRoute r = localTransportStopRoutes.get(i);
|
||||
boolean showDivider = i < localTransportStopRoutes.size() - 1;
|
||||
buildTransportRouteRow(view, r, createClickListenerForCollapsableTransportStopRoutersView(r), showDivider);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < nearbyTransportStopRoutes.size(); i++) {
|
||||
final TransportStopRoute r = nearbyTransportStopRoutes.get(i);
|
||||
boolean showDivider = i < nearbyTransportStopRoutes.size() - 1;
|
||||
buildTransportRouteRow(view, r, createClickListenerForCollapsableTransportStopRoutersView(r), showDivider);
|
||||
}
|
||||
boolean showDivider = i < routes.size() - 1;
|
||||
buildTransportRouteRow(view, r, createClickListenerForCollapsableTransportStopRoutersView(r), showDivider);
|
||||
}
|
||||
}
|
||||
if (!hasNearByRoutes && isNearbyRoutes) {
|
||||
if (isNearbyRoutes && nearbyTransportStopRoutes.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return new CollapsableView(view, this, collapsed);
|
||||
|
|
Loading…
Reference in a new issue