Adding support for sharing multiple instances of MapboxNavigationObserver#5829
Merged
Adding support for sharing multiple instances of MapboxNavigationObserver#5829
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5829 +/- ##
=========================================
Coverage 67.66% 67.67%
- Complexity 3829 3835 +6
=========================================
Files 586 586
Lines 23572 23577 +5
Branches 2714 2716 +2
=========================================
+ Hits 15951 15955 +4
- Misses 6603 6604 +1
Partials 1018 1018
|
28f13fa to
e943866
Compare
169a9db to
a11fe52
Compare
Contributor
Author
|
Another API i've considered is registering observers with a lifecycle. This would ensure 1 observer exists while a lifecycle is in an active state. val observer1 = MapboxNavigationApp.register(fragmentLifecycle, State.STARTED, MyObserver::class)
val observer2 = MapboxNavigationApp.register(carSessionLifecycle, State.CREATED, MyObserver::class)
// observer1 == observer2This is slightly complex to keep track of a multiple maps of |
a11fe52 to
be27e88
Compare
be27e88 to
9b5f7d3
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
We're going to use
MapboxNavigationApp.registerObserverto share subscriptions between different architectures. For example, android auto will register aMapboxNavigationObserverthat may also be registered by drop in ui.This pull request is adding safe ways to get and register
MapboxNavigationObserverinstances. Note that thread safety is not yet being address in this pull request.Code samples
Register from multiple paths
Android Auto Session onCreate
and a Fragment onCreate
This will ensure that only one
MyObserveris registered. The unregister is tied to theMapboxNavigationApp.lifecycleOwner; meaning that when there are no lifecycles attached theMyObserverinstance will be detached but still registered.Sharing multiple subscriptions
The current
MapboxNavigationApp.getObserverwill crash when the observer is not found. There are implementations that we should support in case there are multiple/optional observers registered. For example, you may have registered multiple observers that are updating status on a map (nearby places while navigating for example).MyFragment
// Clear all the instances of a specific observer type