Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-08-02 10:58:40 +02:00
commit 91da4e507e
3 changed files with 39 additions and 14 deletions

View file

@ -3,6 +3,8 @@ package net.osmand.plus.mapcontextmenu.controllers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -157,21 +159,39 @@ public class TransportStopController extends MenuController {
for (TransportIndexRepository t : reps) { for (TransportIndexRepository t : reps) {
if (t.acceptTransportStop(transportStop)) { if (t.acceptTransportStop(transportStop)) {
addRoutes(useEnglishNames, t, transportStop, 0); boolean empty = transportStop.getReferencesToRoutes() != null && transportStop.getReferencesToRoutes().length > 0;
if(!empty) {
addRoutes(useEnglishNames, t, transportStop, transportStop, 0);
}
ArrayList<TransportStop> ls = new ArrayList<>(); 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(), 150);
t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null); t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
for(TransportStop tstop : ls) { for(TransportStop tstop : ls) {
if(tstop.getId() != transportStop.getId() || !Arrays.equals(tstop.getReferencesToRoutes(), if(tstop.getId() != transportStop.getId() || empty) {
transportStop.getReferencesToRoutes())) { addRoutes(useEnglishNames, t, tstop, transportStop,
addRoutes(useEnglishNames, t, tstop, (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation())); (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation()));
} }
} }
} }
} }
Collections.sort(routes, new Comparator<TransportStopRoute>() {
@Override
public int compare(TransportStopRoute o1, TransportStopRoute o2) {
if(o1.distance != o2.distance) {
return Algorithms.compare(o1.distance, o2.distance);
}
int i1 = Algorithms.extractFirstIntegerNumber(o1.desc);
int i2 = Algorithms.extractFirstIntegerNumber(o2.desc);
if(i1 != i2) {
return Algorithms.compare(i1, i2);
}
return o1.desc.compareTo(o2.desc);
}
});
} }
private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, int dist) { private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) {
Collection<TransportRoute> rts = t.getRouteForStop(s); Collection<TransportRoute> rts = t.getRouteForStop(s);
if (rts != null) { if (rts != null) {
for (TransportRoute rs : rts) { for (TransportRoute rs : rts) {
@ -183,6 +203,7 @@ public class TransportStopController extends MenuController {
r.type = type; r.type = type;
r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getEnName(true) : rs.getName()); r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getEnName(true) : rs.getName());
r.route = rs; r.route = rs;
r.refStop = refStop;
r.stop = s; r.stop = s;
r.distance = dist; r.distance = dist;
this.routes.add(r); this.routes.add(r);
@ -191,6 +212,7 @@ public class TransportStopController extends MenuController {
} }
public static class TransportStopRoute { public static class TransportStopRoute {
public TransportStop refStop;
public TransportStopType type; public TransportStopType type;
public String desc; public String desc;
public TransportRoute route; public TransportRoute route;
@ -199,8 +221,12 @@ public class TransportStopController extends MenuController {
public boolean showWholeRoute; public boolean showWholeRoute;
public String getDescription(OsmandApplication ctx, boolean useDistance) { public String getDescription(OsmandApplication ctx, boolean useDistance) {
if(useDistance && distance > 0) { if (useDistance && distance > 0) {
return desc +" (" + OsmAndFormatter.getFormattedDistance(distance, ctx) +")"; String nm = OsmAndFormatter.getFormattedDistance(distance, ctx);
if (!refStop.getName().equals(stop.getName())) {
nm = refStop.getName() + ", " + nm;
}
return desc + " (" + nm + ")";
} }
return desc; return desc;
} }

View file

@ -1,20 +1,13 @@
package net.osmand.plus.resources; package net.osmand.plus.resources;
import gnu.trove.map.hash.TIntObjectHashMap;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.data.LatLon;
import net.osmand.data.TransportRoute; import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;

View file

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.TreeSet;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -112,11 +113,16 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
final int rp = getRadiusPoi(tb); final int rp = getRadiusPoi(tb);
int radius = rp * 3 / 2; int radius = rp * 3 / 2;
try { try {
TreeSet<String> ms = new TreeSet<>();
for (int i = 0; i < objects.size(); i++) { for (int i = 0; i < objects.size(); i++) {
TransportStop n = objects.get(i); TransportStop n = objects.get(i);
if (n.getLocation() == null){ if (n.getLocation() == null){
continue; continue;
} }
if(!ms.add(n.getName())) {
// only unique names
continue;
}
int x = (int) tb.getPixXFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude()); int x = (int) tb.getPixXFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
int y = (int) tb.getPixYFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude()); int y = (int) tb.getPixYFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) { if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) {