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

Consume Sub BannerText in InstructionView #1408

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -238,12 +238,15 @@ public void onProgressChange(Location location, RouteProgress routeProgress) {
updateLocation(location);

// Update InstructionView data from RouteProgress
instructionView.update(routeProgress);
instructionView.updateDistanceWith(routeProgress);
}

@Override
public void onMilestoneEvent(RouteProgress routeProgress, String instruction, Milestone milestone) {
playAnnouncement(milestone);

// Update InstructionView banner instructions
instructionView.updateBannerInstructionsWith(milestone);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
package com.mapbox.services.android.navigation.ui.v5.instruction;

import android.support.annotation.Nullable;

import com.mapbox.api.directions.v5.models.BannerInstructions;
import com.mapbox.api.directions.v5.models.BannerText;
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;
import com.mapbox.services.android.navigation.v5.utils.DistanceFormatter;

public class BannerInstructionModel extends InstructionModel {

private final BannerText primaryBannerText;
private final BannerText secondaryBannerText;
private final BannerText subBannerText;

public BannerInstructionModel(DistanceFormatter distanceFormatter, RouteProgress progress,
BannerInstructions instructions) {
super(distanceFormatter, progress);
primaryBannerText = instructions.primary();
secondaryBannerText = instructions.secondary();
subBannerText = instructions.sub();
}

BannerText retrievePrimaryBannerText() {
return primaryBannerText;
}

BannerText retrieveSecondaryBannerText() {
return secondaryBannerText;
}

BannerText retrieveSubBannerText() {
return subBannerText;
}

@Override
String getManeuverType() {
String retrievePrimaryManeuverType() {
return primaryBannerText.type();
}

@Override
String getManeuverModifier() {
String retrieveSecondaryManeuverModifier() {
return primaryBannerText.modifier();
}

@Nullable
Double retrievePrimaryRoundaboutAngle() {
return primaryBannerText.degrees();
}
}
Original file line number Diff line number Diff line change
@@ -1,83 +1,81 @@
package com.mapbox.services.android.navigation.ui.v5.instruction;

import android.support.annotation.Nullable;
import android.text.SpannableString;

import com.mapbox.api.directions.v5.models.BannerText;
import com.mapbox.api.directions.v5.models.IntersectionLanes;
import com.mapbox.api.directions.v5.models.LegStep;
import com.mapbox.services.android.navigation.v5.routeprogress.RouteLegProgress;
import com.mapbox.api.directions.v5.models.StepIntersection;
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;
import com.mapbox.services.android.navigation.v5.utils.DistanceFormatter;
import com.mapbox.services.android.navigation.v5.utils.RouteUtils;

import java.util.List;

public class InstructionModel {

BannerText primaryBannerText;
BannerText secondaryBannerText;
private BannerText thenBannerText;
private Float roundaboutAngle = null;
private InstructionStepResources stepResources;
private RouteProgress progress;
private RouteUtils routeUtils;
private SpannableString stepDistanceRemaining;
private List<IntersectionLanes> turnLanes;
private String upcomingManeuverModifier;

public InstructionModel(DistanceFormatter distanceFormatter, RouteProgress progress) {
this.progress = progress;
routeUtils = new RouteUtils();
buildInstructionModel(distanceFormatter, progress);
}

BannerText getPrimaryBannerText() {
return primaryBannerText;
}

BannerText getSecondaryBannerText() {
return secondaryBannerText;
}

BannerText getThenBannerText() {
return thenBannerText;
double distanceRemaining = progress.currentLegProgress().currentStepProgress().distanceRemaining();
stepDistanceRemaining = distanceFormatter.formatDistance(distanceRemaining);
extractStepResources(progress);
}

@Nullable
Float getRoundaboutAngle() {
return roundaboutAngle;
RouteProgress retrieveProgress() {
return progress;
}

InstructionStepResources getStepResources() {
return stepResources;
SpannableString retrieveStepDistanceRemaining() {
return stepDistanceRemaining;
}

String getManeuverType() {
return stepResources.getManeuverViewType();
String retrieveUpcomingManeuverModifier() {
return upcomingManeuverModifier;
}

String getManeuverModifier() {
return stepResources.getManeuverViewModifier();
List<IntersectionLanes> retrieveTurnLanes() {
return turnLanes;
}

RouteProgress getProgress() {
return progress;
private void extractStepResources(RouteProgress progress) {
LegStep upcomingStep = progress.currentLegProgress().upComingStep();
if (upcomingStep != null) {
if (hasIntersections(upcomingStep)) {
intersectionTurnLanes(upcomingStep);
}
upcomingManeuverModifier = upcomingStep.maneuver().modifier();
}
}

private void buildInstructionModel(DistanceFormatter distanceFormatter, RouteProgress progress) {
stepResources = new InstructionStepResources(distanceFormatter, progress);
extractStepInstructions(progress);
private void intersectionTurnLanes(LegStep step) {
StepIntersection intersection = step.intersections().get(0);
List<IntersectionLanes> lanes = intersection.lanes();
if (checkForNoneIndications(lanes)) {
turnLanes = null;
return;
}
turnLanes = lanes;
}

private void extractStepInstructions(RouteProgress progress) {
RouteLegProgress legProgress = progress.currentLegProgress();
LegStep currentStep = progress.currentLegProgress().currentStep();
LegStep upComingStep = legProgress.upComingStep();
int stepDistanceRemaining = (int) legProgress.currentStepProgress().distanceRemaining();

primaryBannerText = routeUtils.findCurrentBannerText(currentStep, stepDistanceRemaining, true);
secondaryBannerText = routeUtils.findCurrentBannerText(currentStep, stepDistanceRemaining, false);

if (upComingStep != null) {
thenBannerText = routeUtils.findCurrentBannerText(upComingStep, upComingStep.distance(), true);
private boolean checkForNoneIndications(List<IntersectionLanes> lanes) {
if (lanes == null) {
return true;
}

if (primaryBannerText != null && primaryBannerText.degrees() != null) {
roundaboutAngle = primaryBannerText.degrees().floatValue();
for (IntersectionLanes lane : lanes) {
for (String indication : lane.indications()) {
if (indication.contains("none")) {
return true;
}
}
}
return false;
}

private boolean hasIntersections(LegStep step) {
return step.intersections() != null
&& step.intersections().get(0) != null;
}
}

This file was deleted.

Loading