Fix transport route calculation ui
This commit is contained in:
parent
df057f4fd9
commit
f399119723
2 changed files with 33 additions and 25 deletions
|
@ -155,19 +155,11 @@ public class RoutingHelper {
|
||||||
this.isRoutePlanningMode = isRoutePlanningMode;
|
this.isRoutePlanningMode = isRoutePlanningMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List<LatLon> intermediatePoints, Location currentLocation) {
|
public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List<LatLon> intermediatePoints, Location currentLocation){
|
||||||
if (isPublicTransportMode()) {
|
RouteCalculationResult previousRoute = route;
|
||||||
clearCurrentRoute(null, null);
|
clearCurrentRoute(finalLocation, intermediatePoints);
|
||||||
if (currentLocation != null) {
|
// to update route
|
||||||
transportRoutingHelper.setFinalAndCurrentLocation(finalLocation,
|
setCurrentLocation(currentLocation, false, previousRoute, true);
|
||||||
new LatLon(currentLocation.getLatitude(), currentLocation.getLongitude()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
RouteCalculationResult previousRoute = route;
|
|
||||||
clearCurrentRoute(finalLocation, intermediatePoints);
|
|
||||||
// to update route
|
|
||||||
setCurrentLocation(currentLocation, false, previousRoute, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void clearCurrentRoute(LatLon newFinalLocation, List<LatLon> newIntermediatePoints) {
|
public synchronized void clearCurrentRoute(LatLon newFinalLocation, List<LatLon> newIntermediatePoints) {
|
||||||
|
@ -202,6 +194,7 @@ public class RoutingHelper {
|
||||||
this.lastProjection = null;
|
this.lastProjection = null;
|
||||||
setFollowingMode(false);
|
setFollowingMode(false);
|
||||||
}
|
}
|
||||||
|
transportRoutingHelper.clearCurrentRoute(newFinalLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void finishCurrentRoute() {
|
private synchronized void finishCurrentRoute() {
|
||||||
|
@ -267,6 +260,7 @@ public class RoutingHelper {
|
||||||
|
|
||||||
public void addListener(IRouteInformationListener l){
|
public void addListener(IRouteInformationListener l){
|
||||||
listeners.add(new WeakReference<>(l));
|
listeners.add(new WeakReference<>(l));
|
||||||
|
transportRoutingHelper.addListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeListener(IRouteInformationListener lt){
|
public boolean removeListener(IRouteInformationListener lt){
|
||||||
|
@ -279,6 +273,7 @@ public class RoutingHelper {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
transportRoutingHelper.removeListener(lt);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,7 +301,11 @@ public class RoutingHelper {
|
||||||
private Location setCurrentLocation(Location currentLocation, boolean returnUpdatedLocation,
|
private Location setCurrentLocation(Location currentLocation, boolean returnUpdatedLocation,
|
||||||
RouteCalculationResult previousRoute, boolean targetPointsChanged) {
|
RouteCalculationResult previousRoute, boolean targetPointsChanged) {
|
||||||
Location locationProjection = currentLocation;
|
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;
|
isDeviatedFromRoute = false;
|
||||||
return locationProjection;
|
return locationProjection;
|
||||||
}
|
}
|
||||||
|
@ -568,7 +567,7 @@ public class RoutingHelper {
|
||||||
|
|
||||||
|
|
||||||
private boolean identifyUTurnIsNeeded(Location currentLocation, float posTolerance) {
|
private boolean identifyUTurnIsNeeded(Location currentLocation, float posTolerance) {
|
||||||
if (finalLocation == null || currentLocation == null || !route.isCalculated()) {
|
if (finalLocation == null || currentLocation == null || !route.isCalculated() || isPublicTransportMode()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean isOffRoute = false;
|
boolean isOffRoute = false;
|
||||||
|
@ -940,7 +939,6 @@ public class RoutingHelper {
|
||||||
if (isPublicTransportMode()) {
|
if (isPublicTransportMode()) {
|
||||||
Location start = lastFixedLocation;
|
Location start = lastFixedLocation;
|
||||||
LatLon finish = finalLocation;
|
LatLon finish = finalLocation;
|
||||||
clearCurrentRoute(null, null);
|
|
||||||
if (start != null && finish != null) {
|
if (start != null && finish != null) {
|
||||||
transportRoutingHelper.setFinalAndCurrentLocation(finish,
|
transportRoutingHelper.setFinalAndCurrentLocation(finish,
|
||||||
new LatLon(start.getLatitude(), start.getLongitude()));
|
new LatLon(start.getLatitude(), start.getLongitude()));
|
||||||
|
@ -948,15 +946,8 @@ public class RoutingHelper {
|
||||||
transportRoutingHelper.recalculateRouteDueToSettingsChange();
|
transportRoutingHelper.recalculateRouteDueToSettingsChange();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (finalLocation == null && intermediatePoints == null) {
|
clearCurrentRoute(finalLocation, intermediatePoints);
|
||||||
LatLon finish = settings.getPointToNavigate();
|
recalculateRouteInBackground(lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, true, false);
|
||||||
List<LatLon> intermediates = app.getTargetPointsHelper().getIntermediatePointsLatLonNavigation();
|
|
||||||
clearCurrentRoute(finish, intermediates);
|
|
||||||
setCurrentLocation(lastFixedLocation, false);
|
|
||||||
} else {
|
|
||||||
clearCurrentRoute(finalLocation, intermediatePoints);
|
|
||||||
recalculateRouteInBackground(lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, true, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,23 @@ public class TransportRoutingHelper {
|
||||||
this.currentRoute = currentRoute;
|
this.currentRoute = currentRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addListener(IRouteInformationListener l){
|
||||||
|
listeners.add(new WeakReference<>(l));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeListener(IRouteInformationListener lt){
|
||||||
|
Iterator<WeakReference<IRouteInformationListener>> it = listeners.iterator();
|
||||||
|
while(it.hasNext()) {
|
||||||
|
WeakReference<IRouteInformationListener> ref = it.next();
|
||||||
|
IRouteInformationListener l = ref.get();
|
||||||
|
if(l == null || lt == l) {
|
||||||
|
it.remove();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void recalculateRouteDueToSettingsChange() {
|
public void recalculateRouteDueToSettingsChange() {
|
||||||
clearCurrentRoute(endLocation);
|
clearCurrentRoute(endLocation);
|
||||||
recalculateRouteInBackground(startLocation, endLocation);
|
recalculateRouteInBackground(startLocation, endLocation);
|
||||||
|
|
Loading…
Reference in a new issue