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

Remove origin, destination, unit type and locale from nav options #965

Merged
merged 27 commits into from
May 31, 2018

Conversation

devotaaabel
Copy link
Contributor

@devotaaabel devotaaabel commented May 23, 2018

Closes #924 along with possibly some voice/locale related bugs

@devotaaabel devotaaabel added the ⚠️ DO NOT MERGE PR should not be merged! label May 23, 2018
@devotaaabel devotaaabel added this to the 0.14.0 milestone May 23, 2018
@devotaaabel devotaaabel self-assigned this May 23, 2018
@devotaaabel devotaaabel changed the title Devota remove origin, destination, unit type and locale from nav options Remove origin, destination, unit type and locale from nav options May 23, 2018
@devotaaabel devotaaabel force-pushed the devota-remove-origin-destination-from-nav-options branch from 5194ce1 to b3de512 Compare May 25, 2018 17:48
@devotaaabel devotaaabel removed the ⚠️ DO NOT MERGE PR should not be merged! label May 25, 2018
@danesfeder danesfeder force-pushed the devota-remove-origin-destination-from-nav-options branch from 658424f to 71e6da2 Compare May 25, 2018 19:47
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a 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

Selected route not restored after updating the settings (NavigationViewActivity).

flash_off_route

👀 #800 (EmbeddedNavigationActivity).

speed_view_on_top_off_instructions

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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;
Copy link
Contributor

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";
Copy link
Contributor

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) {
Copy link
Contributor

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));


Copy link
Contributor

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.

public static Locale getNonNullLocale(Context context, Locale locale) {
if (locale == null) {
return getDeviceLocale(context);
public String getNonNullLocale(Context context, String language) {
Copy link
Contributor

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() {
Copy link
Contributor

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".

Copy link
Contributor

@danesfeder danesfeder left a 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());
Copy link
Contributor

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);

Copy link
Contributor

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
Copy link
Contributor

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)) {
Copy link
Contributor

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)
Copy link
Contributor

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.

/**
* Helper class to reduce redundant logging code when no other action is taken in onFailure
*/
public abstract static class SimplifiedCallback implements Callback<DirectionsResponse> {
Copy link
Contributor

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.

@devotaaabel devotaaabel force-pushed the devota-remove-origin-destination-from-nav-options branch 2 times, most recently from 2e3c693 to a0c1303 Compare May 29, 2018 20:37
@devotaaabel devotaaabel force-pushed the devota-remove-origin-destination-from-nav-options branch from a0c1303 to bc958eb Compare May 30, 2018 18:06
Copy link
Contributor

@danesfeder danesfeder left a comment

Choose a reason for hiding this comment

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

Great work @devotaaabel 👍 :shipit:

@devotaaabel devotaaabel force-pushed the devota-remove-origin-destination-from-nav-options branch from 41212e9 to 7389074 Compare May 31, 2018 14:26
@devotaaabel devotaaabel merged commit 7a3a704 into master May 31, 2018
@devotaaabel devotaaabel deleted the devota-remove-origin-destination-from-nav-options branch May 31, 2018 14:56
@danesfeder danesfeder mentioned this pull request May 31, 2018
13 tasks
@Danny-James
Copy link

@Guardiola31337 @danesfeder do we have any instructions on now setting the locale and unit type since this has been removed from the NavigationOptions?

@danesfeder
Copy link
Contributor

danesfeder commented Jun 18, 2018

@Danny-James In 0.14.0 this is now done at the Directions API level, please consult the release notes for further detail there > https://github.com/mapbox/mapbox-navigation-android/releases/tag/v0.14.0

@danesfeder danesfeder mentioned this pull request Jun 21, 2018
11 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.

4 participants