diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index c9f6d15b95..b8e0261d37 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -155,19 +155,11 @@ public class RoutingHelper { this.isRoutePlanningMode = isRoutePlanningMode; } - public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List intermediatePoints, Location currentLocation) { - if (isPublicTransportMode()) { - clearCurrentRoute(null, null); - if (currentLocation != null) { - transportRoutingHelper.setFinalAndCurrentLocation(finalLocation, - new LatLon(currentLocation.getLatitude(), currentLocation.getLongitude())); - } - } else { - RouteCalculationResult previousRoute = route; - clearCurrentRoute(finalLocation, intermediatePoints); - // to update route - setCurrentLocation(currentLocation, false, previousRoute, true); - } + public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List intermediatePoints, Location currentLocation){ + RouteCalculationResult previousRoute = route; + clearCurrentRoute(finalLocation, intermediatePoints); + // to update route + setCurrentLocation(currentLocation, false, previousRoute, true); } public synchronized void clearCurrentRoute(LatLon newFinalLocation, List newIntermediatePoints) { @@ -202,6 +194,7 @@ public class RoutingHelper { this.lastProjection = null; setFollowingMode(false); } + transportRoutingHelper.clearCurrentRoute(newFinalLocation); } private synchronized void finishCurrentRoute() { @@ -267,6 +260,7 @@ public class RoutingHelper { public void addListener(IRouteInformationListener l){ listeners.add(new WeakReference<>(l)); + transportRoutingHelper.addListener(l); } public boolean removeListener(IRouteInformationListener lt){ @@ -279,6 +273,7 @@ public class RoutingHelper { return true; } } + transportRoutingHelper.removeListener(lt); return false; } @@ -306,7 +301,11 @@ public class RoutingHelper { private Location setCurrentLocation(Location currentLocation, boolean returnUpdatedLocation, RouteCalculationResult previousRoute, boolean targetPointsChanged) { Location locationProjection = currentLocation; - if (finalLocation == null || currentLocation == null) { + if (isPublicTransportMode() && currentLocation != null) { + transportRoutingHelper.setFinalAndCurrentLocation(finalLocation, + new LatLon(currentLocation.getLatitude(), currentLocation.getLongitude())); + } + if (finalLocation == null || currentLocation == null || isPublicTransportMode()) { isDeviatedFromRoute = false; return locationProjection; } @@ -568,7 +567,7 @@ public class RoutingHelper { private boolean identifyUTurnIsNeeded(Location currentLocation, float posTolerance) { - if (finalLocation == null || currentLocation == null || !route.isCalculated()) { + if (finalLocation == null || currentLocation == null || !route.isCalculated() || isPublicTransportMode()) { return false; } boolean isOffRoute = false; @@ -940,7 +939,6 @@ public class RoutingHelper { if (isPublicTransportMode()) { Location start = lastFixedLocation; LatLon finish = finalLocation; - clearCurrentRoute(null, null); if (start != null && finish != null) { transportRoutingHelper.setFinalAndCurrentLocation(finish, new LatLon(start.getLatitude(), start.getLongitude())); @@ -948,15 +946,8 @@ public class RoutingHelper { transportRoutingHelper.recalculateRouteDueToSettingsChange(); } } else { - if (finalLocation == null && intermediatePoints == null) { - LatLon finish = settings.getPointToNavigate(); - List intermediates = app.getTargetPointsHelper().getIntermediatePointsLatLonNavigation(); - clearCurrentRoute(finish, intermediates); - setCurrentLocation(lastFixedLocation, false); - } else { - clearCurrentRoute(finalLocation, intermediatePoints); - recalculateRouteInBackground(lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, true, false); - } + clearCurrentRoute(finalLocation, intermediatePoints); + recalculateRouteInBackground(lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, true, false); } } diff --git a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java index df686bd9a4..47c73a0ca3 100644 --- a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java @@ -79,6 +79,23 @@ public class TransportRoutingHelper { this.currentRoute = currentRoute; } + public void addListener(IRouteInformationListener l){ + listeners.add(new WeakReference<>(l)); + } + + public boolean removeListener(IRouteInformationListener lt){ + Iterator> it = listeners.iterator(); + while(it.hasNext()) { + WeakReference ref = it.next(); + IRouteInformationListener l = ref.get(); + if(l == null || lt == l) { + it.remove(); + return true; + } + } + return false; + } + public void recalculateRouteDueToSettingsChange() { clearCurrentRoute(endLocation); recalculateRouteInBackground(startLocation, endLocation);