-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- renamed method - added feedback location collect to onLocation listener - created new methods to handle updating feedback and reroute queues
- Loading branch information
1 parent
bd2f284
commit 8ce5a00
Showing
2 changed files
with
42 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ public class NavigationService extends Service implements LocationEngineListener | |
private final IBinder localBinder = new LocalBinder(); | ||
private NavigationNotification navNotificationManager; | ||
private List<SessionState> queuedRerouteEvents; | ||
private List<FeedbackEvent> queuedFeedbackEvents; | ||
private RingBuffer<Location> locationBuffer; | ||
private long timeIntervalSinceLastOffRoute; | ||
private MapboxNavigation mapboxNavigation; | ||
|
@@ -67,8 +68,6 @@ public class NavigationService extends Service implements LocationEngineListener | |
private NavigationEngine thread; | ||
private Location rawLocation; | ||
|
||
private List<FeedbackEvent> queuedFeedbackEvents; | ||
|
||
@Nullable | ||
@Override | ||
public IBinder onBind(Intent intent) { | ||
|
@@ -199,20 +198,13 @@ public void onLocationChanged(Location location) { | |
locationBuffer.addLast(location); | ||
thread.queueTask(MSG_LOCATION_UPDATED, NewLocationModel.create(location, mapboxNavigation, | ||
recentDistancesFromManeuverInMeters)); | ||
Iterator<SessionState> iterator = queuedRerouteEvents.listIterator(); | ||
while (iterator.hasNext()) { | ||
SessionState sessionState = iterator.next(); | ||
if (sessionState.lastRerouteLocation() != null | ||
&& sessionState.lastRerouteLocation().equals(locationBuffer.peekFirst()) | ||
|| TimeUtils.dateDiff(sessionState.rerouteDate(), new Date(), TimeUnit.SECONDS) | ||
> TWENTY_SECOND_INTERVAL) { | ||
sendRerouteEvent(sessionState); | ||
iterator.remove(); | ||
} | ||
} | ||
|
||
updateRerouteQueue(location); | ||
updateFeedbackQueue(location); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Runs several checks on the actual rawLocation object itself in order to ensure that we are | ||
* performing navigation progress on a accurate/valid rawLocation update. | ||
|
@@ -274,12 +266,12 @@ public void onUserOffRoute(Location location, boolean userOffRoute) { | |
if (location.getTime() > timeIntervalSinceLastOffRoute | ||
+ TimeUnit.SECONDS.toMillis(mapboxNavigation.options().secondsBeforeReroute())) { | ||
timeIntervalSinceLastOffRoute = location.getTime(); | ||
if (mapboxNavigation.getSessionState().lastRerouteLocation() == null) { | ||
if (mapboxNavigation.getSessionState().eventLocation() == null) { | ||
rerouteSessionsStateUpdate(); | ||
} else { | ||
Point lastReroutePoint = Point.fromLngLat( | ||
mapboxNavigation.getSessionState().lastRerouteLocation().getLongitude(), | ||
mapboxNavigation.getSessionState().lastRerouteLocation().getLatitude()); | ||
mapboxNavigation.getSessionState().eventLocation().getLongitude(), | ||
mapboxNavigation.getSessionState().eventLocation().getLatitude()); | ||
if (TurfMeasurement.distance(lastReroutePoint, | ||
Point.fromLngLat(location.getLongitude(), location.getLatitude()), | ||
TurfConstants.UNIT_METERS) | ||
|
@@ -324,23 +316,8 @@ public String recordFeedbackEvent(String feedbackType, String description, | |
.build(); | ||
|
||
FeedbackEvent feedbackEvent = new FeedbackEvent(feedbackEventSessionState, feedbackSource); | ||
// TODO set feedback type and description from the parameters based | ||
// TODO - note: these should use default values if the values passed are empty | ||
|
||
// TODO Send 20 seconds later with "after" location updates | ||
// runnable = new Runnable() { | ||
// @Override | ||
// public void run() { | ||
// mapboxNavigation.setSessionState(mapboxNavigation.getSessionState().toBuilder() | ||
// .afterRerouteLocations(Arrays.asList( | ||
// locationBuffer.toArray(new Location[locationBuffer.size()]))) | ||
// .build()); | ||
// | ||
// | ||
// sendFeedbackEvent(mapboxNavigation.getSessionState()); | ||
// } | ||
// }; | ||
// handler.postDelayed(runnable, TWENTY_SECOND_INTERVAL); | ||
feedbackEvent.setDescription(description); | ||
feedbackEvent.setFeedbackType(feedbackType); | ||
|
||
return feedbackEvent.getFeedbackId(); | ||
} | ||
|
@@ -376,13 +353,13 @@ void sendRerouteEvent(SessionState sessionState) { | |
.build(); | ||
|
||
NavigationMetricsWrapper.rerouteEvent(sessionState, routeProgress, | ||
sessionState.lastRerouteLocation()); | ||
sessionState.eventLocation()); | ||
|
||
for (SessionState session : queuedRerouteEvents) { | ||
queuedRerouteEvents.set(queuedRerouteEvents.indexOf(session), | ||
session.toBuilder().lastRerouteDate( | ||
sessionState.rerouteDate() | ||
).build()); | ||
sessionState.rerouteDate() | ||
).build()); | ||
} | ||
|
||
mapboxNavigation.setSessionState(mapboxNavigation.getSessionState().toBuilder().lastRerouteDate( | ||
|
@@ -405,4 +382,32 @@ private FeedbackEvent findQueuedFeedbackEvent(String feedbackId) { | |
} | ||
return null; | ||
} | ||
|
||
private void updateFeedbackQueue(Location location) { | ||
Iterator<FeedbackEvent> iterator = queuedFeedbackEvents.listIterator(); | ||
while (iterator.hasNext()) { | ||
FeedbackEvent feedbackEvent = iterator.next(); | ||
if (feedbackEvent.getSessionState().eventLocation() != null | ||
&& feedbackEvent.getSessionState().eventLocation().equals(locationBuffer.peekFirst()) | ||
|| TimeUtils.dateDiff(feedbackEvent.getSessionState().rerouteDate(), new Date(), TimeUnit.SECONDS) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
electrostat
Author
Contributor
|
||
> TWENTY_SECOND_INTERVAL) { | ||
sendFeedbackEvent(feedbackEvent); | ||
iterator.remove(); | ||
} | ||
} | ||
} | ||
|
||
private void updateRerouteQueue(Location location) { | ||
Iterator<SessionState> iterator = queuedRerouteEvents.listIterator(); | ||
while (iterator.hasNext()) { | ||
SessionState sessionState = iterator.next(); | ||
if (sessionState.eventLocation() != null | ||
&& sessionState.eventLocation().equals(locationBuffer.peekFirst()) | ||
|| TimeUtils.dateDiff(sessionState.rerouteDate(), new Date(), TimeUnit.SECONDS) | ||
> TWENTY_SECOND_INTERVAL) { | ||
sendRerouteEvent(sessionState); | ||
iterator.remove(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Would both of these methods just send feedback / reroute events every 20 seconds regardless of if there is an actual event or not? Or would that fail because event location would be null cc @ericrwolfe