-
Notifications
You must be signed in to change notification settings - Fork 319
NAVAND-552: predownload voice instructions #6547
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.mapbox.navigation.core.internal | ||
|
|
||
| import androidx.annotation.UiThread | ||
| import androidx.annotation.VisibleForTesting | ||
| import com.mapbox.navigation.core.MapboxNavigation | ||
| import java.util.concurrent.CopyOnWriteArraySet | ||
|
|
||
| fun interface MapboxNavigationCreateObserver { | ||
|
|
||
| fun onCreated(mapboxNavigation: MapboxNavigation) | ||
| } | ||
|
|
||
| @Deprecated("Used to keep track of MapboxNavigation instances created via deprecated methods") | ||
| @UiThread | ||
| object LegacyMapboxNavigationInstanceHolder { | ||
kmadsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Volatile | ||
| private var mapboxNavigation: MapboxNavigation? = null | ||
|
|
||
| private val createObservers = CopyOnWriteArraySet<MapboxNavigationCreateObserver>() | ||
|
|
||
| fun onCreated(instance: MapboxNavigation) { | ||
| mapboxNavigation = instance | ||
| createObservers.forEach { it.onCreated(instance) } | ||
| } | ||
|
|
||
| fun onDestroyed() { | ||
| mapboxNavigation = null | ||
| } | ||
|
|
||
| fun peek(): MapboxNavigation? = mapboxNavigation | ||
|
|
||
| fun registerCreateObserver(observer: MapboxNavigationCreateObserver) { | ||
| createObservers.add(observer) | ||
| mapboxNavigation?.let { observer.onCreated(it) } | ||
| } | ||
|
|
||
| fun unregisterCreateObserver(observer: MapboxNavigationCreateObserver) { | ||
| createObservers.remove(observer) | ||
| } | ||
|
|
||
| @VisibleForTesting(otherwise = VisibleForTesting.NONE) | ||
| fun unregisterAllCreateObservers() { | ||
| createObservers.clear() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| package com.mapbox.navigation.core | ||
|
|
||
| import com.mapbox.navigation.core.internal.LegacyMapboxNavigationInstanceHolder | ||
| import com.mapbox.navigation.core.internal.MapboxNavigationCreateObserver | ||
| import com.mapbox.navigation.testing.LoggingFrontendTestRule | ||
| import io.mockk.clearMocks | ||
| import io.mockk.mockk | ||
| import io.mockk.verify | ||
| import org.junit.After | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| class LegacyMapboxNavigationInstanceHolderTest { | ||
|
|
||
| @get:Rule | ||
| val loggerRule = LoggingFrontendTestRule() | ||
| private val observer = mockk<MapboxNavigationCreateObserver>(relaxed = true) | ||
| private val mapboxNavigation = mockk<MapboxNavigation>(relaxed = true) | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| LegacyMapboxNavigationInstanceHolder.unregisterAllCreateObservers() | ||
| LegacyMapboxNavigationInstanceHolder.onDestroyed() | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| LegacyMapboxNavigationInstanceHolder.unregisterAllCreateObservers() | ||
| LegacyMapboxNavigationInstanceHolder.onDestroyed() | ||
| } | ||
|
|
||
| @Test | ||
| fun `observer is invoked on registration if has mapboxNavigation`() { | ||
| LegacyMapboxNavigationInstanceHolder.onCreated(mapboxNavigation) | ||
|
|
||
| LegacyMapboxNavigationInstanceHolder.registerCreateObserver(observer) | ||
|
|
||
| verify(exactly = 1) { observer.onCreated(mapboxNavigation) } | ||
| } | ||
|
|
||
| @Test | ||
| fun `observer is not invoked on registration if has no mapboxNavigation`() { | ||
| LegacyMapboxNavigationInstanceHolder.registerCreateObserver(observer) | ||
|
|
||
| verify(exactly = 0) { observer.onCreated(mapboxNavigation) } | ||
| } | ||
|
|
||
| @Test | ||
| fun `observer is not invoked on registration if has destroyed mapboxNavigation`() { | ||
| LegacyMapboxNavigationInstanceHolder.onCreated(mapboxNavigation) | ||
| LegacyMapboxNavigationInstanceHolder.onDestroyed() | ||
|
|
||
| LegacyMapboxNavigationInstanceHolder.registerCreateObserver(observer) | ||
|
|
||
| verify(exactly = 0) { observer.onCreated(mapboxNavigation) } | ||
| } | ||
|
|
||
| @Test | ||
| fun `observer is invoked when mapboxNavigation is created`() { | ||
| LegacyMapboxNavigationInstanceHolder.registerCreateObserver(observer) | ||
|
|
||
| LegacyMapboxNavigationInstanceHolder.onCreated(mapboxNavigation) | ||
|
|
||
| verify(exactly = 1) { observer.onCreated(mapboxNavigation) } | ||
| } | ||
|
|
||
| @Test | ||
| fun `observer is invoked when new mapboxNavigation is created`() { | ||
| LegacyMapboxNavigationInstanceHolder.registerCreateObserver(observer) | ||
| LegacyMapboxNavigationInstanceHolder.onCreated(mapboxNavigation) | ||
| clearMocks(observer, answers = false) | ||
|
|
||
| val newNavigation = mockk<MapboxNavigation>(relaxed = true) | ||
| LegacyMapboxNavigationInstanceHolder.onCreated(newNavigation) | ||
|
|
||
| verify(exactly = 1) { observer.onCreated(newNavigation) } | ||
| } | ||
|
|
||
| @Test | ||
| fun `removed observer is not invoked when mapboxNavigation is created`() { | ||
| LegacyMapboxNavigationInstanceHolder.registerCreateObserver(observer) | ||
| LegacyMapboxNavigationInstanceHolder.unregisterCreateObserver(observer) | ||
|
|
||
| LegacyMapboxNavigationInstanceHolder.onCreated(mapboxNavigation) | ||
|
|
||
| verify(exactly = 0) { observer.onCreated(any()) } | ||
| } | ||
|
|
||
| @Test | ||
| fun `multiple observers are invoked when new mapboxNavigation is created`() { | ||
| val secondObserver = mockk<MapboxNavigationCreateObserver>(relaxed = true) | ||
| LegacyMapboxNavigationInstanceHolder.registerCreateObserver(observer) | ||
| LegacyMapboxNavigationInstanceHolder.registerCreateObserver(secondObserver) | ||
|
|
||
| LegacyMapboxNavigationInstanceHolder.onCreated(mapboxNavigation) | ||
|
|
||
| verify(exactly = 1) { | ||
| observer.onCreated(mapboxNavigation) | ||
| secondObserver.onCreated(mapboxNavigation) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `peek with no instance`() { | ||
| assertNull(LegacyMapboxNavigationInstanceHolder.peek()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `peek with active instance`() { | ||
| LegacyMapboxNavigationInstanceHolder.onCreated(mapboxNavigation) | ||
|
|
||
| assertEquals(mapboxNavigation, LegacyMapboxNavigationInstanceHolder.peek()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `peek with destroyed instance`() { | ||
| LegacyMapboxNavigationInstanceHolder.onCreated(mapboxNavigation) | ||
| LegacyMapboxNavigationInstanceHolder.onDestroyed() | ||
|
|
||
| assertNull(LegacyMapboxNavigationInstanceHolder.peek()) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ import com.mapbox.navigation.core.directions.session.RoutesExtra | |||||||||||||||||||
| import com.mapbox.navigation.core.directions.session.RoutesObserver | ||||||||||||||||||||
| import com.mapbox.navigation.core.directions.session.RoutesUpdatedResult | ||||||||||||||||||||
| import com.mapbox.navigation.core.internal.HistoryRecordingStateChangeObserver | ||||||||||||||||||||
| import com.mapbox.navigation.core.internal.LegacyMapboxNavigationInstanceHolder | ||||||||||||||||||||
| import com.mapbox.navigation.core.internal.extensions.registerHistoryRecordingStateChangeObserver | ||||||||||||||||||||
| import com.mapbox.navigation.core.internal.extensions.unregisterHistoryRecordingStateChangeObserver | ||||||||||||||||||||
| import com.mapbox.navigation.core.internal.telemetry.NavigationCustomEventType | ||||||||||||||||||||
|
|
@@ -56,6 +57,7 @@ import io.mockk.coVerifyOrder | |||||||||||||||||||
| import io.mockk.every | ||||||||||||||||||||
| import io.mockk.just | ||||||||||||||||||||
| import io.mockk.mockk | ||||||||||||||||||||
| import io.mockk.mockkObject | ||||||||||||||||||||
| import io.mockk.slot | ||||||||||||||||||||
| import io.mockk.verify | ||||||||||||||||||||
| import io.mockk.verifyOrder | ||||||||||||||||||||
|
|
@@ -1898,4 +1900,32 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() { | |||||||||||||||||||
| routesPreviewController.previewNavigationRoutes(emptyList()) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Test | ||||||||||||||||||||
| fun mapboxNavigationCreationSetsInstanceToHolder() { | ||||||||||||||||||||
| mockkObject(LegacyMapboxNavigationInstanceHolder) { | ||||||||||||||||||||
| createMapboxNavigation() | ||||||||||||||||||||
| verify { LegacyMapboxNavigationInstanceHolder.onCreated(mapboxNavigation) } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Test(expected = IllegalStateException::class) | ||||||||||||||||||||
| fun mapboxNavigationIsNotCreatedIfHolderHasInstance() { | ||||||||||||||||||||
| mockkObject(LegacyMapboxNavigationInstanceHolder) { | ||||||||||||||||||||
| every { LegacyMapboxNavigationInstanceHolder.peek() } returns mockk(relaxed = true) | ||||||||||||||||||||
| createMapboxNavigation() | ||||||||||||||||||||
| verify(exactly = 0) { | ||||||||||||||||||||
| LegacyMapboxNavigationInstanceHolder.onCreated(any()) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+1914
to
+1920
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will it test the same?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How? There is not verification that |
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Test | ||||||||||||||||||||
| fun mapboxNavigationDestructionRemovesInstanceFromHolder() { | ||||||||||||||||||||
| mockkObject(LegacyMapboxNavigationInstanceHolder) { | ||||||||||||||||||||
| createMapboxNavigation() | ||||||||||||||||||||
| mapboxNavigation.onDestroy() | ||||||||||||||||||||
| verify { LegacyMapboxNavigationInstanceHolder.onDestroyed() } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+1925
to
+1929
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think is more important for us:
? Second statement seems more important to me, so I would test it instead
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your test would have passed even without the |
||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
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 is weird, why are we adding a new
@Deprecatedobject? 🤔Uh oh!
There was an error while loading. Please reload this page.
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 have to register RoutesObserver and RouteProgressObserver. And there are multiple ways of creating
MapboxNavigation:MapboxNavigationProvider(deprecated)MapboxNavigationAppThe "correct" way of observing
MapboxNavigationis usingMapboxNavigationAppbut the other ways are widely used and I want the feature to work for all the users. SoLegacyMapboxNavigationInstanceHoldertracks allMapboxNavigationinstances. Not sure if the naming is very good but I wanted to emphasize by this that theMapboxNavigationAppis the appropriate way to do it andLegacyMapboxNavigationInstanceHolderis just for us to support other creation methods.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.
LegacyMapboxNavigationInstanceHolderis an internal object. User aren't supposed to use it anyway, are they?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.
They aren't. It's just a note for us. I can just add a comment or sth instead of deprecating it.
But actually I'm thinking that it should not be deprecated at all. We still expose a valid way of creating
MapboxNavigationvia constructor and some customers use it. So it's not really "legacy", it's more like "everything including legacy". I just don't like it that we haveMapboxNavigationAppand this new way of observing. But since the new one is internal, it's not that big a deal.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.
LegacyMapboxNavigationInstanceHolderis definitely not an improvement toMapboxNavigationAppthough, in my opinion.MapboxNavigationCreateObserveris also redundant.. It is the same asMapboxNavigationObserver.onAttached.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's not, see #6547 (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.
This is not a reason to require an automatic link. It can be done after MapboxNavigation is constructed