-
Notifications
You must be signed in to change notification settings - Fork 318
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
Conversation
@@ -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()); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
43ec813
to
66972fd
Compare
} | ||
|
||
private String buildDepartureInstruction(RouteProgress progress) { | ||
if (progress.getCurrentLegProgress().getUpComingStep().getDistance() > MINIMUM_UPCOMING_STEP_DISTANCE) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
- passing to MilestoneEventListeners for possible voicing on client side
- Fix issues per Cam code review
… use upcoming step for default instruction
6b0014b
to
888da4c
Compare
private String instruction; | ||
|
||
public DefaultInstruction(RouteProgress routeProgress, int identifier) { | ||
super(routeProgress, identifier); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
@cammace ready for another round of 👀 |
- Also include check for empty step name or rounded user distance to 0 (occurring sometimes on departure)
Looks good the merge @danesfeder |
🚀 |
No description provided.