Skip to content

Commit

Permalink
More reroute fixes (#389)
Browse files Browse the repository at this point in the history
* removed collection reverse

* fix lastrerouteseconds

* set the queued reroute events to represent new values

* checkstyle

* fixed total distance completed not getting set
  • Loading branch information
Cameron Mace authored Oct 18, 2017
1 parent 232a638 commit d3e1c98
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ private RouteProgress generateNewRouteProgress(MapboxNavigation mapboxNavigation
MapboxNavigationOptions options = mapboxNavigation.options();

if (newRoute(directionsRoute)) {
// Need to keep track of total distance traveled even when reroute occurs.
if (previousRouteProgress != null) {
mapboxNavigation.getSessionState().toBuilder().previousRouteDistancesCompleted(
mapboxNavigation.getSessionState().previousRouteDistancesCompleted()
+ previousRouteProgress.distanceTraveled()
);
}
// Decode the first steps geometry and hold onto the resulting Position objects till the users
// on the next step. Indices are both 0 since the user just started on the new route.
stepPositions = PolylineUtils.decode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.mapbox.services.android.telemetry.utils.TelemetryUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class NavigationMetricsWrapper {
Expand Down Expand Up @@ -140,8 +139,6 @@ private static Location[] prepareLocations(List<Location> locations) {
if (locations == null || locations.isEmpty()) {
return new Location[0];
}
// Reverse the list order to conform with the spec
Collections.reverse(locations);
return locations.toArray(new Location[locations.size()]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void onLocationChanged(Location location) {
SessionState sessionState = iterator.next();
if (sessionState.lastRerouteLocation() != null
&& sessionState.lastRerouteLocation().equals(locationBuffer.peekFirst())
|| TimeUtils.dateDiff(sessionState.lastRerouteDate(), new Date(), TimeUnit.SECONDS)
|| TimeUtils.dateDiff(sessionState.rerouteDate(), new Date(), TimeUnit.SECONDS)
> TWENTY_SECOND_INTERVAL) {
sendRerouteEvent(sessionState);
iterator.remove();
Expand Down Expand Up @@ -298,7 +298,10 @@ public void rerouteOccurred() {
.routeProgressBeforeReroute(routeProgress)
.beforeRerouteLocations(Arrays.asList(
locationBuffer.toArray(new Location[locationBuffer.size()])))
.lastRerouteDate(new Date())
.previousRouteDistancesCompleted(
mapboxNavigation.getSessionState().previousRouteDistancesCompleted()
+ routeProgress.distanceTraveled())
.rerouteDate(new Date())
.build());
queuedRerouteEvents.add(mapboxNavigation.getSessionState());
}
Expand All @@ -311,6 +314,17 @@ void sendRerouteEvent(SessionState sessionState) {

NavigationMetricsWrapper.rerouteEvent(sessionState, routeProgress,
sessionState.lastRerouteLocation());

for (SessionState session : queuedRerouteEvents) {
queuedRerouteEvents.set(queuedRerouteEvents.indexOf(session),
session.toBuilder().lastRerouteDate(
sessionState.rerouteDate()
).build());
}

mapboxNavigation.setSessionState(mapboxNavigation.getSessionState().toBuilder().lastRerouteDate(
sessionState.rerouteDate()
).build());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ int currentStepCount() {

abstract DirectionsRoute currentDirectionRoute();

@Nullable
abstract Date rerouteDate();

int secondsSinceLastReroute() {
if (lastRerouteDate() == null) {
if (lastRerouteDate() == null || rerouteDate() == null) {
return -1;
}
long diffInMs = new Date().getTime() - lastRerouteDate().getTime();
long diffInMs = rerouteDate().getTime() - lastRerouteDate().getTime();
return (int) TimeUnit.MILLISECONDS.toSeconds(diffInMs);
}

Expand Down Expand Up @@ -128,6 +131,8 @@ abstract static class Builder {

abstract Builder requestIdentifier(@Nullable String requestIdentifier);

abstract Builder rerouteDate(@Nullable Date rerouteDate);

abstract Builder lastRerouteDate(@Nullable Date lastRerouteDate);

abstract Builder mockLocation(boolean mockLocation);
Expand Down

0 comments on commit d3e1c98

Please sign in to comment.