@@ -10,6 +10,9 @@ import com.mapbox.common.BillingSessionStatus
1010import com.mapbox.common.SessionSKUIdentifier
1111import com.mapbox.common.UserSKUIdentifier
1212import com.mapbox.geojson.Point
13+ import com.mapbox.navigation.base.internal.extensions.isEVChargingWaypoint
14+ import com.mapbox.navigation.base.internal.route.Waypoint
15+ import com.mapbox.navigation.base.internal.utils.internalWaypoints
1316import com.mapbox.navigation.base.route.NavigationRoute
1417import com.mapbox.navigation.base.trip.model.RouteLegProgress
1518import com.mapbox.navigation.base.trip.model.RouteProgress
@@ -275,10 +278,10 @@ internal class BillingController(
275278 fun onExternalRouteSet (navigationRoute : NavigationRoute ) {
276279 val runningSessionSkuId = getRunningOrPausedSessionSkuId()
277280 if (runningSessionSkuId == SessionSKUIdentifier .NAV2_SES_TRIP ) {
278- val currentRemainingWaypoints = getRemainingWaypointsOnRoute (
281+ val currentRemainingWaypoints = getRemainingNonEVWaypointsOnRoute (
279282 tripSession.getRouteProgress()
280283 )
281- val newWaypoints = getWaypointsOnRoute (navigationRoute)
284+ val newWaypoints = getNonEVWaypointsOnRoute (navigationRoute) { 1 }
282285
283286 if (! waypointsWithinRange(currentRemainingWaypoints, newWaypoints)) {
284287 val wasSessionPaused = billingService.getSessionStatus(
@@ -381,32 +384,33 @@ internal class BillingController(
381384 * Returns a list of remaining [Point]s that mark ends of legs on the route from the current [RouteProgress],
382385 * ignoring origin.
383386 */
384- private fun getRemainingWaypointsOnRoute (routeProgress : RouteProgress ? ): List <Point >? {
385- return routeProgress?.navigationRoute?.let { route ->
386- val waypoints = route.waypoints
387- waypoints?.drop(
388- (waypoints.size - routeProgress.remainingWaypoints).coerceAtLeast(1 )
389- )?.map {
390- it.location()
391- }
387+ private fun getRemainingNonEVWaypointsOnRoute (routeProgress : RouteProgress ? ): List <Point >? {
388+ if (routeProgress == null ) return null
389+ return getNonEVWaypointsOnRoute(routeProgress.navigationRoute) {
390+ (size - routeProgress.remainingWaypoints).coerceAtLeast(1 )
392391 }
393392 }
394393
395394 /* *
396- * Returns a list of [Point]s that mark ends of legs on the route,
397- * ignoring origin .
395+ * Returns a list of [Point]s that mark ends of legs on the route
396+ * and removes first n elements depending on the result of [dropCountProvider] .
398397 */
399- private fun getWaypointsOnRoute (navigationRoute : NavigationRoute ): List <Point >? {
400- return navigationRoute.waypoints?.drop(1 )?.map {
401- it.location()
402- }
398+ private fun getNonEVWaypointsOnRoute (
399+ navigationRoute : NavigationRoute ,
400+ dropCountProvider : List <Waypoint >.() -> Int
401+ ): List <Point > {
402+ val waypoints = navigationRoute.internalWaypoints()
403+ return waypoints
404+ .drop(waypoints.dropCountProvider())
405+ .filterNot { it.isEVChargingWaypoint() }
406+ .map { it.location }
403407 }
404408
405409 private fun waypointsWithinRange (
406410 first : List <Point >? ,
407411 second : List <Point >?
408412 ): Boolean {
409- if (first == null || second == null || first.size != second.size) {
413+ if (first.isNullOrEmpty() || second.isNullOrEmpty() || first.size != second.size) {
410414 return false
411415 }
412416
@@ -436,5 +440,3 @@ internal class BillingController(
436440 }
437441 }
438442}
439-
440- private data class Waypoint (val index : Int , val point : Point )
0 commit comments