Update route layer
This commit is contained in:
parent
d2a982398b
commit
0855c6c36d
3 changed files with 24 additions and 59 deletions
|
@ -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<List<TransportStopRoute>> routes = new ArrayList<>();
|
||||
private List<TransportStopRoute> routes = new ArrayList<>();
|
||||
private TransportStopType topType;
|
||||
|
||||
public TransportStopController(OsmandApplication app, MapActivity mapActivity,
|
||||
|
@ -111,15 +112,13 @@ public class TransportStopController extends MenuController {
|
|||
|
||||
@Override
|
||||
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
|
||||
for (List<TransportStopRoute> l : routes) {
|
||||
for (TransportStopRoute r : l) {
|
||||
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,34 +132,19 @@ public class TransportStopController extends MenuController {
|
|||
|
||||
for (TransportIndexRepository t : reps) {
|
||||
if (t.acceptTransportStop(transportStop)) {
|
||||
List<String> l;
|
||||
if (useEnglishNames) {
|
||||
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {3}");
|
||||
} else {
|
||||
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {2}");
|
||||
}
|
||||
if (l != null) {
|
||||
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);
|
||||
List<TransportRoute> rts = t.getRouteForStop(transportStop);
|
||||
if (rts != null) {
|
||||
for (TransportRoute rs : rts) {
|
||||
TransportStopType type = TransportStopType.findType(rs.getType());
|
||||
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 {
|
||||
public TransportStopType type;
|
||||
public String desc;
|
||||
public TransportRoute route;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public interface TransportIndexRepository {
|
|||
public void searchTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
|
||||
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);
|
||||
|
||||
|
|
|
@ -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<String> getRouteDescriptionsForStop(TransportStop stop, String format) {
|
||||
assert acceptTransportStop(stop);
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
MessageFormat f = new MessageFormat(format);
|
||||
List<String> res = new ArrayList<String>();
|
||||
public List<TransportRoute> getRouteForStop(TransportStop stop){
|
||||
try {
|
||||
List<TransportRoute> 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<TransportRoute> 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 Collections.emptyList();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue