Skip to content

Commit 36d17f0

Browse files
committed
NAVAND-777: expose a class instead of an interface
1 parent 4965cbb commit 36d17f0

File tree

11 files changed

+92
-126
lines changed

11 files changed

+92
-126
lines changed

libnavigation-core/api/current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ package com.mapbox.navigation.core.routeoptions {
882882

883883
package com.mapbox.navigation.core.routerefresh {
884884

885-
@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public interface RouteRefreshController {
885+
public final class RouteRefreshController {
886886
method public void registerRouteRefreshStateObserver(com.mapbox.navigation.core.routerefresh.RouteRefreshStatesObserver routeRefreshStatesObserver);
887887
method public void requestImmediateRouteRefresh();
888888
method public void unregisterRouteRefreshStateObserver(com.mapbox.navigation.core.routerefresh.RouteRefreshStatesObserver routeRefreshStatesObserver);

libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ import com.mapbox.navigation.core.routealternatives.RouteAlternativesObserver
8585
import com.mapbox.navigation.core.routealternatives.RouteAlternativesRequestCallback
8686
import com.mapbox.navigation.core.routeoptions.RouteOptionsUpdater
8787
import com.mapbox.navigation.core.routerefresh.RouteRefreshController
88-
import com.mapbox.navigation.core.routerefresh.RouteRefreshControllerImpl
8988
import com.mapbox.navigation.core.routerefresh.RouteRefreshControllerProvider
9089
import com.mapbox.navigation.core.telemetry.MapboxNavigationTelemetry
9190
import com.mapbox.navigation.core.telemetry.events.FeedbackEvent
@@ -267,7 +266,6 @@ class MapboxNavigation @VisibleForTesting internal constructor(
267266
private val internalOffRouteObserver: OffRouteObserver
268267
private val internalFallbackVersionsObserver: FallbackVersionsObserver
269268
private val routeAlternativesController: RouteAlternativesController
270-
private val routeRefreshControllerImpl: RouteRefreshControllerImpl
271269
private val arrivalProgressObserver: ArrivalProgressObserver
272270
private val electronicHorizonOptions: ElectronicHorizonOptions = ElectronicHorizonOptions(
273271
navigationOptions.eHorizonOptions.length,
@@ -558,7 +556,8 @@ class MapboxNavigation @VisibleForTesting internal constructor(
558556
tripSession,
559557
threadController,
560558
)
561-
routeRefreshControllerImpl = RouteRefreshControllerProvider.createRouteRefreshController(
559+
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
560+
routeRefreshController = RouteRefreshControllerProvider.createRouteRefreshController(
562561
threadController.getMainScopeAndRootJob().scope,
563562
threadController.getImmediateMainScopeAndRootJob().scope,
564563
navigationOptions.routeRefreshOptions,
@@ -569,8 +568,7 @@ class MapboxNavigation @VisibleForTesting internal constructor(
569568
Time.SystemImpl
570569
)
571570
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
572-
routeRefreshController = routeRefreshControllerImpl
573-
routeRefreshControllerImpl.registerRouteRefreshObserver {
571+
routeRefreshController.registerRouteRefreshObserver {
574572
internalSetNavigationRoutes(
575573
it.allRoutesProgressData.map { pair -> pair.first },
576574
SetRoutes.RefreshRoutes(it.primaryRouteProgressData)
@@ -1224,7 +1222,8 @@ class MapboxNavigation @VisibleForTesting internal constructor(
12241222
historyRecordingStateHandler.unregisterAllStateChangeObservers()
12251223
historyRecordingStateHandler.unregisterAllCopilotSessionObservers()
12261224
developerMetadataAggregator.unregisterAllObservers()
1227-
routeRefreshControllerImpl.destroy()
1225+
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
1226+
routeRefreshController.destroy()
12281227
routesPreviewController.unregisterAllRoutesPreviewObservers()
12291228
runInTelemetryContext { telemetry ->
12301229
telemetry.destroy(this@MapboxNavigation)
@@ -1887,7 +1886,8 @@ class MapboxNavigation @VisibleForTesting internal constructor(
18871886
private fun createInternalRoutesObserver() = RoutesObserver { result ->
18881887
latestLegIndex = null
18891888
routeRefreshRequestDataProvider.onNewRoutes()
1890-
routeRefreshControllerImpl.requestPlannedRouteRefresh(result.navigationRoutes)
1889+
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
1890+
routeRefreshController.requestPlannedRouteRefresh(result.navigationRoutes)
18911891
}
18921892

18931893
private fun createInternalOffRouteObserver() = OffRouteObserver { offRoute ->

libnavigation-core/src/main/java/com/mapbox/navigation/core/SetRoutes.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mapbox.navigation.core
22

33
import com.mapbox.navigation.core.reroute.NavigationRerouteController
4-
import com.mapbox.navigation.core.routerefresh.RouteRefreshControllerImpl
4+
import com.mapbox.navigation.core.routerefresh.RouteRefreshController
55

66
internal sealed class SetRoutes {
77

@@ -37,7 +37,7 @@ internal sealed class SetRoutes {
3737
/**
3838
* Triggered when the **routes do not change but are refreshed**.
3939
*
40-
* Currently this can only be trigger internally by a response to [RouteRefreshControllerImpl.refresh].
40+
* Currently this can only be trigger internally by a response to [RouteRefreshController.refresh].
4141
*/
4242
internal data class RefreshRoutes(
4343
val routeProgressData: RouteProgressData
Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,61 @@
11
package com.mapbox.navigation.core.routerefresh
22

33
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
4-
import com.mapbox.navigation.core.directions.session.RoutesObserver
5-
6-
/**
7-
* This class lets you manage route refreshes.
8-
*/
9-
@ExperimentalPreviewMapboxNavigationAPI
10-
interface RouteRefreshController {
11-
12-
/**
13-
* Immediately refresh current navigation routes.
14-
* Listen for refreshed routes using [RoutesObserver].
15-
*
16-
* The on-demand refresh request is not guaranteed to succeed and call the [RoutesObserver],
17-
* [requestImmediateRouteRefresh] invocations cannot be coupled with
18-
* [RoutesObserver.onRoutesChanged] callbacks for state management.
19-
* You can use [registerRouteRefreshStateObserver] to monitor refresh statuses independently.
20-
*/
21-
fun requestImmediateRouteRefresh()
22-
23-
/**
24-
* Register a [RouteRefreshStatesObserver] to be notified of Route refresh state changes.
25-
*
26-
* @param routeRefreshStatesObserver RouteRefreshStatesObserver
27-
*/
4+
import com.mapbox.navigation.base.route.NavigationRoute
5+
import com.mapbox.navigation.utils.internal.logI
6+
7+
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
8+
class RouteRefreshController internal constructor(
9+
private val plannedRouteRefreshController: PlannedRouteRefreshController,
10+
private val immediateRouteRefreshController: ImmediateRouteRefreshController,
11+
private val stateHolder: RouteRefreshStateHolder,
12+
private val refreshObserversManager: RefreshObserversManager,
13+
private val routeRefresherResultProcessor: RouteRefresherResultProcessor,
14+
) {
15+
2816
fun registerRouteRefreshStateObserver(
2917
routeRefreshStatesObserver: RouteRefreshStatesObserver
30-
)
18+
) {
19+
stateHolder.registerRouteRefreshStateObserver(routeRefreshStatesObserver)
20+
}
3121

32-
/**
33-
* Unregisters a [RouteRefreshStatesObserver].
34-
*/
3522
fun unregisterRouteRefreshStateObserver(
3623
routeRefreshStatesObserver: RouteRefreshStatesObserver
37-
)
24+
) {
25+
stateHolder.unregisterRouteRefreshStateObserver(routeRefreshStatesObserver)
26+
}
27+
28+
fun requestImmediateRouteRefresh() {
29+
val routes = plannedRouteRefreshController.routesToRefresh
30+
if (routes.isNullOrEmpty()) {
31+
logI("No routes to refresh", RouteRefreshLog.LOG_CATEGORY)
32+
stateHolder.onStarted()
33+
stateHolder.onFailure("No routes to refresh")
34+
return
35+
}
36+
plannedRouteRefreshController.pause()
37+
immediateRouteRefreshController.requestRoutesRefresh(routes) {
38+
if (it.value?.success == false) {
39+
plannedRouteRefreshController.resume()
40+
}
41+
}
42+
}
43+
44+
internal fun registerRouteRefreshObserver(observer: RouteRefreshObserver) {
45+
refreshObserversManager.registerObserver(observer)
46+
}
47+
48+
internal fun unregisterRouteRefreshObserver(observer: RouteRefreshObserver) {
49+
refreshObserversManager.unregisterObserver(observer)
50+
}
51+
52+
internal fun destroy() {
53+
refreshObserversManager.unregisterAllObservers()
54+
stateHolder.unregisterAllRouteRefreshStateObservers()
55+
}
56+
57+
internal fun requestPlannedRouteRefresh(routes: List<NavigationRoute>) {
58+
routeRefresherResultProcessor.reset()
59+
plannedRouteRefreshController.startRoutesRefreshing(routes)
60+
}
3861
}

libnavigation-core/src/main/java/com/mapbox/navigation/core/routerefresh/RouteRefreshControllerImpl.kt

Lines changed: 0 additions & 61 deletions
This file was deleted.

libnavigation-core/src/main/java/com/mapbox/navigation/core/routerefresh/RouteRefreshControllerProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal object RouteRefreshControllerProvider {
2424
alternativeMetadataProvider: AlternativeMetadataProvider,
2525
evDynamicDataHolder: EVDynamicDataHolder,
2626
timeProvider: Time
27-
): RouteRefreshControllerImpl {
27+
): RouteRefreshController {
2828
val routeRefresher = RouteRefresher(
2929
RoutesProgressDataProvider(
3030
primaryRouteProgressDataProvider,
@@ -61,7 +61,7 @@ internal object RouteRefreshControllerProvider {
6161
scope,
6262
routeRefresherResultProcessor
6363
)
64-
return RouteRefreshControllerImpl(
64+
return RouteRefreshController(
6565
plannedRouteRefreshController,
6666
immediateRouteRefreshController,
6767
stateHolder,

libnavigation-core/src/test/java/com/mapbox/navigation/core/MapboxNavigationBaseTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import com.mapbox.navigation.core.reroute.RerouteController
2727
import com.mapbox.navigation.core.reroute.RerouteState
2828
import com.mapbox.navigation.core.routealternatives.RouteAlternativesController
2929
import com.mapbox.navigation.core.routealternatives.RouteAlternativesControllerProvider
30-
import com.mapbox.navigation.core.routerefresh.RouteRefreshControllerImpl
30+
import com.mapbox.navigation.core.routerefresh.RouteRefreshController
3131
import com.mapbox.navigation.core.routerefresh.RouteRefreshControllerProvider
3232
import com.mapbox.navigation.core.telemetry.MapboxNavigationTelemetry
3333
import com.mapbox.navigation.core.testutil.createRoutesUpdatedResult
@@ -87,7 +87,7 @@ internal open class MapboxNavigationBaseTest {
8787
val locationEngine: LocationEngine = mockk(relaxUnitFun = true)
8888
val distanceFormatterOptions: DistanceFormatterOptions = mockk(relaxed = true)
8989
val routingTilesOptions: RoutingTilesOptions = mockk(relaxed = true)
90-
val routeRefreshController: RouteRefreshControllerImpl = mockk(relaxed = true)
90+
val routeRefreshController: RouteRefreshController = mockk(relaxed = true)
9191
val evDynamicDataHolder: EVDynamicDataHolder = mockk(relaxed = true)
9292
val routeAlternativesController: RouteAlternativesController = mockk(relaxed = true)
9393
val routeProgress: RouteProgress = mockk(relaxed = true)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.junit.Rule
1515
import org.junit.Test
1616

1717
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
18-
class RouteRefreshControllerImplTest {
18+
class RouteRefreshControllerTest {
1919

2020
private val logger = mockk<LoggerFrontend>(relaxed = true)
2121

@@ -28,7 +28,7 @@ class RouteRefreshControllerImplTest {
2828
private val stateHolder = mockk<RouteRefreshStateHolder>(relaxed = true)
2929
private val refreshObserversManager = mockk<RefreshObserversManager>(relaxed = true)
3030
private val resultProcessor = mockk<RouteRefresherResultProcessor>(relaxed = true)
31-
private val sut = RouteRefreshControllerImpl(
31+
private val sut = RouteRefreshController(
3232
plannedRouteRefreshController,
3333
immediateRouteRefreshController,
3434
stateHolder,

libnavigation-core/src/test/java/com/mapbox/navigation/core/routerefresh/RouteRefreshIntegrationTest.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import io.mockk.every
3131
import io.mockk.mockk
3232
import io.mockk.mockkObject
3333
import io.mockk.unmockkObject
34+
import kotlinx.coroutines.ExperimentalCoroutinesApi
3435
import kotlinx.coroutines.SupervisorJob
3536
import kotlinx.coroutines.delay
3637
import kotlinx.coroutines.launch
@@ -40,8 +41,8 @@ import org.junit.After
4041
import org.junit.Before
4142
import org.junit.Rule
4243

43-
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
44-
open internal class RouteRefreshIntegrationTest {
44+
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class, ExperimentalCoroutinesApi::class)
45+
internal open class RouteRefreshIntegrationTest {
4546

4647
@get:Rule
4748
val loggerRule = LoggingFrontendTestRule()
@@ -63,7 +64,7 @@ open internal class RouteRefreshIntegrationTest {
6364
tripSession,
6465
threadController
6566
)
66-
lateinit var routeRefreshController: RouteRefreshControllerImpl
67+
lateinit var routeRefreshController: RouteRefreshController
6768
val stateObserver = TestStateObserver()
6869
val refreshObserver = TestRefreshObserver()
6970
val testDispatcher = TestCoroutineDispatcher()
@@ -95,23 +96,23 @@ open internal class RouteRefreshIntegrationTest {
9596
every {
9697
NativeRouteParserWrapper.parseDirectionsResponse(any(), any(), any())
9798
} returns ExpectedFactory.createValue(listOf(mockk(relaxed = true)))
98-
primaryRouteProgressDataProvider.onRouteProgressChanged(mockk {
99-
every { currentLegProgress } returns mockk {
100-
every { legIndex } returns 0
101-
every { geometryIndex } returns 0
99+
primaryRouteProgressDataProvider.onRouteProgressChanged(
100+
mockk {
101+
every { currentLegProgress } returns mockk {
102+
every { legIndex } returns 0
103+
every { geometryIndex } returns 0
104+
}
105+
every { currentRouteGeometryIndex } returns 0
102106
}
103-
every { currentRouteGeometryIndex } returns 0
104-
})
107+
)
105108
}
106109

107-
108110
@After
109111
fun tearDown() {
110112
unmockkObject(NativeRouteParserWrapper)
111113
}
112114

113-
114-
fun createRefreshController(refreshInternal: Long): RouteRefreshControllerImpl {
115+
fun createRefreshController(refreshInternal: Long): RouteRefreshController {
115116
val options = RouteRefreshOptions.Builder().intervalMillis(refreshInternal).build()
116117
return RouteRefreshControllerProvider.createRouteRefreshController(
117118
testScope,
@@ -174,9 +175,11 @@ open internal class RouteRefreshIntegrationTest {
174175
leg.toBuilder()
175176
.annotation(
176177
leg.annotation()!!.toBuilder()
177-
.duration(leg.annotation()!!.duration()!!.map {
178-
it + (invocationNumber + 1) * 0.1
179-
})
178+
.duration(
179+
leg.annotation()!!.duration()!!.map {
180+
it + (invocationNumber + 1) * 0.1
181+
}
182+
)
180183
.build()
181184
)
182185
.build()

libnavigation-core/src/test/java/com/mapbox/navigation/core/routerefresh/RouteRefreshOnDemandIntegrationTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package com.mapbox.navigation.core.routerefresh
22

3+
import kotlinx.coroutines.ExperimentalCoroutinesApi
34
import kotlinx.coroutines.test.runBlockingTest
45
import org.junit.Assert.assertEquals
56
import org.junit.Test
67

8+
@OptIn(ExperimentalCoroutinesApi::class)
79
internal class RouteRefreshOnDemandIntegrationTest : RouteRefreshIntegrationTest() {
810

911
@Test
1012
fun routeRefreshOnDemandDoesNotNotifyObserverBeforeTimeout() = runBlockingTest {
11-
val routes = setUpRoutes("route_response_single_route_refresh.json", successfulAttemptNumber = 100)
13+
val routes = setUpRoutes(
14+
"route_response_single_route_refresh.json",
15+
successfulAttemptNumber = 100
16+
)
1217
routeRefreshController = createRefreshController(60_000)
1318
routeRefreshController.registerRouteRefreshObserver(refreshObserver)
1419

0 commit comments

Comments
 (0)