-
Notifications
You must be signed in to change notification settings - Fork 319
Add arrival controller for multiple stops #2787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
examples/src/main/java/com/mapbox/navigation/examples/core/MultipleStopsActivity.kt
Outdated
Show resolved
Hide resolved
81bcadb to
891f8f9
Compare
891f8f9 to
c4cb481
Compare
a543882 to
24eb730
Compare
libnavigation-core/src/main/java/com/mapbox/navigation/core/stops/ArrivalProgressObserver.kt
Outdated
Show resolved
Hide resolved
examples/src/main/java/com/mapbox/navigation/examples/core/MultipleStopsActivity.kt
Outdated
Show resolved
Hide resolved
d048ed6 to
644f890
Compare
| } | ||
|
|
||
| override fun updateRouteLegIndex(routeIndex: Int, legIndex: Int) { | ||
| navigator.updateLegIndex(routeIndex, legIndex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this function is working 🤔 . should we expect it to be working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc: @Guardiola31337
bd48013 to
2a0812d
Compare
Codecov Report
@@ Coverage Diff @@
## master #2787 +/- ##
============================================
+ Coverage 35.00% 35.11% +0.11%
- Complexity 2107 2126 +19
============================================
Files 541 543 +2
Lines 19422 19488 +66
Branches 1841 1851 +10
============================================
+ Hits 6799 6844 +45
- Misses 11807 11818 +11
- Partials 816 826 +10 |
libnavigation-core/src/main/java/com/mapbox/navigation/core/stops/ArrivalProgressObserver.kt
Show resolved
Hide resolved
Guardiola31337
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments / questions to discuss before merging here.
Also, now that Core will provide the ArrivalController API we should revisit / refactor
Lines 28 to 50 in 5c1175f
| /** | |
| * Looks at the current [RouteProgressState] and returns if | |
| * is [RouteProgressState.ROUTE_ARRIVED]. | |
| * | |
| * @param routeProgress the current route progress | |
| * @return true if in arrival state, false if not | |
| */ | |
| fun isArrivalEvent(routeProgress: RouteProgress): Boolean = | |
| routeProgress.currentState()?.let { currentState -> | |
| currentState == RouteProgressState.ROUTE_ARRIVED | |
| } ?: false | |
| /** | |
| * Uses the [RouteProgress] and compares it with [com.mapbox.navigation.ui.NavigationViewOptions] | |
| * to find if the device is close enough to final destination | |
| * | |
| * @param routeProgress the current route progress | |
| * @param maxMeters value to compare the arrival remaining distance with | |
| * @return true if device is close enough, false if not | |
| */ | |
| fun deviceCloseEnoughToFinalDestination(routeProgress: RouteProgress, maxMeters: Float?): Boolean = | |
| (routeProgress.distanceRemaining() <= maxMeters | |
| ?: DEFAULT_MAX_METERS_AWAY_TO_TRIGGER_FINAL_DESTINATION_ARRIVAL) |
| routeRefreshController.start() | ||
|
|
||
| arrivalProgressObserver = ArrivalProgressObserver(tripSession) | ||
| tripSession.registerRouteProgressObserver(arrivalProgressObserver) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should unregister arrivalProgressObserver when in MapboxNavigation#onDestroy to prevent leaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 302 in 5c1175f
| tripSession.unregisterAllRouteProgressObservers() |
I didn't unregister this one because all of them are unregistered onDestroy. Which is interesting, how does the foreground activity continue to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, that's right 👍 Sorry for the confusion!
libnavigation-core/src/main/java/com/mapbox/navigation/core/stops/ArrivalController.kt
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| fun navigateToNextStop(): Boolean { | ||
| val routeIndex = tripSession.getRouteProgress()?.route()?.routeIndex()?.toInt() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watch out this is not the index expected by NN 👀 https://github.com/mapbox/mapbox-java/blob/6c76713f7c2ae19f120fa8a098fa2899be7beeac/services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/DirectionsResponse.java#L211 This is the index of the different routes returned in the DirectionsResponse (alternatives).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does that mean it should just be 0? i'm not actually sure what's right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
libnavigation-core/src/main/java/com/mapbox/navigation/core/stops/ArrivalProgressObserver.kt
Outdated
Show resolved
Hide resolved
| * @param legIndex the index of the leg to navigate to | ||
| */ | ||
| override fun updateRouteLegIndex(routeIndex: Int, legIndex: Int) { | ||
| navigator.updateLegIndex(routeIndex, legIndex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above re: routeIndex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above re: misusing MapboxNavigation#navigateToNextStop
Maybe we can rely on the response returned by the Navigator NavigationStatus
/**
* Follows a new route and leg of the already loaded directions.
* Returns an initialized route state if no errors occurred
* otherwise, it returns an invalid route state.
*
* @param routeIndex new route index
* @param legIndex new leg index
*
* @return an initialized route state as [NavigationStatus]
*/
override fun updateLegIndex(routeIndex: Int, legIndex: Int): NavigationStatus =
navigator.changeRouteLeg(routeIndex, legIndex) There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, actually that may help me figure out why it's not working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated. also found that the navigator status is being updated correctly
examples/src/main/java/com/mapbox/navigation/examples/core/MultipleStopsActivity.kt
Show resolved
Hide resolved
| * Stop controlling arrival at stops, detaching will require the caller | ||
| * to call [navigateToNextStop] manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a quick example in the test app showcasing this use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm maybe need to add a manual mode to the MultipleStopsActivity?
libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt
Outdated
Show resolved
Hide resolved
| * | ||
| * @return true if navigation to next stop could be started, false otherwise | ||
| */ | ||
| fun navigateToNextStop(): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this is called before arriving at a stop and multiple times? Are we checking somehow that this API is not misused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah the check for misuse is in the return value. i wasn't going to introduce crashes until this works as expected.
right now, it doesn't seem to be navigating to next stop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be because downstream in NN they have a check 👀 for ROUTE_ARRIVED event so you can only navigateToNextStop safely? If so, we don't need to add any extra check on our side 🚀 Is that the case @mskurydin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like if you call this too early you'll get an "off-route" event..
to the, what if you call it multiple times, your next calls could be dropped. the Boolean return is the best check for misuse right now
libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt
Show resolved
Hide resolved
c052753 to
c678435
Compare
libnavigation-core/src/main/java/com/mapbox/navigation/core/stops/ArrivalProgressObserver.kt
Outdated
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/trip/session/MapboxTripSession.kt
Outdated
Show resolved
Hide resolved
e2163ac to
ab14717
Compare
libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt
Outdated
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt
Outdated
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt
Outdated
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/stops/ArrivalProgressObserver.kt
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/stops/ArrivalProgressObserver.kt
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt
Outdated
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt
Outdated
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt
Outdated
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/stops/ArrivalController.kt
Outdated
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/stops/ArrivalController.kt
Outdated
Show resolved
Hide resolved
| * Once the [RouteProgress.currentState] has reached [RouteProgressState.ROUTE_ARRIVED] | ||
| * this is called continuously | ||
| */ | ||
| fun onRouteArrival(routeProgress: RouteProgress) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default interface methods could be problematic for Java users. We could use @JvmDefault but it is only supported since JVM target 1.8 😞 What about removing the default and leaving the AutoArrivalController implementation empty and "force" developers to implement on their side? Another option is having a separate interface for route arrival following the Interface segregation principle. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default implementation follows the Interface segregation principle in the sense that, if you implement the interface you're only forced to implement what you need to. removing the default makes the example have an empty interface.
I see a new interface for an option to remove the default, but we would also be adding another class for tests, another progress observer, and another set of methods to attach/detach. my opinion is it's not worth it.
libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigator.kt
Outdated
Show resolved
Hide resolved
...avigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigatorImpl.kt
Outdated
Show resolved
Hide resolved
...avigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigatorImpl.kt
Outdated
Show resolved
Hide resolved
libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigator.kt
Outdated
Show resolved
Hide resolved
libnavigation-core/src/main/java/com/mapbox/navigation/core/trip/session/MapboxTripSession.kt
Outdated
Show resolved
Hide resolved
16d90b9 to
9fb8966
Compare
Guardiola31337
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the feedback @kmadsen 🚀
libnavigation-core/src/main/java/com/mapbox/navigation/core/trip/session/MapboxTripSession.kt
Outdated
Show resolved
Hide resolved
libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigator.kt
Outdated
Show resolved
Hide resolved
...avigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigatorImpl.kt
Outdated
Show resolved
Hide resolved
9b8fe67 to
ae7738d
Compare
ae7738d to
97a9c8d
Compare
Description
Resolves: https://github.com/mapbox/navigation-sdks/issues/315
The arrival distances can be wildly incorrect so this may need to be fixed to make this interface work properly #2748
bug,feature,new API(s),SEMVER, etc.)Goal
Implementation
Creating an interface with the options to control arrival, as well as moving to the next step.
Testing
Please describe the manual tests that you ran to verify your changes
SNAPSHOTupstream dependencies if needed) through testapp/demo app and run all activities to avoid regressionsChecklist
CHANGELOGincluding this PR