Skip to content

Conversation

@abhishek1508
Copy link
Contributor

Description

Implement callback to allow user to accept or dismiss faster route (https://github.com/mapbox/navigation-sdks/issues/220)

  • I have added any issue links
  • I have added all related labels (bug, feature, new API(s), SEMVER, etc.)
  • I have added the appropriate milestone and project boards

Goal

Implement callback to allow user to accept or dismiss faster route

Implementation

Implement callback to allow user to accept or dismiss faster route

Screenshots or Gifs

fasterRoute

Testing

Please describe the manual tests that you ran to verify your changes

  • I have tested locally (including SNAPSHOT upstream dependencies if needed) through testapp/demo app and run all activities to avoid regressions
  • I have tested via a test drive, or a simulation/mock location app
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have updated the CHANGELOG including this PR

@Guardiola31337
Copy link
Contributor

Could you @designevokes @map-angela @noracalabrese take a look at this when you have a chance? It'd be 💯 if we can start getting input from you on the design side of things.

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor comments / questions to discuss as a team @abhishek1508

}
}

private val fasterRouteObserver = object : FasterRouteObserver {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this as part of this PR? Currently faster route is disable by default downstream

private fun isRouteFaster(newRoute: DirectionsRoute): Boolean {
// TODO: Implement the logic to check if the route is faster
return false
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I would like to stick it as a part of this PR because that's the objective of this ticket. To be able to provide a callback for user to act on faster route. The part where we fix the above isRouteFaster is going to come up here

private val router: Router
) : DirectionsSession {

private val fasterRouteInterval = 2 * 60 * 1000L // 2 minutes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be customizable from a client point of view as well as enabling / disabling faster functionality completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming up as a part of this

@abhishek1508 abhishek1508 force-pushed the feature/ak-#220_faster_route_callback branch from fbbeee4 to b7fc749 Compare February 11, 2020 01:04
Copy link

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag the team for a review next time around @abhishek1508, I completely missed the PR! :)

The idea LGTM, we're only missing the docs. The UI lives only in an example so I'm happy to merge and we can keep the design discussion going for the refactor of the UI lib.


interface FasterRouteObserver {

fun onFasterRouteAvailable(fasterRoute: DirectionsRoute)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we provide a list of routes from the response here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private fun requestFasterRoute(routeOptions: RouteOptions) {
       if (routes.isEmpty()) {
           return
       }
       router.getRoute(routeOptions, object : Router.Callback {
           override fun onResponse(routes: List<DirectionsRoute>) {
               val route = routes[0]
               if (isRouteFaster(route)) {
                   fasterRouteObservers.forEach { it.onFasterRouteAvailable(route) }
               }
           }

           override fun onFailure(throwable: Throwable) {
               // do nothing
           }

           override fun onCanceled() {
               // do nothing
           }
       })
   }

If you look at the onResponse we use the route at index 0 to check if the route is faster than the current route. If true only then we broadcast a faster route. The question, I would like to ask here is do we want to emit a list of routes because then how does the end client know which route is faster in that list? There are 2 solutions to this:

  • We emit the list of route and say that route at index 0 in this list has been verified to be faster; so use it - so then in that case why to even send a list since the 0th route is always going to be faster.
  • Send a list to the user and ask him to find out which route is faster

I don't see either of the solution that we would probably want to extend from SDK perspective.

Faster route in itself is a very specific feature that says we found 1 faster route rather than multiple faster routes. In that case I think we should only emit one route.
Comments/Thoughts?

@LukasPaczos LukasPaczos requested a review from a team February 12, 2020 17:40
Copy link

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be great to add unit tests as well.

@codecov-io
Copy link

codecov-io commented Feb 12, 2020

Codecov Report

Merging #2455 into master will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##             master    #2455   +/-   ##
=========================================
  Coverage     32.29%   32.29%           
  Complexity      621      621           
=========================================
  Files           143      143           
  Lines          5605     5605           
  Branches        434      434           
=========================================
  Hits           1810     1810           
  Misses         3595     3595           
  Partials        200      200


fun unregisterRoutesObserver(routesObserver: RoutesObserver)

fun registerFasterRouteObserver(fasterRouteObserver: FasterRouteObserver)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in #2462, if MapboxNavigation is going to be responsible for making the decision if the route is faster, it could also notify the users back and maintain the observers' list. We don't need to return the control back to the DirectionsSession.

Otherwise, I'd prefer MapboxDirectionsSession to have a constructor injected FasterRouteDetector from #2462 instead of the FasterRouteRequestCallback mechanism. We ultimately don't need to worry about whether or not the requested succeeded as the session's client.

Copy link

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge and iterate in #2462 👍

@abhishek1508 abhishek1508 force-pushed the feature/ak-#220_faster_route_callback branch from 8608149 to 085f420 Compare February 13, 2020 17:46
@abhishek1508 abhishek1508 merged commit e58f657 into master Feb 13, 2020
@abhishek1508 abhishek1508 deleted the feature/ak-#220_faster_route_callback branch February 13, 2020 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants