From cbcd909fd503b2c667ad35d3845b4be86e4e2ff7 Mon Sep 17 00:00:00 2001 From: VysotskiVadim Date: Mon, 10 Jul 2023 10:20:00 +0200 Subject: [PATCH] use null navigator for recreation --- .../navigation/core/MapboxNavigation.kt | 28 +++++++++---------- .../internal/MapboxNativeNavigator.kt | 2 +- .../internal/MapboxNativeNavigatorImpl.kt | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt b/libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt index 89326fc2879..e254d48c973 100644 --- a/libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt +++ b/libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt @@ -470,15 +470,7 @@ class MapboxNavigation @VisibleForTesting internal constructor( tilesVersion = navigationOptions.routingTilesOptions.tilesVersion ), navigationOptions.accessToken ?: "", - if (moduleRouter.isInternalImplementation()) { - // We pass null to let NN know that default router is used and it can rely - // on implementation details in some cases like offline-online switch. - // Meanwhile platform SDK uses its own instance of native router for - // route requests - null - } else { - RouterInterfaceAdapter(moduleRouter, ::getNavigationRoutes) - }, + getRouterInterfaceForNativeNavigator() ) etcGateAPI = EtcGateApi(navigator.experimental) @@ -620,6 +612,18 @@ class MapboxNavigation @VisibleForTesting internal constructor( roadObjectMatcher = RoadObjectMatcher(navigator) } + private fun getRouterInterfaceForNativeNavigator(): RouterInterface? { + return if (moduleRouter.isInternalImplementation()) { + // We pass null to let NN know that default router is used and it can rely + // on implementation details in some cases like offline-online switch. + // Meanwhile platform SDK uses its own instance of native router for + // route requests + null + } else { + RouterInterfaceAdapter(moduleRouter, ::getNavigationRoutes) + } + } + /** * Control the location events playback during a replay trip session. * Start a replay trip session with [startReplayTripSession]. @@ -2033,11 +2037,7 @@ class MapboxNavigation @VisibleForTesting internal constructor( historyRecorderHandles.composite, createTilesConfig(isFallback, tilesVersion), navigationOptions.accessToken ?: "", - if (moduleRouter.isInternalImplementation()) { - nativeRouter - } else { - RouterInterfaceAdapter(moduleRouter, ::getNavigationRoutes) - }, + getRouterInterfaceForNativeNavigator() ) etcGateAPI.experimental = navigator.experimental assignHistoryRecorders() diff --git a/libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigator.kt b/libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigator.kt index 95beec77f0f..5ddd5df3e75 100644 --- a/libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigator.kt +++ b/libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigator.kt @@ -53,7 +53,7 @@ interface MapboxNativeNavigator { historyRecorderComposite: HistoryRecorderHandle?, tilesConfig: TilesConfig, accessToken: String, - router: RouterInterface, + router: RouterInterface?, ) suspend fun resetRideSession() diff --git a/libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigatorImpl.kt b/libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigatorImpl.kt index 8269d3fa3eb..456e3866366 100644 --- a/libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigatorImpl.kt +++ b/libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigatorImpl.kt @@ -111,7 +111,7 @@ object MapboxNativeNavigatorImpl : MapboxNativeNavigator { historyRecorderComposite: HistoryRecorderHandle?, tilesConfig: TilesConfig, accessToken: String, - router: RouterInterface + router: RouterInterface? ) { val storeNavSessionState = navigator!!.storeNavigationSession() create(config, historyRecorderComposite, tilesConfig, accessToken, router)