-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed route index, UUID, and RouteOptions assignment across types
- Loading branch information
1 parent
90125a3
commit 33f7013
Showing
7 changed files
with
242 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 8 additions & 30 deletions
38
...ices-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsResponseFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,30 @@ | ||
package com.mapbox.api.directions.v5; | ||
|
||
import androidx.annotation.NonNull; | ||
import com.mapbox.api.directions.v5.models.DirectionsResponse; | ||
import com.mapbox.api.directions.v5.models.DirectionsRoute; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.mapbox.api.directions.v5.models.RouteOptions; | ||
import retrofit2.Response; | ||
|
||
class DirectionsResponseFactory { | ||
|
||
private final MapboxDirections mapboxDirections; | ||
|
||
DirectionsResponseFactory(MapboxDirections mapboxDirections) { | ||
this.mapboxDirections = mapboxDirections; | ||
} | ||
|
||
Response<DirectionsResponse> generate(Response<DirectionsResponse> response) { | ||
static Response<DirectionsResponse> generate( | ||
@NonNull RouteOptions routeOptions, | ||
Response<DirectionsResponse> response | ||
) { | ||
if (isNotSuccessful(response)) { | ||
return response; | ||
} else { | ||
return Response.success( | ||
response | ||
.body() | ||
.toBuilder() | ||
.routes(updateRoutesWithRequestData(response)) | ||
.build(), | ||
.updateWithRequestData(routeOptions), | ||
response.raw() | ||
); | ||
} | ||
} | ||
|
||
private boolean isNotSuccessful(Response<DirectionsResponse> response) { | ||
private static boolean isNotSuccessful(Response<DirectionsResponse> response) { | ||
return !response.isSuccessful() | ||
|| response.body() == null; | ||
} | ||
|
||
private List<DirectionsRoute> updateRoutesWithRequestData(Response<DirectionsResponse> response) { | ||
List<DirectionsRoute> routes = response.body().routes(); | ||
List<DirectionsRoute> modifiedRoutes = new ArrayList<>(); | ||
for (DirectionsRoute route : routes) { | ||
modifiedRoutes.add( | ||
route.toBuilder() | ||
.routeOptions(mapboxDirections.routeOptions()) | ||
.requestUuid(response.body().uuid()) | ||
.build() | ||
); | ||
} | ||
return modifiedRoutes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.