Skip to content

Commit 93fb66d

Browse files
committed
NAVAND-713: meet code review
1 parent f064cb0 commit 93fb66d

File tree

7 files changed

+100
-118
lines changed

7 files changed

+100
-118
lines changed

libnavigation-base/src/main/java/com/mapbox/navigation/base/internal/RouteRefreshRequestData.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import com.mapbox.api.directions.v5.models.DirectionsRoute
1010
* right in front of the user (see [DirectionsRoute.geometry]), null if unavailable.
1111
* @param legGeometryIndex leg-wise index representing the geometry point
1212
* right in front of the user (see [DirectionsRoute.geometry]), null if unavailable.
13-
* @param evData map containing EV related dynamic data.
13+
* @param experimentalProperties map containing dynamic data.
1414
*/
1515
class RouteRefreshRequestData(
1616
val legIndex: Int,
1717
val routeGeometryIndex: Int,
1818
val legGeometryIndex: Int?,
19-
val evData: Map<String, String>,
19+
val experimentalProperties: Map<String, String>,
2020
) {
2121

2222
/**
@@ -31,7 +31,7 @@ class RouteRefreshRequestData(
3131
if (legIndex != other.legIndex) return false
3232
if (routeGeometryIndex != other.routeGeometryIndex) return false
3333
if (legGeometryIndex != other.legGeometryIndex) return false
34-
if (evData != other.evData) return false
34+
if (experimentalProperties != other.experimentalProperties) return false
3535

3636
return true
3737
}
@@ -43,7 +43,7 @@ class RouteRefreshRequestData(
4343
var result = legIndex
4444
result = 31 * result + routeGeometryIndex
4545
result = 31 * result + (legGeometryIndex ?: 0)
46-
result = 31 * result + evData.hashCode()
46+
result = 31 * result + experimentalProperties.hashCode()
4747
return result
4848
}
4949

@@ -55,7 +55,7 @@ class RouteRefreshRequestData(
5555
"legIndex=$legIndex, " +
5656
"routeGeometryIndex=$routeGeometryIndex, " +
5757
"legGeometryIndex=$legGeometryIndex" +
58-
"evData=$evData" +
58+
"experimentalProperties=$experimentalProperties" +
5959
")"
6060
}
6161
}

libnavigation-base/src/main/java/com/mapbox/navigation/base/internal/route/AnnotationsRefresher.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ internal object AnnotationsRefresher {
108108
}
109109

110110
private fun List<JsonElement>.toJsonArray(): JsonArray {
111-
return JsonArray().also { array ->
111+
return JsonArray(this.size).also { array ->
112112
forEach { array.add(it) }
113113
}
114114
}

libnavigation-base/src/main/java/com/mapbox/navigation/base/internal/route/NavigationRouteEx.kt

+11-14
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fun NavigationRoute.refreshRoute(
4646
legAnnotations: List<LegAnnotation?>?,
4747
incidents: List<List<Incident>?>?,
4848
closures: List<List<Closure>?>?,
49-
unrecognizedProperties: Map<String, JsonElement>?,
49+
waypoints: List<DirectionsWaypoint?>?,
5050
): NavigationRoute {
5151
val updateLegs = directionsRoute.legs()?.mapIndexed { index, routeLeg ->
5252
if (index < initialLegIndex) {
@@ -95,19 +95,19 @@ fun NavigationRoute.refreshRoute(
9595
.build()
9696
}
9797
}
98-
return update(
99-
{
100-
toBuilder()
101-
.legs(updateLegs)
102-
.updateRouteDurationBasedOnLegsDuration(updateLegs)
103-
.build()
104-
}
105-
) {
98+
val directionsRouteBlock: DirectionsRoute.() -> DirectionsRoute = {
99+
toBuilder()
100+
.legs(updateLegs)
101+
.updateRouteDurationBasedOnLegsDuration(updateLegs)
102+
.build()
103+
}
104+
val directionsResponseBlock: DirectionsResponse.Builder.() -> DirectionsResponse.Builder = {
106105
updateWaypoints(
107106
directionsResponse.waypoints(),
108-
unrecognizedProperties
107+
waypoints
109108
)
110109
}
110+
return update(directionsRouteBlock, directionsResponseBlock)
111111
}
112112

113113
private fun adjustedIndex(offsetIndex: Int, originalIndex: Int?): Int {
@@ -198,14 +198,11 @@ private fun List<LegStep>.updateSteps(
198198

199199
private fun DirectionsResponse.Builder.updateWaypoints(
200200
oldWaypoints: List<DirectionsWaypoint>?,
201-
newUnrecognizedProperties: Map<String, JsonElement>?,
201+
updatedWaypoints: List<DirectionsWaypoint?>?,
202202
): DirectionsResponse.Builder {
203203
if (oldWaypoints == null) {
204204
return this
205205
}
206-
val updatedWaypoints = WaypointsParser.parse(
207-
newUnrecognizedProperties?.get(Constants.KEY_WAYPOINTS)
208-
)
209206
val newWaypoints = mutableListOf<DirectionsWaypoint>()
210207
if (updatedWaypoints != null) {
211208
oldWaypoints.forEachIndexed { index, oldWaypoint ->

0 commit comments

Comments
 (0)