Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectionsProfile for reroutes in NavigationView #575

Merged
merged 2 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.support.annotation.Nullable;

import com.google.auto.value.AutoValue;
import com.mapbox.api.directions.v5.DirectionsCriteria;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.services.android.navigation.v5.navigation.NavigationUnitType;
Expand All @@ -13,6 +14,9 @@ public abstract class NavigationViewOptions {
@Nullable
public abstract DirectionsRoute directionsRoute();

@Nullable
public abstract String directionsProfile();

@Nullable
public abstract Point origin();

Expand All @@ -31,6 +35,8 @@ public abstract static class Builder {

public abstract Builder directionsRoute(DirectionsRoute directionsRoute);

public abstract Builder directionsProfile(@DirectionsCriteria.ProfileCriteria String directionsProfile);

public abstract Builder origin(Point origin);

public abstract Builder destination(Point destination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class RouteViewModel extends AndroidViewModel implements Callback<Directi
private Point origin;
private Location rawLocation;
private boolean extractLaunchData = true;
private String routeProfile;
private String unitType;

public RouteViewModel(@NonNull Application application) {
Expand Down Expand Up @@ -71,7 +72,7 @@ public void updateRawLocation(@NonNull Location rawLocation) {
/**
* Checks the options used to launch this {@link com.mapbox.services.android.navigation.ui.v5.NavigationView}.
* <p>
* Will launch with either a {@link DirectionsRoute} or pair of {@link Point}s
* Will launch with either a {@link DirectionsRoute} or pair of {@link Point}s.
*
* @param options holds either a set of {@link Point} coordinates or a {@link DirectionsRoute}
*/
Expand Down Expand Up @@ -127,6 +128,7 @@ private void fetchRoute(Point origin, Point destination) {
.accessToken(Mapbox.getAccessToken())
.origin(origin, bearing, 90d)
.voiceUnits(unitType)
.profile(routeProfile)
.destination(destination).build().getRoute(this);
}
}
Expand Down Expand Up @@ -157,6 +159,8 @@ private boolean launchWithRoute(NavigationViewOptions options) {
private void extractRoute(NavigationViewOptions options) {
DirectionsRoute route = options.directionsRoute();
if (route != null) {
String profile = options.directionsProfile();
routeProfile = profile != null ? profile : route.routeOptions().profile();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several checks are already in place to ensure this is never null including the MAS Directions builder and the server response itself. I've opened mapbox/mapbox-java#683 to change the annotation for this to a NonNull

Copy link
Contributor Author

@danesfeder danesfeder Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cammace awesome, thanks for the heads up on this. The options.directionsProfile() is actually the nullable profile from the NavigationViewOptions. If it's null, we fall back to the RouteOptions profile used from the original DirectionsRoute passed in at initialization of the drop-in UI.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, it is posible to pass Locale when reroute? seems to be the answer for issue #633

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darkwizzard PR is waiting for review #635

RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
LegStep lastStep = lastLeg.steps().get(lastLeg.steps().size() - 1);
destination.setValue(lastStep.maneuver().location());
Expand All @@ -173,6 +177,8 @@ private void extractRoute(NavigationViewOptions options) {
*/
private void extractCoordinates(NavigationViewOptions options) {
if (options.origin() != null && options.destination() != null) {
String profile = options.directionsProfile();
routeProfile = profile != null ? profile : DirectionsCriteria.PROFILE_DRIVING_TRAFFIC;
origin = options.origin();
destination.setValue(options.destination());
fetchRouteFromCoordinates();
Expand Down