Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class FreeDriveNavigationActivity : AppCompatActivity(), OnMapReadyCallback {
activityRef.get()?.navigationMapboxMap?.updateLocation(result.lastLocation)
}

override fun onFailure(exception: java.lang.Exception) {
override fun onFailure(exception: Exception) {
Timber.i(exception)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ constructor(
Message("onDestroy")
)
MapboxNavigationTelemetry.unregisterListeners(this@MapboxNavigation)
directionsSession.shutdownSession()
directionsSession.shutdown()
directionsSession.unregisterAllRoutesObservers()
tripSession.stop()
tripSession.unregisterAllLocationObservers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ internal interface DirectionsSession {
/**
* Interrupts the route-fetching request
*/
fun shutdownSession()
fun shutdown()
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ internal class MapboxDirectionsSession(
/**
* Interrupt route-fetcher request
*/
override fun shutdownSession() {
override fun shutdown() {
router.shutdown()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class MapboxTripSession(
enhancedLocation = null
routeProgress = null
isOffRoute = false
navigator.reset()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ class MapboxNavigationTest {
verify(exactly = 1) { tripSession.route = null }
}

@Test
fun onDestroyCallsTripSessionStop() {
mapboxNavigation.onDestroy()

verify(exactly = 1) { tripSession.stop() }
}

@Test
fun unregisterAllBannerInstructionsObservers() {
mapboxNavigation.onDestroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class MapboxDirectionsSessionTest {

@Test
fun shutDown() {
session.shutdownSession()
session.shutdown()
verify { router.shutdown() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ class MapboxTripSessionTest {
}

@Test
fun stopSession() {
fun stopSessionCallsTripServiceStopService() {
tripSession.start()

tripSession.stop()

verify { locationEngine.removeLocationUpdates(locationCallbackSlot.captured) }
}

@Test
fun stopSessionCallsLocationEngineRemoveLocationUpdates() {
tripSession.start()
locationCallbackSlot.captured.onSuccess(locationEngineResult)

tripSession.stop()

verify { tripService.stopService() }
verify { locationEngine.removeLocationUpdates(locationCallbackSlot.captured) }
}

@Test
fun stopSessionCallsMapboxNativeNavigatorReset() {
tripSession.start()

tripSession.stop()

verify { navigator.reset() }
}

@Test
fun stopSessionDoesNotClearUpRoute() {
tripSession.route = route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,9 @@ interface MapboxNativeNavigator {
* @return [VoiceInstruction] for step index you passed
*/
fun getVoiceInstruction(index: Int): VoiceInstruction?

/**
* Reset resources.
*/
fun reset()
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object MapboxNativeNavigatorImpl : MapboxNativeNavigator {
private const val TWO_LEGS: Short = 2
private const val PRIMARY_ROUTE_INDEX = 0

private val navigator: Navigator = Navigator()
private var navigator: Navigator = Navigator()
private var route: DirectionsRoute? = null
private var routeBufferGeoJson: Geometry? = null
private val mutex = Mutex()
Expand Down Expand Up @@ -323,6 +323,12 @@ object MapboxNativeNavigatorImpl : MapboxNativeNavigator {
override fun getVoiceInstruction(index: Int): VoiceInstruction? =
navigator.getVoiceInstruction(index)

/**
* Reset resources.
*/
override fun reset() {
navigator = Navigator()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to reset the other things, like route

}
/**
* Builds [RouteProgress] object based on [NavigationStatus] returned by [Navigator]
*/
Expand Down