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 b28d820c7c5..526fff93d0a 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 @@ -122,7 +122,7 @@ private boolean addBannerInstructions(RouteProgress routeProgress) { List steps = currentLeg.steps(); for (LegStep step : steps) { List bannerInstructions = step.bannerInstructions(); - if (bannerInstructions != null) { + if (bannerInstructions != null && !bannerInstructions.isEmpty()) { instructions.addAll(bannerInstructions); didAddInstructions = true; } @@ -150,8 +150,8 @@ private boolean removeInstructionsFrom(int currentInstructionIndex) { if (currentInstructionIndex == FIRST_INSTRUCTION_INDEX) { instructions.remove(FIRST_INSTRUCTION_INDEX); return true; - } else if (currentInstructionIndex < instructions.size() - 1) { - instructions.subList(0, currentInstructionIndex).clear(); + } else if (currentInstructionIndex <= instructions.size()) { + instructions.subList(FIRST_INSTRUCTION_INDEX, currentInstructionIndex).clear(); return true; } return false; diff --git a/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListPresenterTest.java b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListPresenterTest.java index cae6445d73d..938db620fbf 100644 --- a/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListPresenterTest.java +++ b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/summary/list/InstructionListPresenterTest.java @@ -18,6 +18,7 @@ import java.util.List; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyDouble; @@ -107,6 +108,19 @@ public void updateBannerListWith_instructionListIsPopulated() throws Exception { assertTrue(didUpdate); } + @Test + public void updateBannerListWith_emptyInstructionsReturnFalse() throws Exception { + RouteProgress routeProgress = buildRouteProgress(); + RouteUtils routeUtils = buildRouteUtils(routeProgress); + clearInstructions(routeProgress); + DistanceFormatter distanceFormatter = mock(DistanceFormatter.class); + InstructionListPresenter presenter = new InstructionListPresenter(routeUtils, distanceFormatter); + + boolean didUpdate = presenter.updateBannerListWith(routeProgress); + + assertFalse(didUpdate); + } + @NonNull private RouteProgress buildRouteProgress() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); @@ -140,4 +154,13 @@ private int retrieveInstructionSizeFrom(RouteLeg routeLeg) { } return instructions.size() - 1; } + + private void clearInstructions(RouteProgress routeProgress) { + for (LegStep step : routeProgress.currentLeg().steps()) { + List instructions = step.bannerInstructions(); + if (instructions != null) { + instructions.clear(); + } + } + } } \ No newline at end of file