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

Default Text Instructions #98

Merged
merged 10 commits into from
Jun 28, 2017
Merged

Default Text Instructions #98

merged 10 commits into from
Jun 28, 2017

Conversation

cammace
Copy link

@cammace cammace commented Jun 27, 2017

No description provided.

@cammace cammace added enhancement ⚠️ DO NOT MERGE PR should not be merged! labels Jun 27, 2017
@cammace cammace added this to the v0.4.0 milestone Jun 27, 2017
@@ -94,7 +93,9 @@ void onLocationChanged(DirectionsRoute directionsRoute, Location location) {
for (Milestone milestone : milestones) {
if (milestone.isOccurring(previousRouteProgress, routeProgress)) {
for (MilestoneEventListener listener : milestoneEventListeners) {
listener.onMilestoneEvent(routeProgress, INSTRUCTION_STRING, milestone.getIdentifier());
// Create a new DefaultInstruction based on the current RouteProgress and Milestone identifier
DefaultInstruction instruction = new DefaultInstruction(routeProgress, milestone.getIdentifier());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the generic Instruction class like so: Instruction instruction = new DefaultInstruction(. This way in the future, if a dev wants to implement their own instruction engine, they can (though we currently don't offer a way to pass in custom implementations)

@@ -0,0 +1,97 @@
package com.mapbox.services.android.navigation.v5.instruction;

public class LengthUnit {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire class can be removed in favor of TurfHelpers.convertDistance() added in this PR: mapbox/mapbox-java#481

}

private String buildDepartureInstruction(RouteProgress progress) {
if (progress.getCurrentLegProgress().getUpComingStep().getDistance() > MINIMUM_UPCOMING_STEP_DISTANCE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cammace can you check my logic here? I had interpreted it as

if the next step > 15 meters, announce normally, if < 15 meters, use the combo announcement

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep looks good.

private static final String IN_STRING_FORMAT = "In %s %s";
private static final String THEN_STRING_FORMAT = "%s then %s";
private static final String THEN_IN_STRING_FORMAT = "%s then in %s %s";
private static final String CONTINUE_STRING_FORMAT = "Continue on %s for %s";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these strings should go into the string.xml file so we can handle translations.

}

private String buildArrivalInstruction(RouteProgress progress) {
String instruction = progress.getCurrentLegProgress().getUpComingStep().getManeuver().getInstruction();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getUpComingStep needs to be checked if null since there's a chance it could be.

@danesfeder danesfeder changed the title text instructions Default Text Instructions Jun 27, 2017
private String instruction;

public DefaultInstruction(RouteProgress routeProgress, int identifier) {
super(routeProgress, identifier);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove abstract constructor and super()

}

private String createInstruction(RouteProgress routeProgress, int identifier) {
if (defaultInstructionEngine.get(identifier) != null) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this null checks to make sure the identifier matches one of the keys inside defaultInstructionEngine correct? Line comment would be nice explaining this

import java.text.DecimalFormat;
import java.util.Locale;

class DefaultInstructionEngine extends SparseArray<DefaultInstructionEngine.InstructionBuilder> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have a set number of key-value pairs, should we define the sparse array size or is this not possible? See the SparseArray constructor.

initDefaultBuilders();
}

private void initDefaultBuilders() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ticket out and work in a different branch how we could expose a way for developers to add their own instructions specific to their custom milestone. My understanding is right now if the user wants to add an instruction they'd need to implement their own instructionEngine or handle the string building inside MilestoneEvent callback.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cammace yeah, that's correct - I'll create a ticket


/**
* Creates a {@link String} with the current step name and distance remaining
* Example: "Continue on Main St. for 3.2 miles"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should look into better handling the distance values, we might want to further round 3.2 miles to 3 miles since the driver most likely won't be able to distinguish the 0.2-mile difference. No need to fix in this PR but opening a ticket might be a good idea.


import com.mapbox.services.android.navigation.v5.RouteProgress;

public abstract class Instruction {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc using @since 0.4.0 tag

Instruction(RouteProgress routeProgress, int identifier) {
}

public abstract String getInstruction();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc using @since 0.4.0 tag

import java.text.DecimalFormat;
import java.util.Locale;

class DefaultInstructionEngine extends SparseArray<DefaultInstructionEngine.InstructionBuilder> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the class is only visible inside the package, it might be good to add some basic Javadoc here including the @since 0.4.0 tag.


import com.mapbox.services.android.navigation.v5.RouteProgress;

public class DefaultInstruction extends Instruction {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc using @since 0.4.0 tag

private DefaultInstructionEngine defaultInstructionEngine;
private String instruction;

public DefaultInstruction(RouteProgress routeProgress, int identifier) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc using @since 0.4.0 tag

@danesfeder
Copy link
Contributor

@cammace ready for another round of 👀

- Also include check for empty step name or rounded user distance to 0 (occurring sometimes on departure)
@cammace cammace added ready for review and removed ⚠️ DO NOT MERGE PR should not be merged! labels Jun 28, 2017
@cammace
Copy link
Author

cammace commented Jun 28, 2017

Looks good the merge @danesfeder

@danesfeder danesfeder merged commit 45cda51 into master Jun 28, 2017
@danesfeder danesfeder deleted the text-instructions branch June 28, 2017 16:41
@danesfeder
Copy link
Contributor

🚀

@cammace cammace mentioned this pull request Aug 1, 2017
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants