Skip to content

Commit

Permalink
hide turn lanes, then step and clear banner instructions when banner …
Browse files Browse the repository at this point in the history
…text is overridden
  • Loading branch information
Guardiola31337 committed Sep 11, 2018
1 parent 65e5150 commit b5bd454
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mapbox.services.android.navigation.ui.v5;

import com.mapbox.api.directions.v5.models.BannerInstructions;

class BannerInstructionsWrapper {
private final BannerInstructions bannerInstructions;
private final boolean isBannerTextOverridden;

BannerInstructionsWrapper(BannerInstructions bannerInstructions, boolean isBannerTextOverridden) {
this.bannerInstructions = bannerInstructions;
this.isBannerTextOverridden = isBannerTextOverridden;
}

public BannerInstructions getBannerInstructions() {
return bannerInstructions;
}

public boolean isBannerTextOverridden() {
return isBannerTextOverridden;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ SpeechAnnouncement onAnnouncement(SpeechAnnouncement announcement) {
return announcement;
}

BannerInstructions onBannerDisplay(BannerInstructions instructions) {
BannerInstructionsWrapper onBannerDisplay(BannerInstructions instructions) {
if (bannerInstructionsListener != null) {
String textBanner = bannerInstructionsListener.willDisplay(instructions);
List<BannerComponents> bannerComponents = new ArrayList<>(ONE);
bannerComponents.add(instructions.primary().components().get(FIRST).toBuilder().text(textBanner)
.abbreviation(textBanner).build());
BannerInstructions bannerToBeDisplayed = instructions.toBuilder().primary(instructions.primary().toBuilder()
.components(bannerComponents).build()).build();
return bannerToBeDisplayed;
return new BannerInstructionsWrapper(bannerToBeDisplayed, true);
}
return instructions;
return new BannerInstructionsWrapper(instructions, false);
}

private void assignProgressChangeListener(NavigationViewOptions navigationViewOptions, MapboxNavigation navigation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class NavigationViewModel extends AndroidViewModel {
private RouteUtils routeUtils;
private LocaleUtils localeUtils;
private String accessToken;
private boolean isBannerTextOverridden;

public NavigationViewModel(Application application) {
super(application);
Expand Down Expand Up @@ -157,7 +158,7 @@ public void cancelFeedback() {

/**
* Returns the current instance of {@link MapboxNavigation}.
*
* <p>
* Will be null if navigation has not been initialized.
*/
@Nullable
Expand Down Expand Up @@ -279,7 +280,9 @@ private void addMilestones(NavigationViewOptions options) {
@Override
public void onProgressChange(Location location, RouteProgress routeProgress) {
NavigationViewModel.this.routeProgress = routeProgress;
instructionModel.setValue(new InstructionModel(getApplication(), routeProgress, language, unitType));
InstructionModel instruction = new InstructionModel(getApplication(), routeProgress, language, unitType);
instruction.setBannerTextOverridden(isBannerTextOverridden);
instructionModel.setValue(instruction);
summaryModel.setValue(new SummaryModel(getApplication(), routeProgress, language, unitType, timeFormatType));
navigationLocation.setValue(location);
}
Expand Down Expand Up @@ -403,7 +406,7 @@ private void playVoiceAnnouncement(Milestone milestone) {
private void updateBannerInstruction(RouteProgress routeProgress, Milestone milestone) {
if (milestone instanceof BannerInstructionMilestone) {
BannerInstructions instructions = ((BannerInstructionMilestone) milestone).getBannerInstructions();
instructions = retrieveInstructionsFromBannerEvent(instructions);
instructions = retrieveInstructionsFromBannerEvent(instructions).getBannerInstructions();
if (instructions != null) {
BannerInstructionModel model = new BannerInstructionModel(getApplication(), instructions,
routeProgress, language, unitType);
Expand Down Expand Up @@ -471,10 +474,13 @@ private SpeechAnnouncement retrieveAnnouncementFromSpeechEvent(SpeechAnnouncemen
return announcement;
}

private BannerInstructions retrieveInstructionsFromBannerEvent(BannerInstructions instructions) {
private BannerInstructionsWrapper retrieveInstructionsFromBannerEvent(BannerInstructions instructions) {
if (navigationViewEventDispatcher != null) {
instructions = navigationViewEventDispatcher.onBannerDisplay(instructions);
BannerInstructionsWrapper wrapper = navigationViewEventDispatcher.onBannerDisplay(instructions);
isBannerTextOverridden = wrapper.isBannerTextOverridden();
return wrapper;
}
return instructions;
isBannerTextOverridden = false;
return new BannerInstructionsWrapper(instructions, isBannerTextOverridden);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class InstructionModel {
private RouteUtils routeUtils;
private String language;
private String unitType;
private boolean isBannerTextOverridden;

public InstructionModel(Context context, RouteProgress progress, String language, String unitType) {
this.progress = progress;
Expand All @@ -29,6 +30,14 @@ public InstructionModel(Context context, RouteProgress progress, String language
buildInstructionModel(context, progress);
}

public boolean isBannerTextOverridden() {
return isBannerTextOverridden;
}

public void setBannerTextOverridden(boolean bannerTextOverridden) {
isBannerTextOverridden = bannerTextOverridden;
}

BannerText getPrimaryBannerText() {
return primaryBannerText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ private void updateTurnLanes(InstructionModel model) {
String maneuverViewModifier = model.getManeuverModifier();
double durationRemaining = model.getProgress().currentLegProgress().currentStepProgress().durationRemaining();

if (shouldShowTurnLanes(turnLanes, maneuverViewModifier, durationRemaining)) {
boolean isBannerTextOverridden = model.isBannerTextOverridden();
if (!isBannerTextOverridden && shouldShowTurnLanes(turnLanes, maneuverViewModifier, durationRemaining)) {
if (turnLaneLayout.getVisibility() == GONE) {
turnLaneAdapter.addTurnLanes(turnLanes, maneuverViewModifier);
showTurnLanes();
Expand Down Expand Up @@ -759,7 +760,8 @@ private void hideTurnLanes() {
* @param model to determine if the then step layout should be shown
*/
private void updateThenStep(InstructionModel model) {
if (shouldShowThenStep(model)) {
boolean isBannerTextOverridden = model.isBannerTextOverridden();
if (!isBannerTextOverridden && shouldShowThenStep(model)) {
String thenStepManeuverType = model.getStepResources().getThenStepManeuverType();
String thenStepManeuverModifier = model.getStepResources().getThenStepManeuverModifier();
thenManeuverView.setManeuverTypeAndModifier(thenStepManeuverType, thenStepManeuverModifier);
Expand Down Expand Up @@ -932,6 +934,10 @@ private void updateLandscapeConstraintsTo(int layoutRes) {
* @param model to provide the current steps and unit type
*/
private void updateInstructionList(InstructionModel model) {
boolean isBannerTextOverridden = model.isBannerTextOverridden();
if (isBannerTextOverridden) {
instructionListAdapter.clearBannerInstructions();
}
RouteProgress routeProgress = model.getProgress();
boolean isListShowing = instructionListLayout.getVisibility() == VISIBLE;
instructionListAdapter.updateBannerListWith(routeProgress, isListShowing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ public void updateBannerListWith(RouteProgress routeProgress, boolean isListShow
public void updateDistanceFormatter(DistanceFormatter distanceFormatter) {
presenter.updateDistanceFormatter(distanceFormatter);
}

public void clearBannerInstructions() {
presenter.clearBannerInstructions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ void updateDistanceFormatter(DistanceFormatter distanceFormatter) {
}
}

void clearBannerInstructions() {
instructions.clear();
}

private boolean shouldUpdate(DistanceFormatter distanceFormatter) {
return distanceFormatter != null
&& (this.distanceFormatter == null || !this.distanceFormatter.equals(distanceFormatter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ public void onNewBannerInstruction_bannerToBeDisplayedIsReturned() {
when(bannerInstructionsListener.willDisplay(originalInstructions)).thenReturn(textBanner);
NavigationViewEventDispatcher eventDispatcher = buildViewEventDispatcher(bannerInstructionsListener);

BannerInstructions modifiedInstruction = eventDispatcher.onBannerDisplay(originalInstructions);
BannerInstructionsWrapper modifiedInstruction = eventDispatcher.onBannerDisplay(originalInstructions);

assertEquals("banner to be displayed", modifiedInstruction.primary().components().get(0).text());
assertEquals("banner to be displayed", modifiedInstruction.primary().components().get(0).abbreviation());
assertEquals("banner to be displayed", modifiedInstruction.getBannerInstructions().primary().components().get(0).text());
assertEquals("banner to be displayed", modifiedInstruction.getBannerInstructions().primary().components().get(0).abbreviation());
}

@Test
Expand Down

0 comments on commit b5bd454

Please sign in to comment.