Skip to content

Commit 8e5967b

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

File tree

9 files changed

+70
-108
lines changed

9 files changed

+70
-108
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)

libnavigation-core/src/test/java/com/mapbox/navigation/core/routerefresh/RouteRefreshControllerImplTest.kt renamed to libnavigation-core/src/test/java/com/mapbox/navigation/core/routerefresh/RouteRefreshControllerTest.kt

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ open internal class RouteRefreshIntegrationTest {
6363
tripSession,
6464
threadController
6565
)
66-
lateinit var routeRefreshController: RouteRefreshControllerImpl
66+
lateinit var routeRefreshController: RouteRefreshController
6767
val stateObserver = TestStateObserver()
6868
val refreshObserver = TestRefreshObserver()
6969
val testDispatcher = TestCoroutineDispatcher()
@@ -111,7 +111,7 @@ open internal class RouteRefreshIntegrationTest {
111111
}
112112

113113

114-
fun createRefreshController(refreshInternal: Long): RouteRefreshControllerImpl {
114+
fun createRefreshController(refreshInternal: Long): RouteRefreshController {
115115
val options = RouteRefreshOptions.Builder().intervalMillis(refreshInternal).build()
116116
return RouteRefreshControllerProvider.createRouteRefreshController(
117117
testScope,

0 commit comments

Comments
 (0)