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

Use BannerText roundabout degrees + Banner and Voice Milestone Tests #854

Merged
merged 8 commits into from
Apr 19, 2018
Merged
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ navigation-fixtures:

# Distance Congestion annotation: Mapbox DC to National Mall
curl "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/-77.034042,38.899949;-77.03949,38.888871?geometries=polyline6&overview=full&steps=true&annotations=congestion%2Cdistance&access_token=$(MAPBOX_ACCESS_TOKEN)" \
-o libandroid-navigation/src/test/resources/directions_distance_congestion_annotation.json
-o libandroid-navigation/src/test/resources/directions_distance_congestion_annotation.json

# Default Directions
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-122.416686,37.783425;-121.90034,37.333317?geometries=polyline6&steps=true&banner_instructions=true&voice_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
-o libandroid-navigation/src/test/resources/directions_v5_precision_6.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package com.mapbox.services.android.navigation.ui.v5.instruction;

import android.content.Context;
import android.support.annotation.Nullable;

import com.mapbox.api.directions.v5.models.BannerInstructions;
import com.mapbox.api.directions.v5.models.BannerText;
import com.mapbox.api.directions.v5.models.LegStep;
import com.mapbox.services.android.navigation.v5.navigation.NavigationUnitType;
import com.mapbox.services.android.navigation.v5.routeprogress.RouteLegProgress;
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;

import java.util.List;
import java.util.Locale;

import static com.mapbox.services.android.navigation.v5.utils.RouteUtils.findCurrentBannerText;

public class InstructionModel {

private BannerText primaryBannerText;
private BannerText secondaryBannerText;
private BannerText thenBannerText;
private Float roundaboutAngle = null;
private InstructionStepResources stepResources;
private RouteProgress progress;
private Locale locale;
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor thing annotations normally are on top of the definition like 👇

@NavigationUnitType.UnitType
private int unitType;

👇

private @NavigationUnitType.UnitType int unitType;
@NavigationUnitType.UnitType
private int unitType;

public InstructionModel(Context context, RouteProgress progress,
Locale locale, @NavigationUnitType.UnitType int unitType) {
Expand All @@ -40,6 +45,11 @@ BannerText getThenBannerText() {
return thenBannerText;
}

@Nullable
Float getRoundaboutAngle() {
return roundaboutAngle;
}

InstructionStepResources getStepResources() {
return stepResources;
}
Expand All @@ -54,42 +64,20 @@ private void buildInstructionModel(Context context, RouteProgress progress) {
}

private void extractStepInstructions(RouteProgress progress) {
primaryBannerText = retrievePrimaryInstructionText(progress);
secondaryBannerText = retrieveSecondaryInstructionText(progress);
thenBannerText = retrieveThenInstructionText(progress);
}
RouteLegProgress legProgress = progress.currentLegProgress();
LegStep currentStep = progress.currentLegProgress().currentStep();
LegStep upComingStep = legProgress.upComingStep();
int stepDistanceRemaining = (int) legProgress.currentStepProgress().distanceRemaining();

private BannerText retrievePrimaryInstructionText(RouteProgress progress) {
List<BannerInstructions> bannerInstructions = progress.currentLegProgress().currentStep().bannerInstructions();
if (hasInstructions(bannerInstructions)) {
return bannerInstructions.get(0).primary();
} else {
return null;
}
}
primaryBannerText = findCurrentBannerText(currentStep, stepDistanceRemaining, true);
secondaryBannerText = findCurrentBannerText(currentStep, stepDistanceRemaining, false);

private BannerText retrieveSecondaryInstructionText(RouteProgress progress) {
List<BannerInstructions> bannerInstructions = progress.currentLegProgress().currentStep().bannerInstructions();
if (hasInstructions(bannerInstructions)) {
return bannerInstructions.get(0).secondary();
} else {
return null;
if (upComingStep != null) {
thenBannerText = findCurrentBannerText(upComingStep, upComingStep.distance(), true);
}
}

private BannerText retrieveThenInstructionText(RouteProgress progress) {
if (progress.currentLegProgress().upComingStep() != null) {
List<BannerInstructions> bannerInstructions = progress.currentLegProgress().upComingStep().bannerInstructions();
if (hasInstructions(bannerInstructions)) {
return bannerInstructions.get(0).primary();
} else {
return null;
}
if (primaryBannerText != null && primaryBannerText.degrees() != null) {
roundaboutAngle = primaryBannerText.degrees().floatValue();
}
return null;
}

private boolean hasInstructions(List<BannerInstructions> bannerInstructions) {
return bannerInstructions != null && !bannerInstructions.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public void subscribe(NavigationViewModel navigationViewModel) {
public void onChanged(@Nullable InstructionModel model) {
if (model != null) {
updateViews(model);
updateTextInstruction(model);
}
}
});
Expand Down Expand Up @@ -212,8 +213,7 @@ public void onChanged(@Nullable Boolean isOffRoute) {
@SuppressWarnings("UnusedDeclaration")
public void update(RouteProgress routeProgress) {
if (routeProgress != null && !isRerouting) {
InstructionModel model =
new InstructionModel(getContext(), routeProgress, locale, unitType);
InstructionModel model = new InstructionModel(getContext(), routeProgress, locale, unitType);
updateViews(model);
updateTextInstruction(model);
}
Expand Down Expand Up @@ -608,8 +608,12 @@ public void onClick(View instructionLayoutText) {
* @param model provides maneuver modifier / type
*/
private void updateManeuverView(InstructionModel model) {
upcomingManeuverView.setManeuverModifier(model.getStepResources().getManeuverViewModifier());
upcomingManeuverView.setManeuverType(model.getStepResources().getManeuverViewType());
String maneuverViewType = model.getStepResources().getManeuverViewType();
String maneuverViewModifier = model.getStepResources().getManeuverViewModifier();
upcomingManeuverView.setManeuverTypeAndModifier(maneuverViewType, maneuverViewModifier);
if (model.getRoundaboutAngle() != null) {
upcomingManeuverView.setRoundaboutAngle(model.getRoundaboutAngle());
}
}

/**
Expand Down Expand Up @@ -739,8 +743,9 @@ private void hideTurnLanes() {
*/
private void updateThenStep(InstructionModel model) {
if (shouldShowThenStep(model)) {
thenManeuverView.setManeuverType(model.getStepResources().getThenStepManeuverType());
thenManeuverView.setManeuverModifier(model.getStepResources().getThenStepManeuverModifier());
String thenStepManeuverType = model.getStepResources().getThenStepManeuverType();
String thenStepManeuverModifier = model.getStepResources().getThenStepManeuverModifier();
thenManeuverView.setManeuverTypeAndModifier(thenStepManeuverType, thenStepManeuverModifier);
thenStepText.setText(model.getThenBannerText().text());
showThenStepLayout();
} else {
Expand Down
Loading