-
Notifications
You must be signed in to change notification settings - Fork 319
Add some flexibility to NavigationLocationProvider #6420
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
base: main
Are you sure you want to change the base?
Conversation
ec1428e to
010756e
Compare
| * @see LocationObserver | ||
| * @see MapboxNavigation.registerLocationObserver | ||
| */ | ||
| @CallSuper |
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.
Thinking about making this final.. Leaving it open provides more flexibility but it's not covering a real use case.
Once it is open it cannot be closed, so am debating making it final. Maybe someone would want to intercept these events 🤔
Codecov Report
@@ Coverage Diff @@
## main #6420 +/- ##
============================================
- Coverage 69.28% 69.27% -0.01%
- Complexity 4664 4667 +3
============================================
Files 698 699 +1
Lines 27499 27512 +13
Branches 3213 3214 +1
============================================
+ Hits 19052 19060 +8
- Misses 7201 7206 +5
Partials 1246 1246
|
010756e to
e1b0408
Compare
LukasPaczos
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 investigating this problem and idea! It looks like the proposed solution of using Java interfaces is rather robust and we're not sacrificing a lot, only default arguments won't be available (we'd have to write manual overloads) but that's a rarely used feature in the interfaces in the first place.
CHANGELOG.md
Outdated
| - Mitigated a rare issue that caused a crash in alternative routes fork offset calculation when using `MapboxRouteLineApi#setNavigationRoutes`. [#6404](https://github.com/mapbox/mapbox-navigation-android/pull/6404) | ||
| - Improved `MapboxNavigation#startTripSession(withForegroundService = true)` docs to indicate that it should only be called from a foreground state. [#6405](https://github.com/mapbox/mapbox-navigation-android/pull/6405) | ||
| - Fixed an issue where registered `RouteProgressObserver`s were not invoked, while alternative routes were updated. [#6397](https://github.com/mapbox/mapbox-navigation-android/pull/6397) | ||
| - Make `NavigationLocationProvider` an open class so it can be extended. [#6420](https://github.com/mapbox/mapbox-navigation-android/pull/6420) |
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's the use case for opening it up?
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.
It makes it so you can access the MapboxNavigation.LocationObserver events.
Take a look at the FeedbackActivity.kt as an example
private val navigationLocationProvider = object : NavigationLocationProvider() {
// Will be triggered when the `NavigationLocationProvider` has been attached to `mapboxNavigation`
override fun onNewLocationMatcherResult(locationMatcherResult: LocationMatcherResult) {
super.onNewLocationMatcherResult(locationMatcherResult)
updateCamera(locationMatcherResult.enhancedLocation)
}
}
// The same as calling "registerLocationObserver"
navigationLocationProvider.onAttached(mapboxNavigation)
// MapboxNavitationApp.registerObserver(navigationLocationProvider) <== alternative to the line above
// mapboxNavigation.registerLocationObserver(navigationLocationProvider) <== Also works.. There is a potential to do something like this.. But it's not the intention considering it is a class and not an interface (multiple inheritance issues)
class CustomNavigationCamera : NavigationLocationProvider() {
| class NavigationLocationProvider : LocationProvider { | ||
| open class NavigationLocationProvider : | ||
| LocationProvider, | ||
| LocationObserver, |
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.
By implementing the interface directly, we're exposing it as part of the NavigationLocationProvider surface, while it's not needed. The LocationObserver instance could be a member of the NavigationLocationProvider instead.
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.
It makes it so you can capture onNewLocationMatcherResult events downstream.
LocationConsumer does not give access to LocationMatcherResult. If it is internal, we need a another way to surface the map matched locations. Do you think there should be another registry of LocationObserver observers?
...avui-maps/src/main/java/com/mapbox/navigation/ui/maps/location/NavigationLocationProvider.kt
Outdated
Show resolved
Hide resolved
There are also abstract classes. I know that with interfaces you can implement many, while you can inherit only from one class but it can also be an alternative for some cases.
I understand that option 1 is not applicable here because we don't want to break the API, but I'm talking about approaches for new interfaces. |
| } | ||
|
|
||
| /** | ||
| * Use [getInstance] to share a single instance of the [NavigationLocationProvider]. |
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.
How is that related to the method?
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.
This function is called by MapboxNavigationApp when the object is registered by MapboxNavigationApp. It allows you to share a single instance.
But point taken, this method comment should at least give details about what this function does.
e1b0408 to
80113b5
Compare
80113b5 to
709748e
Compare
Description
I recently investigated the
-jvm-defaultcompiler flag but it would cause a SEMVER.There is a nice alternative approach, and that is
default java interfaces. Right now we are stuck with kotlin interfaces that cannot change because they will create ajava SEMVER. If a future kotlin version supports java-interop with kotlin interfaces, we can always go back and use it.Kotlin is experimenting with ideas for generating default methods, meanwhile java interfaces are simple and stable.
This pull request demonstrates the approach with the
LocationObserverand allows us to delete unused functions.I'm also proposing we upgrade
NavigationLocationProviderso it can be integrated withMapboxNavigationApparchitecture.Links to other issues and investigations
Why now?
I'm looking to delete the CarAppLocation in
:ui-androidauto:, if we updateNavigationLocationProviderI could delete that code. I'm also looking to delete the need for this.I'm also showing the
default java interfaceapproach by example @mapbox/navigation-android . There are a few interfaces that can benefit from this.