From 7fb60f8f4dafaa9c2c25d08acee22e488c3d4c9e Mon Sep 17 00:00:00 2001 From: Kyle Madsen Date: Fri, 27 Jan 2023 16:45:00 -0800 Subject: [PATCH] fixing issues --- android-auto-app/build.gradle | 3 +- .../navigation/core/trip/MapboxTripStarter.kt | 48 ++++--------------- .../core/trip/MapboxTripStarterTest.kt | 37 +++++++------- 3 files changed, 32 insertions(+), 56 deletions(-) diff --git a/android-auto-app/build.gradle b/android-auto-app/build.gradle index 2608bde738f..b121a01897b 100644 --- a/android-auto-app/build.gradle +++ b/android-auto-app/build.gradle @@ -72,8 +72,7 @@ dependencies { // This example is used for development so it may depend on unstable versions. // Examples based on final versions can be found in the examples repository. // https://github.com/mapbox/mapbox-navigation-android-examples - implementation project(':libnavui-dropin') -// implementation("com.mapbox.navigation:ui-dropin:2.10.0") + implementation("com.mapbox.navigation:ui-dropin:2.10.0") implementation("com.mapbox.search:mapbox-search-android:1.0.0-beta.43") // Dependencies needed for this example. diff --git a/libnavigation-core/src/main/java/com/mapbox/navigation/core/trip/MapboxTripStarter.kt b/libnavigation-core/src/main/java/com/mapbox/navigation/core/trip/MapboxTripStarter.kt index 3618c4863c8..d62bf08d149 100644 --- a/libnavigation-core/src/main/java/com/mapbox/navigation/core/trip/MapboxTripStarter.kt +++ b/libnavigation-core/src/main/java/com/mapbox/navigation/core/trip/MapboxTripStarter.kt @@ -152,14 +152,16 @@ class MapboxTripStarter internal constructor( isLocationPermissionGranted.onEach { granted -> onMapMatchingEnabled(mapboxNavigation, granted) } - MapboxTripStarterType.ReplayRoute -> - replayRouteSession.getOptions().onEach { options -> - onReplayRouteEnabled(mapboxNavigation, options) - } - MapboxTripStarterType.ReplayHistory -> - replayHistorySession.getOptions().onEach { options -> - onReplayHistoryEnabled(mapboxNavigation, options) - } + MapboxTripStarterType.ReplayRoute -> { + replayHistorySession.onDetached(mapboxNavigation) + replayRouteSession.onAttached(mapboxNavigation) + replayRouteSession.getOptions() + } + MapboxTripStarterType.ReplayHistory -> { + replayRouteSession.onDetached(mapboxNavigation) + replayHistorySession.onAttached(mapboxNavigation) + replayHistorySession.getOptions() + } } } } @@ -186,36 +188,6 @@ class MapboxTripStarter internal constructor( } } - /** - * Internally called when the trip type has been set to replay route. - * - * @param mapboxNavigation - * @param options parameters for the [ReplayRouteSession] - */ - private fun onReplayRouteEnabled( - mapboxNavigation: MapboxNavigation, - options: ReplayRouteSessionOptions - ) { - replayHistorySession.onDetached(mapboxNavigation) - replayRouteSession.setOptions(options) - replayRouteSession.onAttached(mapboxNavigation) - } - - /** - * Internally called when the trip type has been set to replay history. - * - * @param mapboxNavigation - * @param options parameters for the [ReplayHistorySession] - */ - private fun onReplayHistoryEnabled( - mapboxNavigation: MapboxNavigation, - options: ReplayHistorySessionOptions - ) { - replayRouteSession.onDetached(mapboxNavigation) - replayHistorySession.setOptions(options) - replayHistorySession.onAttached(mapboxNavigation) - } - /** * Internally called when the trip session needs to be stopped. * diff --git a/libnavigation-core/src/test/java/com/mapbox/navigation/core/trip/MapboxTripStarterTest.kt b/libnavigation-core/src/test/java/com/mapbox/navigation/core/trip/MapboxTripStarterTest.kt index b325031378f..dbbc0d1bfad 100644 --- a/libnavigation-core/src/test/java/com/mapbox/navigation/core/trip/MapboxTripStarterTest.kt +++ b/libnavigation-core/src/test/java/com/mapbox/navigation/core/trip/MapboxTripStarterTest.kt @@ -8,6 +8,7 @@ import com.mapbox.navigation.core.directions.session.RoutesObserver import com.mapbox.navigation.core.replay.history.ReplayHistorySession import com.mapbox.navigation.core.replay.history.ReplayHistorySessionOptions import com.mapbox.navigation.core.replay.route.ReplayRouteSession +import com.mapbox.navigation.core.replay.route.ReplayRouteSessionOptions import com.mapbox.navigation.core.trip.session.TripSessionState import com.mapbox.navigation.testing.LoggingFrontendTestRule import com.mapbox.navigation.testing.MainCoroutineRule @@ -44,12 +45,19 @@ class MapboxTripStarterTest { @get:Rule val coroutineRule = MainCoroutineRule() - private val replayRouteSession = mockk(relaxed = true) - private var historyOptions = MutableStateFlow(ReplayHistorySessionOptions.Builder().build()) + private var replayRouteOptions = MutableStateFlow(ReplayRouteSessionOptions.Builder().build()) + private val replayRouteSession = mockk(relaxed = true) { + every { getOptions() } returns replayRouteOptions + every { setOptions(any()) } answers { + replayRouteOptions.value = firstArg() + this@mockk + } + } + private var replayHistoryOptions = MutableStateFlow(ReplayHistorySessionOptions.Builder().build()) private val replayHistorySession = mockk(relaxed = true) { - every { getOptions() } returns historyOptions + every { getOptions() } returns replayHistoryOptions every { setOptions(any()) } answers { - historyOptions.value = firstArg() + replayHistoryOptions.value = firstArg() } } @@ -192,20 +200,20 @@ class MapboxTripStarterTest { val mapboxNavigation = mockMapboxNavigation() sut.enableReplayRoute() - sut.onAttached(mapboxNavigation) - val nextOptions = sut.getReplayRouteSessionOptions().toBuilder() + val customOptions = sut.getReplayRouteSessionOptions().toBuilder() .decodeMinDistance(Double.MAX_VALUE) .build() - sut.enableReplayRoute(nextOptions) + sut.enableReplayRoute(customOptions) + sut.onAttached(mapboxNavigation) verifyOrder { - replayRouteSession.setOptions(any()) + replayRouteSession.setOptions(customOptions) replayRouteSession.onAttached(mapboxNavigation) + } + verify(exactly = 0) { + mapboxNavigation.stopTripSession() replayRouteSession.onDetached(mapboxNavigation) - replayRouteSession.setOptions(nextOptions) - replayRouteSession.onAttached(mapboxNavigation) } - verify(exactly = 0) { mapboxNavigation.stopTripSession() } } @Test @@ -219,7 +227,6 @@ class MapboxTripStarterTest { sut.onDetached(mapboxNavigation) verifyOrder { - replayRouteSession.onDetached(mapboxNavigation) replayHistorySession.onDetached(mapboxNavigation) replayRouteSession.onAttached(mapboxNavigation) replayRouteSession.onDetached(mapboxNavigation) @@ -283,17 +290,15 @@ class MapboxTripStarterTest { every { PermissionsManager.areLocationPermissionsGranted(any()) } returns false val mapboxNavigation = mockMapboxNavigation() - sut.enableReplayHistory() - sut.onAttached(mapboxNavigation) val nextOptions = sut.getReplayHistorySessionOptions().toBuilder() .enableSetRoute(false) .build() sut.enableReplayHistory(nextOptions) + sut.onAttached(mapboxNavigation) verifyOrder { - replayHistorySession.setOptions(any()) - replayHistorySession.onAttached(mapboxNavigation) replayHistorySession.setOptions(nextOptions) + replayHistorySession.onAttached(mapboxNavigation) } verify(exactly = 0) { mapboxNavigation.stopTripSession()