Skip to content

Commit

Permalink
[DO NOT MERGE] simplify will voice and will display apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Guardiola31337 committed Sep 11, 2018
1 parent e1ba03d commit 65e5150
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ public void onInstructionListVisibilityChanged(boolean shown) {
}

@Override
public SpeechAnnouncement willVoice(SpeechAnnouncement announcement) {
return SpeechAnnouncement.builder().announcement("All announcements will be the same.").build();
public String willVoice(SpeechAnnouncement announcement) {
return "All announcements will be the same.";
}

@Override
public BannerInstructions willDisplay(BannerInstructions instructions) {
return instructions;
public String willDisplay(BannerInstructions instructions) {
return "All banners will be the same.";
}

private void startNavigation(DirectionsRoute directionsRoute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@
import android.support.design.widget.BottomSheetBehavior.BottomSheetCallback;
import android.view.View;

import com.mapbox.api.directions.v5.models.BannerComponents;
import com.mapbox.api.directions.v5.models.BannerInstructions;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.services.android.navigation.ui.v5.feedback.FeedbackItem;
import com.mapbox.services.android.navigation.ui.v5.listeners.BannerInstructionsListener;
import com.mapbox.services.android.navigation.ui.v5.listeners.FeedbackListener;
import com.mapbox.services.android.navigation.ui.v5.listeners.InstructionListListener;
import com.mapbox.services.android.navigation.ui.v5.listeners.SpeechAnnouncementListener;
import com.mapbox.services.android.navigation.ui.v5.listeners.NavigationListener;
import com.mapbox.services.android.navigation.ui.v5.listeners.RouteListener;
import com.mapbox.services.android.navigation.ui.v5.listeners.SpeechAnnouncementListener;
import com.mapbox.services.android.navigation.ui.v5.voice.SpeechAnnouncement;
import com.mapbox.services.android.navigation.v5.milestone.MilestoneEventListener;
import com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation;
import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener;

import java.util.ArrayList;
import java.util.List;

/**
* In charge of holding any {@link NavigationView} related listeners {@link NavigationListener},
* {@link RouteListener}, or {@link FeedbackListener} and firing listener events when
* triggered by the {@link NavigationView}.
*/
class NavigationViewEventDispatcher {

private static final int ONE = 1;
private static final int FIRST = 0;
private ProgressChangeListener progressChangeListener;
private MilestoneEventListener milestoneEventListener;
private FeedbackListener feedbackListener;
Expand Down Expand Up @@ -167,14 +173,22 @@ void onInstructionListVisibilityChanged(boolean shown) {

SpeechAnnouncement onAnnouncement(SpeechAnnouncement announcement) {
if (speechAnnouncementListener != null) {
return speechAnnouncementListener.willVoice(announcement);
String textAnnouncement = speechAnnouncementListener.willVoice(announcement);
SpeechAnnouncement announcementToBeVoiced = SpeechAnnouncement.builder().announcement(textAnnouncement).build();
return announcementToBeVoiced;
}
return announcement;
}

BannerInstructions onBannerDisplay(BannerInstructions instructions) {
if (bannerInstructionsListener != null) {
return bannerInstructionsListener.willDisplay(instructions);
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 instructions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public interface BannerInstructionsListener {
* and it will be ignored.
*
* @param instructions about to be displayed
* @return instructions to be displayed; null if should be ignored
* @since 0.16.0
* @return instruction text to be displayed; null if should be ignored
* @since 0.18.0
*/
BannerInstructions willDisplay(BannerInstructions instructions);
String willDisplay(BannerInstructions instructions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public interface SpeechAnnouncementListener {
* and it will be ignored.
*
* @param announcement about to be announced
* @return announcement to be played; null if should be ignored
* @since 0.16.0
* @return text announcement to be played; null if should be ignored
* @since 0.18.0
*/
SpeechAnnouncement willVoice(SpeechAnnouncement announcement);
String willVoice(SpeechAnnouncement announcement);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.support.annotation.NonNull;

import com.mapbox.api.directions.v5.models.BannerComponents;
import com.mapbox.api.directions.v5.models.BannerInstructions;
import com.mapbox.api.directions.v5.models.BannerText;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.services.android.navigation.ui.v5.feedback.FeedbackItem;
Expand All @@ -19,8 +21,13 @@

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -362,10 +369,8 @@ public void onMilestoneEventListenerAddedInOptions_isRemovedInOnDestroy() {

@Test
public void onNewBannerInstruction_instructionListenerIsCalled() {
BannerInstructions modifiedInstructions = mock(BannerInstructions.class);
BannerInstructions originalInstructions = mock(BannerInstructions.class);
BannerInstructions originalInstructions = mock(BannerInstructions.class, RETURNS_DEEP_STUBS);
BannerInstructionsListener bannerInstructionsListener = mock(BannerInstructionsListener.class);
when(bannerInstructionsListener.willDisplay(originalInstructions)).thenReturn(modifiedInstructions);
NavigationViewEventDispatcher eventDispatcher = buildViewEventDispatcher(bannerInstructionsListener);

eventDispatcher.onBannerDisplay(originalInstructions);
Expand All @@ -375,17 +380,49 @@ public void onNewBannerInstruction_instructionListenerIsCalled() {

@Test
public void onNewVoiceAnnouncement_instructionListenerIsCalled() {
SpeechAnnouncement modifiedAnnouncement = mock(SpeechAnnouncement.class);
SpeechAnnouncement originalAnnouncement = mock(SpeechAnnouncement.class);
SpeechAnnouncementListener speechAnnouncementListener = mock(SpeechAnnouncementListener.class);
when(speechAnnouncementListener.willVoice(originalAnnouncement)).thenReturn(modifiedAnnouncement);
String textAnnouncement = "announcement to be voiced";
when(speechAnnouncementListener.willVoice(originalAnnouncement)).thenReturn(textAnnouncement);
NavigationViewEventDispatcher eventDispatcher = buildViewEventDispatcher(speechAnnouncementListener);

eventDispatcher.onAnnouncement(originalAnnouncement);

verify(speechAnnouncementListener).willVoice(originalAnnouncement);
}

@Test
public void onNewBannerInstruction_bannerToBeDisplayedIsReturned() {
List<BannerComponents> originalBannerComponents = new ArrayList<>(1);
BannerComponents originalBannerComponent = BannerComponents.builder().text("text").type("type").build();
originalBannerComponents.add(originalBannerComponent);
BannerText originalBannerText = BannerText.builder().components(originalBannerComponents).build();
BannerInstructions originalInstructions = BannerInstructions.builder().primary(originalBannerText)
.distanceAlongGeometry(25.0).build();
BannerInstructionsListener bannerInstructionsListener = mock(BannerInstructionsListener.class);
String textBanner = "banner to be displayed";
when(bannerInstructionsListener.willDisplay(originalInstructions)).thenReturn(textBanner);
NavigationViewEventDispatcher eventDispatcher = buildViewEventDispatcher(bannerInstructionsListener);

BannerInstructions 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());
}

@Test
public void onNewVoiceAnnouncement_announcementToBeVoicedIsReturned() {
SpeechAnnouncement originalAnnouncement = SpeechAnnouncement.builder().announcement("announcement").build();
SpeechAnnouncementListener speechAnnouncementListener = mock(SpeechAnnouncementListener.class);
String textAnnouncement = "announcement to be voiced";
when(speechAnnouncementListener.willVoice(originalAnnouncement)).thenReturn(textAnnouncement);
NavigationViewEventDispatcher eventDispatcher = buildViewEventDispatcher(speechAnnouncementListener);

SpeechAnnouncement modifiedAnnouncement = eventDispatcher.onAnnouncement(originalAnnouncement);

assertEquals("announcement to be voiced", modifiedAnnouncement.announcement());
}

@NonNull
private NavigationViewEventDispatcher buildViewEventDispatcher(SpeechAnnouncementListener speechAnnouncementListener) {
NavigationViewEventDispatcher eventDispatcher = new NavigationViewEventDispatcher();
Expand Down

0 comments on commit 65e5150

Please sign in to comment.