Skip to content

Commit

Permalink
Inactive leg color fix (#7511)
Browse files Browse the repository at this point in the history
* Style inactive legs independently right away

* MapboxNavigation#currentLegIndex

* Changelog

* updated expected result because 2.7 adds soft gradient before the last point

* added missing test, adjusted data calculation needed to make the test pass

* ignore cherry-picked test that requires later changes

* update Nav Native to v111.0.0-backports.2

* fixed code style

---------

Co-authored-by: VysotskiVadim <[email protected]>
Co-authored-by: Łukasz Paczos <[email protected]>
  • Loading branch information
3 people authored Sep 14, 2023
1 parent a636d73 commit be6f787
Show file tree
Hide file tree
Showing 13 changed files with 692 additions and 110 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ Mapbox welcomes participation and contributions from everyone.
#### Bug fixes and improvements
- Updated `NavigationView` to render upcoming maneuvers. [#6175](https://github.com/mapbox/mapbox-navigation-android/pull/6175)
- Updated `NavigationView` to allow drawing of the info panel behind the translucent navigation bar. [#6145](https://github.com/mapbox/mapbox-navigation-android/pull/6145)
- Fixed an issue where `NavigationView` switches from Active Guidance to Free Drive state after rotating device when replay is enabled. [#6140](https://github.com/mapbox/mapbox-navigation-android/pull/6140)
- Fixed an issue where `NavigationView` switches from Active Guidance to Free Drive state after rotating device when replay is enabled. [#6140](https://github.com/mapbox/mapbox-navigation-android/pull/6140)
- Improved inactive leg independent styling: now the inactive leg will be styled differently right away, not only when the route progress updates begin.
- Added `MapboxNavigation#currentLegIndex`. Use this method to correctly pass leg index to `MapboxRouteLineAPI#setNavigationRoutes` method, this is especially important if you use independent inactive leg styling:
```kotlin
val routesObserver = RoutesObserver {
routeLineAPI.setNavigationRoutes(result.navigationRoutes, mapboxNavigation.currentLegIndex()).apply {
routeLineView.renderRouteDrawData(mapboxMap.getStyle()!!, this)
}
}
```

## Mapbox Navigation SDK 2.7.0 - 17 August, 2022
### Changelog
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
// version which we should use in this build
def mapboxNavigatorVersion = System.getenv("FORCE_MAPBOX_NAVIGATION_NATIVE_VERSION")
if (mapboxNavigatorVersion == null || mapboxNavigatorVersion == '') {
mapboxNavigatorVersion = '111.0.0'
mapboxNavigatorVersion = '111.0.0-backports.2'
}
println("Navigation Native version: " + mapboxNavigatorVersion)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,16 @@ class MapboxNavigation @VisibleForTesting internal constructor(
CacheHandleWrapper.requestRoadGraphDataUpdate(navigator.cache, callback)
}

/**
* Returns leg index the user is currently on. If no RouteProgress updates are available,
* returns the value passed as `initialLegIndex` parameter to `setNavigationRoutes`.
* If no routes are set, returns 0.
*/
fun currentLegIndex(): Int {
return tripSession.getRouteProgress()?.currentLegProgress?.legIndex
?: directionsSession.initialLegIndex
}

private fun internalSetNavigationRoutes(
routes: List<NavigationRoute>,
legIndex: Int = 0,
Expand Down
7 changes: 7 additions & 0 deletions libnavui-maps/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,13 @@ package com.mapbox.navigation.ui.maps.route.line {
method public com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue> setAlternativeTrafficColor(com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>, @ColorInt int color);
method public com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue> setAlternativeTrafficColor(com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>, com.mapbox.maps.extension.style.expressions.generated.Expression expression);
method public suspend Object? setNavigationRouteLines(com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi, java.util.List<com.mapbox.navigation.ui.maps.route.line.model.NavigationRouteLine> newRoutes, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>>);
method public suspend Object? setNavigationRouteLines(com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi, java.util.List<com.mapbox.navigation.ui.maps.route.line.model.NavigationRouteLine> newRoutes, int activeLegIndex, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>>);
method public suspend Object? setNavigationRouteLines(com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi, java.util.List<com.mapbox.navigation.ui.maps.route.line.model.NavigationRouteLine> newRoutes, java.util.List<com.mapbox.navigation.core.routealternatives.AlternativeRouteMetadata> alternativeRoutesMetadata, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>>);
method public suspend Object? setNavigationRouteLines(com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi, java.util.List<com.mapbox.navigation.ui.maps.route.line.model.NavigationRouteLine> newRoutes, int activeLegIndex, java.util.List<com.mapbox.navigation.core.routealternatives.AlternativeRouteMetadata> alternativeRoutesMetadata, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>>);
method public suspend Object? setNavigationRoutes(com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi, java.util.List<com.mapbox.navigation.base.route.NavigationRoute> newRoutes, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>>);
method public suspend Object? setNavigationRoutes(com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi, java.util.List<com.mapbox.navigation.base.route.NavigationRoute> newRoutes, int activeLegIndex, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>>);
method public suspend Object? setNavigationRoutes(com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi, java.util.List<com.mapbox.navigation.base.route.NavigationRoute> newRoutes, java.util.List<com.mapbox.navigation.core.routealternatives.AlternativeRouteMetadata> alternativeRoutesMetadata, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>>);
method public suspend Object? setNavigationRoutes(com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi, java.util.List<com.mapbox.navigation.base.route.NavigationRoute> newRoutes, int activeLegIndex, java.util.List<com.mapbox.navigation.core.routealternatives.AlternativeRouteMetadata> alternativeRoutesMetadata, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>>);
method public com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue> setPrimaryTrafficColor(com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>, @ColorInt int color);
method public com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue> setPrimaryTrafficColor(com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>, com.mapbox.maps.extension.style.expressions.generated.Expression expression);
method @Deprecated public suspend Object? setRoutes(com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi, java.util.List<com.mapbox.navigation.ui.maps.route.line.model.RouteLine> newRoutes, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>>);
Expand All @@ -834,8 +838,11 @@ package com.mapbox.navigation.ui.maps.route.line.api {
method public double getVanishPointOffset();
method public void setNavigationRouteLines(java.util.List<com.mapbox.navigation.ui.maps.route.line.model.NavigationRouteLine> newRoutes, com.mapbox.navigation.ui.base.util.MapboxNavigationConsumer<com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>> consumer);
method public void setNavigationRouteLines(java.util.List<com.mapbox.navigation.ui.maps.route.line.model.NavigationRouteLine> newRoutes, java.util.List<com.mapbox.navigation.core.routealternatives.AlternativeRouteMetadata> alternativeRoutesMetadata, com.mapbox.navigation.ui.base.util.MapboxNavigationConsumer<com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>> consumer);
method public void setNavigationRouteLines(java.util.List<com.mapbox.navigation.ui.maps.route.line.model.NavigationRouteLine> newRoutes, int activeLegIndex, java.util.List<com.mapbox.navigation.core.routealternatives.AlternativeRouteMetadata> alternativeRoutesMetadata, com.mapbox.navigation.ui.base.util.MapboxNavigationConsumer<com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>> consumer);
method public void setNavigationRoutes(java.util.List<com.mapbox.navigation.base.route.NavigationRoute> newRoutes, com.mapbox.navigation.ui.base.util.MapboxNavigationConsumer<com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>> consumer);
method public void setNavigationRoutes(java.util.List<com.mapbox.navigation.base.route.NavigationRoute> newRoutes, int activeLegIndex, com.mapbox.navigation.ui.base.util.MapboxNavigationConsumer<com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>> consumer);
method public void setNavigationRoutes(java.util.List<com.mapbox.navigation.base.route.NavigationRoute> newRoutes, java.util.List<com.mapbox.navigation.core.routealternatives.AlternativeRouteMetadata> alternativeRoutesMetadata, com.mapbox.navigation.ui.base.util.MapboxNavigationConsumer<com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>> consumer);
method public void setNavigationRoutes(java.util.List<com.mapbox.navigation.base.route.NavigationRoute> newRoutes, int activeLegIndex, java.util.List<com.mapbox.navigation.core.routealternatives.AlternativeRouteMetadata> alternativeRoutesMetadata, com.mapbox.navigation.ui.base.util.MapboxNavigationConsumer<com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>> consumer);
method public void setRoadClasses(java.util.List<java.lang.String> roadClasses);
method @Deprecated public void setRoutes(java.util.List<com.mapbox.navigation.ui.maps.route.line.model.RouteLine> newRoutes, com.mapbox.navigation.ui.base.util.MapboxNavigationConsumer<com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue>> consumer);
method public com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteLineUpdateValue> setVanishingOffset(double offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1332,8 +1332,26 @@ internal object MapboxRouteLineUtils {
isPrimaryRoute,
colorResources
)
if (useSoftGradient) {
val stopGap = softGradientTransitionDistance / route.distance()
val stopGap = softGradientTransitionDistance / route.distance()
getTrafficLineExpression(
vanishingPointOffset,
lineStartColor,
lineColor,
stopGap,
useSoftGradient,
segments
)
}

internal fun getTrafficLineExpression(
vanishingPointOffset: Double,
lineStartColor: Int,
lineColor: Int,
stopGap: Double,
useSoftGradient: Boolean,
segments: List<RouteLineExpressionData>,
): Expression {
return if (useSoftGradient) {
getTrafficLineExpressionSoftGradient(
vanishingPointOffset,
lineStartColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.mapbox.navigation.core.routealternatives.AlternativeRouteMetadata
import com.mapbox.navigation.ui.maps.internal.route.line.MapboxRouteLineUtils
import com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi
import com.mapbox.navigation.ui.maps.route.line.model.ClosestRouteValue
import com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineOptions
import com.mapbox.navigation.ui.maps.route.line.model.NavigationRouteLine
import com.mapbox.navigation.ui.maps.route.line.model.RouteLine
import com.mapbox.navigation.ui.maps.route.line.model.RouteLineClearValue
Expand Down Expand Up @@ -83,18 +84,59 @@ object MapboxRouteLineApiExtensions {
*
* @param newRoutes one or more routes. The first route in the collection will be considered
* the primary route and any additional routes will be alternate routes.
* @param activeLegIndex the index of the currently active leg of the primary route.
*
* @return a state which contains the side effects to be applied to the map
*/
suspend fun MapboxRouteLineApi.setNavigationRouteLines(
newRoutes: List<NavigationRouteLine>,
activeLegIndex: Int,
): Expected<RouteLineError, RouteSetValue> {
return setNavigationRouteLines(
newRoutes = newRoutes,
activeLegIndex = activeLegIndex,
alternativeRoutesMetadata = emptyList()
)
}

/**
* Sets the routes that will be operated on.
*
* @param newRoutes one or more routes. The first route in the collection will be considered
* the primary route and any additional routes will be alternate routes.
* @param alternativeRoutesMetadata if available, the update will hide the portions of the alternative routes
* until the deviation point with the primary route. See [MapboxNavigation.getAlternativeMetadataFor].
*
* @return a state which contains the side effects to be applied to the map
*/
suspend fun MapboxRouteLineApi.setNavigationRouteLines(
newRoutes: List<NavigationRouteLine>,
alternativeRoutesMetadata: List<AlternativeRouteMetadata>
): Expected<RouteLineError, RouteSetValue> {
return setNavigationRouteLines(newRoutes, 0, alternativeRoutesMetadata)
}

/**
* Sets the routes that will be operated on.
*
* @param newRoutes one or more routes. The first route in the collection will be considered
* the primary route and any additional routes will be alternate routes.
* @param activeLegIndex the index of the currently active leg of the primary route.
* This is used when [MapboxRouteLineOptions.styleInactiveRouteLegsIndependently] is enabled.
* @param alternativeRoutesMetadata if available, the update will hide the portions of the alternative routes
* until the deviation point with the primary route. See [MapboxNavigation.getAlternativeMetadataFor].
*
* @return a state which contains the side effects to be applied to the map
*/
suspend fun MapboxRouteLineApi.setNavigationRouteLines(
newRoutes: List<NavigationRouteLine>,
activeLegIndex: Int,
alternativeRoutesMetadata: List<AlternativeRouteMetadata>
): Expected<RouteLineError, RouteSetValue> {
return suspendCancellableCoroutine { continuation ->
this.setNavigationRouteLines(
newRoutes,
activeLegIndex,
alternativeRoutesMetadata
) { value -> continuation.resume(value) }

Expand Down Expand Up @@ -123,18 +165,60 @@ object MapboxRouteLineApiExtensions {
*
* @param newRoutes one or more routes. The first route in the collection will be considered
* the primary route and any additional routes will be alternate routes.
* @param activeLegIndex the index of the currently active leg of the primary route.
* This is used when [MapboxRouteLineOptions.styleInactiveRouteLegsIndependently] is enabled.
*
* @return a state which contains the side effects to be applied to the map
*/
suspend fun MapboxRouteLineApi.setNavigationRoutes(
newRoutes: List<NavigationRoute>,
activeLegIndex: Int,
): Expected<RouteLineError, RouteSetValue> {
return setNavigationRoutes(
newRoutes = newRoutes,
activeLegIndex = activeLegIndex,
alternativeRoutesMetadata = emptyList()
)
}

/**
* Sets the routes that will be operated on.
*
* @param newRoutes one or more routes. The first route in the collection will be considered
* the primary route and any additional routes will be alternate routes.
* @param alternativeRoutesMetadata if available, the update will hide the portions of the alternative routes
* until the deviation point with the primary route. See [MapboxNavigation.getAlternativeMetadataFor].
*
* @return a state which contains the side effects to be applied to the map
*/
suspend fun MapboxRouteLineApi.setNavigationRoutes(
newRoutes: List<NavigationRoute>,
alternativeRoutesMetadata: List<AlternativeRouteMetadata>
): Expected<RouteLineError, RouteSetValue> {
return setNavigationRoutes(newRoutes, 0, alternativeRoutesMetadata)
}

/**
* Sets the routes that will be operated on.
*
* @param newRoutes one or more routes. The first route in the collection will be considered
* the primary route and any additional routes will be alternate routes.
* @param activeLegIndex the index of the currently active leg of the primary route.
* This is used when [MapboxRouteLineOptions.styleInactiveRouteLegsIndependently] is enabled.
* @param alternativeRoutesMetadata if available, the update will hide the portions of the alternative routes
* until the deviation point with the primary route. See [MapboxNavigation.getAlternativeMetadataFor].
*
* @return a state which contains the side effects to be applied to the map
*/
suspend fun MapboxRouteLineApi.setNavigationRoutes(
newRoutes: List<NavigationRoute>,
activeLegIndex: Int,
alternativeRoutesMetadata: List<AlternativeRouteMetadata>
): Expected<RouteLineError, RouteSetValue> {
return suspendCancellableCoroutine { continuation ->
this.setNavigationRoutes(
newRoutes,
activeLegIndex,
alternativeRoutesMetadata
) { value -> continuation.resume(value) }

Expand Down
Loading

0 comments on commit be6f787

Please sign in to comment.