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

Added null checks in case the user isn't using voice instructions #852

Merged
merged 2 commits into from
Apr 12, 2018
Merged
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 @@ -16,18 +16,16 @@ public class VoiceInstructionMilestone extends Milestone {
private DirectionsRoute currentRoute;
private LegStep currentStep;
private List<VoiceInstructions> stepVoiceInstructions;
private final VoiceInstructionLoader voiceInstructionLoader;

VoiceInstructionMilestone(Builder builder) {
super(builder);
voiceInstructionLoader = VoiceInstructionLoader.getInstance();
}

@Override
public boolean isOccurring(RouteProgress previousRouteProgress, RouteProgress routeProgress) {
if (isNewRoute(routeProgress)) {
clearInstructionList();
voiceInstructionLoader.cacheInstructions(routeProgress, true);
cacheInstructions(routeProgress, true);
}

if (shouldAddInstructions(routeProgress)) {
Expand All @@ -36,7 +34,7 @@ public boolean isOccurring(RouteProgress previousRouteProgress, RouteProgress ro

for (VoiceInstructions voice : stepVoiceInstructions) {
if (shouldBeVoiced(routeProgress, voice)) {
voiceInstructionLoader.cacheInstructions(routeProgress, false);
cacheInstructions(routeProgress, false);
announcement = voice.announcement();
ssmlAnnouncement = voice.ssmlAnnouncement();
stepVoiceInstructions.remove(voice);
Expand Down Expand Up @@ -138,6 +136,19 @@ private boolean shouldBeVoiced(RouteProgress routeProgress, VoiceInstructions vo
>= routeProgress.currentLegProgress().currentStepProgress().distanceRemaining();
}

/**
* Caches the instructions in the VoiceInstructionLoader if it has been initialized
*
* @param routeProgress containing the instructions
* @param isFirst whether it's the first routeProgress of the route
*/
private void cacheInstructions(RouteProgress routeProgress, boolean isFirst) {
VoiceInstructionLoader voiceInstructionLoader = VoiceInstructionLoader.getInstance();
if (voiceInstructionLoader != null) {
voiceInstructionLoader.cacheInstructions(routeProgress, isFirst);
}
}

public static final class Builder extends Milestone.Builder {

private Trigger.Statement trigger;
Expand Down