-
Notifications
You must be signed in to change notification settings - Fork 319
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
Remove origin, destination, unit type and locale from nav options #965
Remove origin, destination, unit type and locale from nav options #965
Conversation
5194ce1
to
b3de512
Compare
658424f
to
71e6da2
Compare
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.
When testing this PR I found 👇
Selected route not restored after updating the settings (NavigationViewActivity
).
👀 #800 (EmbeddedNavigationActivity
).
When clicking the top banner (list of instructions displayed) the speed view is visible (EmbeddedNavigationActivity
).
In certain scenarios when a reroute occurs, noticed that the speech player changed when it shouldn't (couldn't reproduce but worth noting).
Also added some nit picks/questions.
} | ||
|
||
private Locale getLocale() { | ||
private String getUnitType() { |
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.
get/set nomenclature is hijacked by the Java language and should be only used when defining POJOs/DTOs.
} | ||
|
||
@NavigationUnitType.UnitType | ||
private int getUnitType() { | ||
private String getLanguage() { |
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.
Same here ☝️
language = localeUtils.getDeviceLanguage(this); | ||
} | ||
|
||
return language; | ||
} | ||
|
||
private boolean getShouldSimulateRoute() { |
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.
Same here ☝️
@@ -9,10 +11,20 @@ | |||
import com.mapbox.services.android.navigation.testapp.R; | |||
|
|||
public class NavigationViewSettingsActivity extends PreferenceActivity { | |||
SharedPreferences.OnSharedPreferenceChangeListener listener; |
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.
Why is this package-private?
@@ -9,10 +11,20 @@ | |||
import com.mapbox.services.android.navigation.testapp.R; | |||
|
|||
public class NavigationViewSettingsActivity extends PreferenceActivity { | |||
SharedPreferences.OnSharedPreferenceChangeListener listener; | |||
public static final String UNIT_TYPE_CHANGED = "unit_type_changed"; |
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.
Why are we exposing UNIT_TYPE_CHANGED
and LANGUAGE_CHANGED
publicly? Both could be package-private.
* @param unitType to use, or NONE_SPECIFIED to use default for locale country | ||
*/ | ||
public DistanceUtils(Context context, @NonNull Locale locale, @NavigationUnitType.UnitType int unitType) { | ||
public DistanceUtils(Context context, String language, @DirectionsCriteria.VoiceUnitCriteria String unitType) { |
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.
Why removing @NonNull
annotation? See comment above ☝️
unitStrings.put(UNIT_KILOMETERS, context.getString(R.string.kilometers)); | ||
unitStrings.put(UNIT_METERS, context.getString(R.string.meters)); | ||
unitStrings.put(UNIT_MILES, context.getString(R.string.miles)); | ||
unitStrings.put(UNIT_FEET, context.getString(R.string.feet)); | ||
|
||
|
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.
NIT unnecessary new line
|
||
import java.util.Locale; | ||
|
||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationUnitType.TYPE_IMPERIAL; | ||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationUnitType.TYPE_METRIC; | ||
|
||
public class LocaleUtils { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
public static Locale getNonNullLocale(Context context, Locale locale) { | ||
if (locale == null) { | ||
return getDeviceLocale(context); | ||
public String getNonNullLocale(Context context, String language) { |
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 rename this method, it's not returning a Locale
anymore.
private LocaleUtils localeUtils; | ||
|
||
@Before | ||
public void setup() { |
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.
In general, we should avoid inline setup 👀 https://speakerdeck.com/guardiola31337/elegant-unit-testing-mobilization-2016?slide=65
Could you extract this block of code into private "factory" methods and use them only in the tests that actually need it/across the rest of the tests?
IMO, it reflects better what's going on in the test and you don't break the triple A "rule".
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.
Some comments added in addition to @Guardiola31337's. Great work on untangling this 🍝 - in the end, this will make localization a lot more straightforward for our users.
locale = LocaleUtils.getNonNullLocale(getApplication(), options.locale()); | ||
unitType = options.unitType(); | ||
private void initLocaleInfo(NavigationUiOptions options) { | ||
language = new LocaleUtils().getNonNullLocale(getApplication(), options.directionsRoute().voiceLanguage()); |
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.
Can we also update this naming to initLanguage
or intializeLanguage
as the underlying code has changed a bit here?
private boolean shouldDistanceUtilsBeInitialized(String language, | ||
@DirectionsCriteria.VoiceUnitCriteria String unitType) { | ||
return distanceUtils == null || !this.language.equals(language) || !this.unitType.equals(unitType); | ||
|
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.
NIT - new line added
@@ -330,26 +329,26 @@ public void showInstructionList() { | |||
/** | |||
* Sets the locale to use for languages and default unit type |
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.
Comment can be updated to reflect new code
distanceUtils = new DistanceUtils(context, locale, unitType); | ||
this.locale = locale; | ||
String language, @DirectionsCriteria.VoiceUnitCriteria String unitType) { | ||
if (distanceUtils == null || !this.language.equals(language) || !this.unitType.equals(unitType)) { |
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.
Can we update this line to include the same boolean function you created in https://github.com/mapbox/mapbox-navigation-android/pull/965/files#diff-ac7c5e067e3f4755a545253204a39851R92?
setupCaches(context); | ||
instructionQueue = new ConcurrentLinkedQueue(); | ||
voiceInstructionLoader = VoiceInstructionLoader.builder() | ||
.language(locale.toString()) | ||
.language(language) |
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.
💯 I believe this was the source of some of the Locale
related voice bugs we were seeing
if (locale == null) { | ||
locale = LocaleUtils.getDeviceLocale(context); | ||
} | ||
RouteOptions routeOptions = mapboxNavigation.getRoute().routeOptions(); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
/** | ||
* Helper class to reduce redundant logging code when no other action is taken in onFailure | ||
*/ | ||
public abstract static class SimplifiedCallback implements Callback<DirectionsResponse> { |
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.
I agree with @Guardiola31337 here - our developers looks at the test app for examples of how to use NavigationRoute
and this may end up creating some confusion.
2e3c693
to
a0c1303
Compare
a0c1303
to
bc958eb
Compare
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.
Great work @devotaaabel 👍
…usion with MapboxNavigationOptions
41212e9
to
7389074
Compare
@Guardiola31337 @danesfeder do we have any instructions on now setting the locale and unit type since this has been removed from the |
@Danny-James In |
Closes #924 along with possibly some voice/locale related bugs