diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 731cde125c..f79287d248 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu.controllers; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.data.TransportRoute; import net.osmand.data.TransportStop; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -62,7 +63,7 @@ public class TransportStopController extends MenuController { } private TransportStop transportStop; - private List> routes = new ArrayList<>(); + private List routes = new ArrayList<>(); private TransportStopType topType; public TransportStopController(OsmandApplication app, MapActivity mapActivity, @@ -111,13 +112,11 @@ public class TransportStopController extends MenuController { @Override public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { - for (List l : routes) { - for (TransportStopRoute r : l) { - if (r.type == null) { - addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false); - } else { - addPlainMenuItem(r.type.getResourceId(), r.desc, false, false); - } + for (TransportStopRoute r : routes) { + if (r.type == null) { + addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false); + } else { + addPlainMenuItem(r.type.getResourceId(), r.desc, false, false); } } super.addPlainMenuItems(typeStr, pointDescription, latLon); @@ -133,33 +132,18 @@ public class TransportStopController extends MenuController { for (TransportIndexRepository t : reps) { if (t.acceptTransportStop(transportStop)) { - List l; - if (useEnglishNames) { - l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {3}"); - } else { - l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {2}"); - } - if (l != null) { - List routeList = new ArrayList<>(); - for (String s : l) { - int firstSpaceIndex = s.indexOf(' '); - if (firstSpaceIndex != -1) { - String typeName = s.substring(0, firstSpaceIndex); - TransportStopType type = TransportStopType.findType(typeName); - TransportStopRoute r = new TransportStopRoute(); - r.type = type; - if (type == null) { - r.desc = s; - } else { - r.desc = s.substring(firstSpaceIndex + 1); - } - routeList.add(r); - if (topType == null && type != null && type.isTopType()) { - topType = type; - } + List rts = t.getRouteForStop(transportStop); + if (rts != null) { + for (TransportRoute rs : rts) { + TransportStopType type = TransportStopType.findType(rs.getType()); + TransportStopRoute r = new TransportStopRoute(); + if (topType == null && type != null && type.isTopType()) { + topType = type; } + r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getName() : rs.getEnName(true)); + r.route = rs; + this.routes.add(r); } - routes.add(routeList); } } } @@ -168,5 +152,6 @@ public class TransportStopController extends MenuController { private class TransportStopRoute { public TransportStopType type; public String desc; + public TransportRoute route; } } diff --git a/OsmAnd/src/net/osmand/plus/resources/TransportIndexRepository.java b/OsmAnd/src/net/osmand/plus/resources/TransportIndexRepository.java index e228f24eca..9e6df98679 100644 --- a/OsmAnd/src/net/osmand/plus/resources/TransportIndexRepository.java +++ b/OsmAnd/src/net/osmand/plus/resources/TransportIndexRepository.java @@ -18,7 +18,7 @@ public interface TransportIndexRepository { public void searchTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, List stops, ResultMatcher matcher); - public List getRouteDescriptionsForStop(TransportStop stop, String format); + public List getRouteForStop(TransportStop stop); public List searchTransportRouteStops(double latitude, double longitude, LatLon locationToGo, int zoom); diff --git a/OsmAnd/src/net/osmand/plus/resources/TransportIndexRepositoryBinary.java b/OsmAnd/src/net/osmand/plus/resources/TransportIndexRepositoryBinary.java index fb521a0812..aadb5201e7 100644 --- a/OsmAnd/src/net/osmand/plus/resources/TransportIndexRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/plus/resources/TransportIndexRepositoryBinary.java @@ -55,38 +55,18 @@ public class TransportIndexRepositoryBinary implements TransportIndexRepository } } - - /** - * - * @param stop - * @param format {0} - ref, {1} - type, {2} - name, {3} - name_en - * @return null if something goes wrong - */ @Override - public List getRouteDescriptionsForStop(TransportStop stop, String format) { - assert acceptTransportStop(stop); - long now = System.currentTimeMillis(); - - MessageFormat f = new MessageFormat(format); - List res = new ArrayList(); + public List getRouteForStop(TransportStop stop){ try { - List routes = file.getTransportRouteDescriptions(stop); - if(routes != null){ - for(TransportRoute route : routes){ - res.add(f.format(new String[] { route.getRef() + "", route.getType() + "", route.getName() + "", route.getEnName(true) + "" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } + List res = file.getTransportRouteDescriptions(stop); + if(res != null){ + return res; } } catch (IOException e) { log.error("Disk error ", e); //$NON-NLS-1$ } - - if (log.isDebugEnabled()) { - log.debug(String.format("Search for stop %s done in %s ms found %s.", //$NON-NLS-1$ - stop.getId() + "", System.currentTimeMillis() - now, res.size())); //$NON-NLS-1$ - } - return res; + return Collections.emptyList(); } - @Override