@@ -56,10 +56,10 @@ class ReplayRouteSession : MapboxNavigationObserver {
5656
5757 private var options = ReplayRouteSessionOptions .Builder ().build()
5858
59- private lateinit var polylineDecodeStream: ReplayPolylineDecodeStream
6059 private lateinit var replayRouteMapper: ReplayRouteMapper
6160 private var mapboxNavigation: MapboxNavigation ? = null
6261 private var lastLocationEvent: ReplayEventUpdateLocation ? = null
62+ private var polylineDecodeStream: ReplayPolylineDecodeStream ? = null
6363 private var currentRoute: NavigationRoute ? = null
6464
6565 private val routeProgressObserver = RouteProgressObserver { routeProgress ->
@@ -72,6 +72,8 @@ class ReplayRouteSession : MapboxNavigationObserver {
7272 private val routesObserver = RoutesObserver { result ->
7373 if (result.navigationRoutes.isEmpty()) {
7474 mapboxNavigation?.resetReplayLocation()
75+ currentRoute = null
76+ polylineDecodeStream = null
7577 }
7678 }
7779
@@ -114,19 +116,21 @@ class ReplayRouteSession : MapboxNavigationObserver {
114116
115117 private fun MapboxNavigation.resetReplayLocation () {
116118 mapboxReplayer.clearEvents()
117- resetTripSession()
118- if (options.locationResetEnabled) {
119- val context = navigationOptions.applicationContext
120- if (PermissionsManager .areLocationPermissionsGranted(context)) {
121- pushRealLocation(context)
122- } else {
123- logW(LOG_CATEGORY ) {
124- " Location permission have not been accepted. If this is intentional, disable" +
125- " this warning with ReplayRouteSessionOptions.locationResetEnabled."
119+ resetTripSession {
120+ if (options.locationResetEnabled) {
121+ val context = navigationOptions.applicationContext
122+ if (PermissionsManager .areLocationPermissionsGranted(context)) {
123+ pushRealLocation(context)
124+ } else {
125+ logW(LOG_CATEGORY ) {
126+ " Location permissions have not been accepted. If this is intentional, " +
127+ " disable this warning with " +
128+ " ReplayRouteSessionOptions.locationResetEnabled."
129+ }
126130 }
127131 }
132+ mapboxReplayer.play()
128133 }
129- mapboxReplayer.play()
130134 }
131135
132136 override fun onDetached (mapboxNavigation : MapboxNavigation ) {
@@ -159,7 +163,7 @@ class ReplayRouteSession : MapboxNavigationObserver {
159163
160164 // Skip up to the current geometry index. There is some imprecision here because the
161165 // distance traveled is not equal to a route index.
162- polylineDecodeStream.skip(routeProgress.currentRouteGeometryIndex)
166+ polylineDecodeStream? .skip(routeProgress.currentRouteGeometryIndex)
163167
164168 pushMorePoints()
165169 }
@@ -172,7 +176,7 @@ class ReplayRouteSession : MapboxNavigationObserver {
172176 }
173177
174178 private fun pushMorePoints () {
175- val nextPoints = polylineDecodeStream.decode(options.decodeMinDistance)
179+ val nextPoints = polylineDecodeStream? .decode(options.decodeMinDistance) ? : return
176180 val nextReplayLocations = replayRouteMapper.mapPointList(nextPoints)
177181 lastLocationEvent = nextReplayLocations.lastOrNull { it is ReplayEventUpdateLocation }
178182 as ? ReplayEventUpdateLocation
0 commit comments