Update route layer

This commit is contained in:
Victor Shcherb 2016-07-29 15:14:11 +02:00
parent d2a982398b
commit 0855c6c36d
3 changed files with 24 additions and 59 deletions

View file

@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu.controllers;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -62,7 +63,7 @@ public class TransportStopController extends MenuController {
} }
private TransportStop transportStop; private TransportStop transportStop;
private List<List<TransportStopRoute>> routes = new ArrayList<>(); private List<TransportStopRoute> routes = new ArrayList<>();
private TransportStopType topType; private TransportStopType topType;
public TransportStopController(OsmandApplication app, MapActivity mapActivity, public TransportStopController(OsmandApplication app, MapActivity mapActivity,
@ -111,13 +112,11 @@ public class TransportStopController extends MenuController {
@Override @Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
for (List<TransportStopRoute> l : routes) { for (TransportStopRoute r : routes) {
for (TransportStopRoute r : l) { if (r.type == null) {
if (r.type == null) { addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false);
addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false); } else {
} else { addPlainMenuItem(r.type.getResourceId(), r.desc, false, false);
addPlainMenuItem(r.type.getResourceId(), r.desc, false, false);
}
} }
} }
super.addPlainMenuItems(typeStr, pointDescription, latLon); super.addPlainMenuItems(typeStr, pointDescription, latLon);
@ -133,33 +132,18 @@ public class TransportStopController extends MenuController {
for (TransportIndexRepository t : reps) { for (TransportIndexRepository t : reps) {
if (t.acceptTransportStop(transportStop)) { if (t.acceptTransportStop(transportStop)) {
List<String> l; List<TransportRoute> rts = t.getRouteForStop(transportStop);
if (useEnglishNames) { if (rts != null) {
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {3}"); for (TransportRoute rs : rts) {
} else { TransportStopType type = TransportStopType.findType(rs.getType());
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {2}"); TransportStopRoute r = new TransportStopRoute();
} if (topType == null && type != null && type.isTopType()) {
if (l != null) { topType = type;
List<TransportStopRoute> 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;
}
} }
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 { private class TransportStopRoute {
public TransportStopType type; public TransportStopType type;
public String desc; public String desc;
public TransportRoute route;
} }
} }

View file

@ -18,7 +18,7 @@ public interface TransportIndexRepository {
public void searchTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, public void searchTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
int limit, List<TransportStop> stops, ResultMatcher<TransportStop> matcher); int limit, List<TransportStop> stops, ResultMatcher<TransportStop> matcher);
public List<String> getRouteDescriptionsForStop(TransportStop stop, String format); public List<TransportRoute> getRouteForStop(TransportStop stop);
public List<RouteInfoLocation> searchTransportRouteStops(double latitude, double longitude, LatLon locationToGo, int zoom); public List<RouteInfoLocation> searchTransportRouteStops(double latitude, double longitude, LatLon locationToGo, int zoom);

View file

@ -55,40 +55,20 @@ 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 @Override
public List<String> getRouteDescriptionsForStop(TransportStop stop, String format) { public List<TransportRoute> getRouteForStop(TransportStop stop){
assert acceptTransportStop(stop);
long now = System.currentTimeMillis();
MessageFormat f = new MessageFormat(format);
List<String> res = new ArrayList<String>();
try { try {
List<TransportRoute> routes = file.getTransportRouteDescriptions(stop); List<TransportRoute> res = file.getTransportRouteDescriptions(stop);
if(routes != null){ if(res != null){
for(TransportRoute route : routes){ return res;
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$
}
} }
} catch (IOException e) { } catch (IOException e) {
log.error("Disk error ", e); //$NON-NLS-1$ log.error("Disk error ", e); //$NON-NLS-1$
} }
return Collections.emptyList();
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;
} }
@Override @Override
public List<RouteInfoLocation> searchTransportRouteStops(double latitude, double longitude, LatLon locationToGo, int zoom) { public List<RouteInfoLocation> searchTransportRouteStops(double latitude, double longitude, LatLon locationToGo, int zoom) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();