From ce60430af6fe8e9c42d55f5475f47dd4a7eef5f3 Mon Sep 17 00:00:00 2001 From: Seth Bourget Date: Mon, 27 Feb 2023 14:38:35 -0800 Subject: [PATCH] Added flag to ignore route line updates in the view under certain conditions. --- changelog/unreleased/bugfixes/6974.md | 1 + .../maps/route/line/api/MapboxRouteLineApi.kt | 19 ++- .../route/line/api/MapboxRouteLineView.kt | 10 +- .../route/line/model/RouteLineUpdateValue.kt | 12 +- .../route/line/api/MapboxRouteLineApiTest.kt | 1 + .../route/line/api/MapboxRouteLineViewTest.kt | 145 ++++++++++++++++++ .../line/model/RouteLineUpdateValueTest.kt | 11 +- 7 files changed, 186 insertions(+), 13 deletions(-) create mode 100644 changelog/unreleased/bugfixes/6974.md diff --git a/changelog/unreleased/bugfixes/6974.md b/changelog/unreleased/bugfixes/6974.md new file mode 100644 index 00000000000..ee8705b584f --- /dev/null +++ b/changelog/unreleased/bugfixes/6974.md @@ -0,0 +1 @@ +- Fixed route progress vanishing point update issue introduced by feature that displays the active leg of the route line above inactive legs for multi-leg routes. [#6974](https://github.com/mapbox/mapbox-navigation-android/pull/6974) \ No newline at end of file diff --git a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt index 1092cc3efcf..2cff2a654e7 100644 --- a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt +++ b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt @@ -799,6 +799,12 @@ class MapboxRouteLineApi( } } + // The purpose of this is to provide the correct masking layer data to be rendered in the view. + // Although the primary route line layer data is returned here it shouldn't be rendered by the + // view. It is included because the parameter isn't nullable. If it were the data wouldn't + // be included since it's only the masking layers that should be updated. For this reason + // the variable to ignore the primary route line data is set to true so the view class will + // ignore it. private fun provideRouteLegUpdate( routeLineOverlayDynamicData: RouteLineDynamicData?, consumer: MapboxNavigationConsumer> @@ -806,13 +812,16 @@ class MapboxRouteLineApi( ifNonNull(routeLineOverlayDynamicData) { maskingLayerData -> getRouteDrawData { expected -> expected.value?.apply { + val updateValue = RouteLineUpdateValue( + this.primaryRouteLineData.dynamicData, + this.alternativeRouteLinesData.map { it.dynamicData }, + maskingLayerData + ).also { + it.ignorePrimaryRouteLineData = true + } consumer.accept( ExpectedFactory.createValue( - RouteLineUpdateValue( - this.primaryRouteLineData.dynamicData, - this.alternativeRouteLinesData.map { it.dynamicData }, - maskingLayerData - ) + updateValue ) ) } diff --git a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt index 98a5a8f5136..263f61390f0 100644 --- a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt +++ b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt @@ -370,10 +370,12 @@ class MapboxRouteLineView(options: MapboxRouteLineOptions) { jobControl.scope.launch(Dispatchers.Main) { mutex.withLock { update.onValue { - primaryRouteLineLayerGroup.map { layerId -> - toExpressionUpdateFun(layerId, it.primaryRouteLineDynamicData) - }.forEach { updateFun -> - updateFun(style) + if (!it.ignorePrimaryRouteLineData) { + primaryRouteLineLayerGroup.map { layerId -> + toExpressionUpdateFun(layerId, it.primaryRouteLineDynamicData) + }.forEach { updateFun -> + updateFun(style) + } } ifNonNull(it.routeLineMaskingLayerDynamicData) { overlayData -> diff --git a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValue.kt b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValue.kt index 301e6c3344a..7ba4e65576b 100644 --- a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValue.kt +++ b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValue.kt @@ -13,6 +13,8 @@ class RouteLineUpdateValue internal constructor( val routeLineMaskingLayerDynamicData: RouteLineDynamicData? = null ) { + internal var ignorePrimaryRouteLineData = false + /** * @return a class with mutable values for replacing. */ @@ -20,7 +22,9 @@ class RouteLineUpdateValue internal constructor( primaryRouteLineDynamicData, alternativeRouteLinesDynamicData, routeLineMaskingLayerDynamicData - ) + ).also { + it.ignorePrimaryRouteLineData = ignorePrimaryRouteLineData + } /** * Represents the mutable data for updating the appearance of the route lines. @@ -35,6 +39,8 @@ class RouteLineUpdateValue internal constructor( var routeLineMaskingLayerDynamicData: RouteLineDynamicData? = null ) { + internal var ignorePrimaryRouteLineData = false + /** * @return a RouteLineUpdateValue */ @@ -42,7 +48,9 @@ class RouteLineUpdateValue internal constructor( primaryRouteLineDynamicData, alternativeRouteLinesDynamicData, routeLineMaskingLayerDynamicData - ) + ).also { + it.ignorePrimaryRouteLineData = ignorePrimaryRouteLineData + } } /** diff --git a/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt b/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt index 5f60fe8acdd..2933702eafd 100644 --- a/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt +++ b/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt @@ -1237,6 +1237,7 @@ class MapboxRouteLineApiTest { checkExpression(expectedCasingExpressionContents, casingExpression) checkExpression(expectedTrailExpressionContents, trailExpression) checkExpression(expectedTrailCasingExpressionContents, trailCasingExpression) + assertTrue(result.ignorePrimaryRouteLineData) callbackCalled = true } diff --git a/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineViewTest.kt b/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineViewTest.kt index e1a73fa191a..b820bb0bde7 100644 --- a/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineViewTest.kt +++ b/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineViewTest.kt @@ -541,6 +541,151 @@ class MapboxRouteLineViewTest { unmockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils") } + @Test + fun renderTraveledRouteLineUpdate_whenIgnorePrimaryRouteLineData() = + coroutineRule.runBlockingTest { + mockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils") + mockkObject(MapboxRouteLineUtils) + val options = MapboxRouteLineOptions.Builder(ctx).build() + val trafficLineExp = mockk() + val routeLineExp = mockk() + val casingLineEx = mockk() + val restrictedRoadExp = mockk() + val trailExpression = mockk() + val trailCasingExpression = mockk() + val state: Expected = + ExpectedFactory.createValue( + RouteLineUpdateValue( + primaryRouteLineDynamicData = RouteLineDynamicData( + { routeLineExp }, + { casingLineEx }, + { trafficLineExp }, + { restrictedRoadExp }, + trailExpressionProvider = { trailExpression }, + trailCasingExpressionProvider = { trailCasingExpression } + ), + alternativeRouteLinesDynamicData = listOf( + RouteLineDynamicData( + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() } + ), + RouteLineDynamicData( + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() } + ) + ), + routeLineMaskingLayerDynamicData = RouteLineDynamicData( + { routeLineExp }, + { casingLineEx }, + { trafficLineExp }, + { restrictedRoadExp }, + trailExpressionProvider = { trailExpression }, + trailCasingExpressionProvider = { trailCasingExpression } + ) + ).also { + it.ignorePrimaryRouteLineData = true + } + ) + val style = mockk