From b5bd4549073752a76db808e4166f861bd373825e Mon Sep 17 00:00:00 2001 From: Guardiola31337 Date: Wed, 5 Sep 2018 16:06:49 +0200 Subject: [PATCH] hide turn lanes, then step and clear banner instructions when banner text is overridden --- .../ui/v5/BannerInstructionsWrapper.java | 21 +++++++++++++++++++ .../ui/v5/NavigationViewEventDispatcher.java | 6 +++--- .../navigation/ui/v5/NavigationViewModel.java | 18 ++++++++++------ .../ui/v5/instruction/InstructionModel.java | 9 ++++++++ .../ui/v5/instruction/InstructionView.java | 10 +++++++-- .../summary/list/InstructionListAdapter.java | 4 ++++ .../list/InstructionListPresenter.java | 4 ++++ .../v5/NavigationViewEventDispatcherTest.java | 6 +++--- 8 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/BannerInstructionsWrapper.java diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/BannerInstructionsWrapper.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/BannerInstructionsWrapper.java new file mode 100644 index 00000000000..2862f760e55 --- /dev/null +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/BannerInstructionsWrapper.java @@ -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; + } +} diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcher.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcher.java index 4f2f26e3217..ded467adad9 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcher.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcher.java @@ -180,7 +180,7 @@ SpeechAnnouncement onAnnouncement(SpeechAnnouncement announcement) { return announcement; } - BannerInstructions onBannerDisplay(BannerInstructions instructions) { + BannerInstructionsWrapper onBannerDisplay(BannerInstructions instructions) { if (bannerInstructionsListener != null) { String textBanner = bannerInstructionsListener.willDisplay(instructions); List bannerComponents = new ArrayList<>(ONE); @@ -188,9 +188,9 @@ BannerInstructions onBannerDisplay(BannerInstructions instructions) { .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) { diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewModel.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewModel.java index a032349edd9..567a02156b9 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewModel.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewModel.java @@ -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); @@ -157,7 +158,7 @@ public void cancelFeedback() { /** * Returns the current instance of {@link MapboxNavigation}. - * + *

* Will be null if navigation has not been initialized. */ @Nullable @@ -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); } @@ -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); @@ -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); } } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionModel.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionModel.java index 806713bb585..c1211531890 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionModel.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionModel.java @@ -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; @@ -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; } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionView.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionView.java index 859e4eceefd..a8fee91e561 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionView.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionView.java @@ -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(); @@ -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); @@ -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); diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListAdapter.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListAdapter.java index 68b4f50ac2a..c32a305b302 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListAdapter.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListAdapter.java @@ -53,4 +53,8 @@ public void updateBannerListWith(RouteProgress routeProgress, boolean isListShow public void updateDistanceFormatter(DistanceFormatter distanceFormatter) { presenter.updateDistanceFormatter(distanceFormatter); } + + public void clearBannerInstructions() { + presenter.clearBannerInstructions(); + } } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListPresenter.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListPresenter.java index 74828dc9589..525e8bbe1e3 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListPresenter.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListPresenter.java @@ -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)); diff --git a/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcherTest.java b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcherTest.java index db4ecf725b8..874317c8e78 100644 --- a/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcherTest.java +++ b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcherTest.java @@ -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