added const RADIUS and refactored two methods

This commit is contained in:
Chumva 2018-02-16 15:47:46 +02:00
parent 4a52e4fcd5
commit 37f6b89bd7
5 changed files with 40 additions and 24 deletions

View file

@ -792,6 +792,19 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
return null;
}
public List<TransportStopRoute> getLocalTransportStopRoutes() {
if (menuController != null) {
return menuController.getLocalTransportStopRoutes();
}
return null;
}
public List<TransportStopRoute> getNearbyTransportStopRoutes() {
if (menuController != null) {
return menuController.getNearbyTransportStopRoutes();
}
return null;
}
public void navigateButtonPressed() {
if (navigateInPedestrianMode()) {
settings.APPLICATION_MODE.set(ApplicationMode.PEDESTRIAN);

View file

@ -51,6 +51,7 @@ import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.AnimateDraggingMapThread;
@ -495,18 +496,18 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
TextView nearbRoutesWithinTv = (TextView) view.findViewById(R.id.nearby_routes_within_text_view);
LinearLayout nearbyRoutesLayoutToHide = (LinearLayout) view.findViewById(R.id.nearby_routes);
List<TransportStopRoute> localTransportStopRoutes = menu.getMenuController().getLocalTransportStopRoutes();
List<TransportStopRoute> nearbyTransportStopRoutes = menu.getMenuController().getNearbyTransportStopRoutes();
List<TransportStopRoute> localTransportStopRoutes = menu.getLocalTransportStopRoutes();
List<TransportStopRoute> nearbyTransportStopRoutes = menu.getNearbyTransportStopRoutes();
if (localTransportStopRoutes!=null&&localTransportStopRoutes.size() > 0) {
if (localTransportStopRoutes != null && localTransportStopRoutes.size() > 0) {
localTransportStopRoutesGrid.setAdapter(createTransportStopRouteAdapter(localTransportStopRoutes));
localTransportStopRoutesGrid.setVisibility(View.VISIBLE);
} else {
localTransportStopRoutesGrid.setVisibility(View.GONE);
}
if (nearbyTransportStopRoutes!=null&&nearbyTransportStopRoutes.size() > 0) {
if (nearbyTransportStopRoutes != null && nearbyTransportStopRoutes.size() > 0) {
String nearInDistance = getMyApplication().getString(R.string.transport_nearby_routes) + " "
+ OsmAndFormatter.getFormattedDistance(150, getMyApplication());
+ OsmAndFormatter.getFormattedDistance(TransportStopController.RADIUS, getMyApplication());
nearbRoutesWithinTv.setText(nearInDistance);
nearbyTransportStopRoutesGrid.setAdapter(createTransportStopRouteAdapter(nearbyTransportStopRoutes));
nearbyTransportStopRoutesGrid.setVisibility(View.VISIBLE);

View file

@ -54,6 +54,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.render.RenderingIcons;
@ -316,7 +317,7 @@ public class MenuBuilder {
CollapsableView collapsableView = getCollapsableTransportStopRoutesView(view.getContext(), false, true);
if (collapsableView != null) {
String routesWithingDistance = app.getString(R.string.transport_nearby_routes_within) + " " + OsmAndFormatter.getFormattedDistance(150, app);
String routesWithingDistance = app.getString(R.string.transport_nearby_routes_within) + " " + OsmAndFormatter.getFormattedDistance(TransportStopController.RADIUS,app);
buildRow(view, 0, null, routesWithingDistance, 0, true, collapsableView,
false, 0, false, null, true);
}
@ -845,8 +846,8 @@ public class MenuBuilder {
private CollapsableView getCollapsableTransportStopRoutesView(final Context context, boolean collapsed, boolean isNearbyRoutes) {
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, false);
List<TransportStopRoute> localTransportStopRoutes = mapContextMenu.getMenuController().getLocalTransportStopRoutes();
List<TransportStopRoute> nearbyTransportStopRoutes = mapContextMenu.getMenuController().getNearbyTransportStopRoutes();
List<TransportStopRoute> localTransportStopRoutes = mapContextMenu.getLocalTransportStopRoutes();
List<TransportStopRoute> nearbyTransportStopRoutes = mapContextMenu.getNearbyTransportStopRoutes();
if (!isNearbyRoutes) {
buildTransportRouteRows(view, localTransportStopRoutes);
} else {

View file

@ -523,14 +523,20 @@ public abstract class MenuController extends BaseMenuController implements Colla
return null;
}
public List<TransportStopRoute> getLocalTransportStopRoutes() {
private List<TransportStopRoute> getSubTransportStopRoutes(boolean isNearby) {
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 (!isCurrentRouteNearby) {
res.add(route);
if (isNearby) {
if (isCurrentRouteNearby) {
res.add(route);
}
} else {
if (!isCurrentRouteNearby) {
res.add(route);
}
}
}
return res;
@ -538,19 +544,12 @@ public abstract class MenuController extends BaseMenuController implements Colla
return null;
}
public List<TransportStopRoute> getLocalTransportStopRoutes() {
return getSubTransportStopRoutes(false);
}
public List<TransportStopRoute> getNearbyTransportStopRoutes() {
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 (isCurrentRouteNearby) {
res.add(route);
}
}
return res;
}
return null;
return getSubTransportStopRoutes(true);
}
public void share(LatLon latLon, String title, String address) {

View file

@ -28,6 +28,8 @@ import java.util.List;
public class TransportStopController extends MenuController {
public static final int RADIUS =150;
private TransportStop transportStop;
private List<TransportStopRoute> routes = new ArrayList<>();
private TransportStopType topType;
@ -101,7 +103,7 @@ public class TransportStopController extends MenuController {
addRoutes(routes, useEnglishNames, t, transportStop, transportStop, 0);
}
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(), RADIUS);
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) {