Skip to content

Commit 9447ef5

Browse files
author
Seth Bourget
committed
Added flag to ignore route line updates in the view under certain conditions.
1 parent 89a2e42 commit 9447ef5

File tree

7 files changed

+186
-13
lines changed

7 files changed

+186
-13
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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)

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,20 +799,29 @@ class MapboxRouteLineApi(
799799
}
800800
}
801801

802+
// The purpose of this is to provide the correct masking layer data to be rendered in the view.
803+
// Although the primary route line layer data is returned here it shouldn't be rendered by the
804+
// view. It is included because the parameter isn't nullable. If it were the data wouldn't
805+
// be included since it's only the masking layers that should be updated. For this reason
806+
// the variable to ignore the primary route line data is set to true so the view class will
807+
// ignore it.
802808
private fun provideRouteLegUpdate(
803809
routeLineOverlayDynamicData: RouteLineDynamicData?,
804810
consumer: MapboxNavigationConsumer<Expected<RouteLineError, RouteLineUpdateValue>>
805811
) {
806812
ifNonNull(routeLineOverlayDynamicData) { maskingLayerData ->
807813
getRouteDrawData { expected ->
808814
expected.value?.apply {
815+
val updateValue = RouteLineUpdateValue(
816+
this.primaryRouteLineData.dynamicData,
817+
this.alternativeRouteLinesData.map { it.dynamicData },
818+
maskingLayerData
819+
).also {
820+
it.ignorePrimaryRouteLineData = true
821+
}
809822
consumer.accept(
810823
ExpectedFactory.createValue<RouteLineError, RouteLineUpdateValue>(
811-
RouteLineUpdateValue(
812-
this.primaryRouteLineData.dynamicData,
813-
this.alternativeRouteLinesData.map { it.dynamicData },
814-
maskingLayerData
815-
)
824+
updateValue
816825
)
817826
)
818827
}

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,12 @@ class MapboxRouteLineView(options: MapboxRouteLineOptions) {
370370
jobControl.scope.launch(Dispatchers.Main) {
371371
mutex.withLock {
372372
update.onValue {
373-
primaryRouteLineLayerGroup.map { layerId ->
374-
toExpressionUpdateFun(layerId, it.primaryRouteLineDynamicData)
375-
}.forEach { updateFun ->
376-
updateFun(style)
373+
if (!it.ignorePrimaryRouteLineData) {
374+
primaryRouteLineLayerGroup.map { layerId ->
375+
toExpressionUpdateFun(layerId, it.primaryRouteLineDynamicData)
376+
}.forEach { updateFun ->
377+
updateFun(style)
378+
}
377379
}
378380

379381
ifNonNull(it.routeLineMaskingLayerDynamicData) { overlayData ->

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValue.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ class RouteLineUpdateValue internal constructor(
1313
val routeLineMaskingLayerDynamicData: RouteLineDynamicData? = null
1414
) {
1515

16+
internal var ignorePrimaryRouteLineData = false
17+
1618
/**
1719
* @return a class with mutable values for replacing.
1820
*/
1921
fun toMutableValue() = MutableRouteLineUpdateValue(
2022
primaryRouteLineDynamicData,
2123
alternativeRouteLinesDynamicData,
2224
routeLineMaskingLayerDynamicData
23-
)
25+
).also {
26+
it.ignorePrimaryRouteLineData = ignorePrimaryRouteLineData
27+
}
2428

2529
/**
2630
* Represents the mutable data for updating the appearance of the route lines.
@@ -35,14 +39,18 @@ class RouteLineUpdateValue internal constructor(
3539
var routeLineMaskingLayerDynamicData: RouteLineDynamicData? = null
3640
) {
3741

42+
internal var ignorePrimaryRouteLineData = false
43+
3844
/**
3945
* @return a RouteLineUpdateValue
4046
*/
4147
fun toImmutableValue() = RouteLineUpdateValue(
4248
primaryRouteLineDynamicData,
4349
alternativeRouteLinesDynamicData,
4450
routeLineMaskingLayerDynamicData
45-
)
51+
).also {
52+
it.ignorePrimaryRouteLineData = ignorePrimaryRouteLineData
53+
}
4654
}
4755

4856
/**

libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ class MapboxRouteLineApiTest {
10641064
assertEquals(expectedCasingExpression, casingExpression.toString())
10651065
assertEquals(expectedTrailExpression, trailExpression.toString())
10661066
assertEquals(expectedTrailCasingExpression, trailCasingExpression.toString())
1067+
assertTrue(result.ignorePrimaryRouteLineData)
10671068

10681069
callbackCalled = true
10691070
}

libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineViewTest.kt

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,151 @@ class MapboxRouteLineViewTest {
541541
unmockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils")
542542
}
543543

544+
@Test
545+
fun renderTraveledRouteLineUpdate_whenIgnorePrimaryRouteLineData() =
546+
coroutineRule.runBlockingTest {
547+
mockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils")
548+
mockkObject(MapboxRouteLineUtils)
549+
val options = MapboxRouteLineOptions.Builder(ctx).build()
550+
val trafficLineExp = mockk<Expression>()
551+
val routeLineExp = mockk<Expression>()
552+
val casingLineEx = mockk<Expression>()
553+
val restrictedRoadExp = mockk<Expression>()
554+
val trailExpression = mockk<Expression>()
555+
val trailCasingExpression = mockk<Expression>()
556+
val state: Expected<RouteLineError, RouteLineUpdateValue> =
557+
ExpectedFactory.createValue(
558+
RouteLineUpdateValue(
559+
primaryRouteLineDynamicData = RouteLineDynamicData(
560+
{ routeLineExp },
561+
{ casingLineEx },
562+
{ trafficLineExp },
563+
{ restrictedRoadExp },
564+
trailExpressionProvider = { trailExpression },
565+
trailCasingExpressionProvider = { trailCasingExpression }
566+
),
567+
alternativeRouteLinesDynamicData = listOf(
568+
RouteLineDynamicData(
569+
{ throw UnsupportedOperationException() },
570+
{ throw UnsupportedOperationException() },
571+
{ throw UnsupportedOperationException() },
572+
{ throw UnsupportedOperationException() }
573+
),
574+
RouteLineDynamicData(
575+
{ throw UnsupportedOperationException() },
576+
{ throw UnsupportedOperationException() },
577+
{ throw UnsupportedOperationException() },
578+
{ throw UnsupportedOperationException() }
579+
)
580+
),
581+
routeLineMaskingLayerDynamicData = RouteLineDynamicData(
582+
{ routeLineExp },
583+
{ casingLineEx },
584+
{ trafficLineExp },
585+
{ restrictedRoadExp },
586+
trailExpressionProvider = { trailExpression },
587+
trailCasingExpressionProvider = { trailCasingExpression }
588+
)
589+
).also {
590+
it.ignorePrimaryRouteLineData = true
591+
}
592+
)
593+
val style = mockk<Style> {
594+
every {
595+
setStyleLayerProperty(any(), any(), any())
596+
} returns ExpectedFactory.createNone()
597+
}.also {
598+
mockCheckForLayerInitialization(it)
599+
}
600+
601+
pauseDispatcher {
602+
val view = MapboxRouteLineView(options)
603+
view.initPrimaryRouteLineLayerGroup(MapboxRouteLineUtils.layerGroup1SourceLayerIds)
604+
view.renderRouteLineUpdate(style, state)
605+
}
606+
607+
verify(exactly = 0) {
608+
style.setStyleLayerProperty(
609+
LAYER_GROUP_1_TRAFFIC,
610+
"line-gradient",
611+
trafficLineExp
612+
)
613+
}
614+
verify(exactly = 0) {
615+
style.setStyleLayerProperty(
616+
LAYER_GROUP_1_MAIN,
617+
"line-gradient",
618+
routeLineExp
619+
)
620+
}
621+
verify(exactly = 0) {
622+
style.setStyleLayerProperty(
623+
LAYER_GROUP_1_CASING,
624+
"line-gradient",
625+
casingLineEx
626+
)
627+
}
628+
verify(exactly = 0) {
629+
style.setStyleLayerProperty(
630+
LAYER_GROUP_1_RESTRICTED,
631+
"line-gradient",
632+
restrictedRoadExp
633+
)
634+
}
635+
verify(exactly = 0) {
636+
style.setStyleLayerProperty(
637+
LAYER_GROUP_1_TRAIL,
638+
"line-gradient",
639+
trailExpression
640+
)
641+
}
642+
verify(exactly = 0) {
643+
style.setStyleLayerProperty(
644+
LAYER_GROUP_1_TRAIL_CASING,
645+
"line-gradient",
646+
trailCasingExpression
647+
)
648+
}
649+
verify {
650+
style.setStyleLayerProperty(
651+
MASKING_LAYER_TRAFFIC,
652+
"line-gradient",
653+
trafficLineExp
654+
)
655+
}
656+
verify {
657+
style.setStyleLayerProperty(
658+
MASKING_LAYER_MAIN,
659+
"line-gradient",
660+
routeLineExp
661+
)
662+
}
663+
verify {
664+
style.setStyleLayerProperty(
665+
MASKING_LAYER_CASING,
666+
"line-gradient",
667+
casingLineEx
668+
)
669+
}
670+
verify {
671+
style.setStyleLayerProperty(
672+
MASKING_LAYER_TRAIL,
673+
"line-gradient",
674+
trailExpression
675+
)
676+
}
677+
verify {
678+
style.setStyleLayerProperty(
679+
MASKING_LAYER_TRAIL_CASING,
680+
"line-gradient",
681+
trailCasingExpression
682+
)
683+
}
684+
685+
unmockkObject(MapboxRouteLineUtils)
686+
unmockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils")
687+
}
688+
544689
@Test
545690
fun renderTraveledRouteLineTrimUpdate() = coroutineRule.runBlockingTest {
546691
mockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils")

libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValueTest.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mapbox.navigation.ui.maps.route.line.model
22

33
import io.mockk.mockk
44
import org.junit.Assert.assertEquals
5+
import org.junit.Assert.assertTrue
56
import org.junit.Test
67

78
class RouteLineUpdateValueTest {
@@ -12,7 +13,9 @@ class RouteLineUpdateValueTest {
1213
RouteLineDynamicData(mockk(), mockk(), mockk(), mockk()),
1314
listOf(),
1415
mockk()
15-
)
16+
).also {
17+
it.ignorePrimaryRouteLineData = true
18+
}
1619

1720
val result = original.toMutableValue()
1821

@@ -25,6 +28,7 @@ class RouteLineUpdateValueTest {
2528
original.routeLineMaskingLayerDynamicData,
2629
result.routeLineMaskingLayerDynamicData
2730
)
31+
assertTrue(result.ignorePrimaryRouteLineData)
2832
}
2933

3034
@Test
@@ -33,7 +37,9 @@ class RouteLineUpdateValueTest {
3337
RouteLineDynamicData(mockk(), mockk(), mockk(), mockk()),
3438
listOf(),
3539
mockk()
36-
)
40+
).also {
41+
it.ignorePrimaryRouteLineData = true
42+
}
3743
val replacementPrimaryRouteLineDynamicData =
3844
RouteLineDynamicData(mockk(), mockk(), mockk(), mockk())
3945
val replacementList = listOf<RouteLineDynamicData>()
@@ -48,5 +54,6 @@ class RouteLineUpdateValueTest {
4854
assertEquals(replacementPrimaryRouteLineDynamicData, result.primaryRouteLineDynamicData)
4955
assertEquals(replacementList, result.alternativeRouteLinesDynamicData)
5056
assertEquals(replacementMaskingData, result.routeLineMaskingLayerDynamicData)
57+
assertTrue(result.ignorePrimaryRouteLineData)
5158
}
5259
}

0 commit comments

Comments
 (0)