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

Add example with MapboxNavigation driving separate UI components #1219

Merged
merged 3 commits into from
Aug 29, 2018

Conversation

danesfeder
Copy link
Contributor

Adds an example to the test application demonstrating MapboxNavigation setup / updating an InstructionView + NavigationMapboxMap

Currently uses default styling for map, instruction view, and route line.

ezgif com-video-to-gif

cc @nitaliano @d-prukop @bsudekum

@danesfeder danesfeder added this to the 0.18.0 milestone Aug 16, 2018
@danesfeder danesfeder self-assigned this Aug 16, 2018
@nitaliano
Copy link

nitaliano commented Aug 16, 2018

I think we should

  • Disable being able to long press while we are in a navigation mode
  • Add a floating cancel button to exit navigation

@danesfeder danesfeder force-pushed the dan-component-navigation-example branch 5 times, most recently from 3b96aef to 455c460 Compare August 20, 2018 17:58
@danesfeder
Copy link
Contributor Author

@Guardiola31337 this is also ready for review unless @nitaliano you have anything else to add here

@nitaliano
Copy link

I'm good on my end

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.

This looks great so far @danesfeder @nitaliano

I left some minor comments / questions to consider before merging this PR.

Are all the comments in ComponentNavigationActivity really necessary? Have we considered extracting blocks of code into well-named (based on the comments) private methods? This way the overall code will be easier to read/understand and comments will become superfluous so they won't be necessary. In general, we should keep public methods as clean as possible so they read like pseudocode (i.e. no conditionals, fors, etc.).

Intent intent = new Intent(view.getContext(), samples.get(position).getActivity());
startActivity(intent);
}
view.setOnClickListener(view1 -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about using a different naming here? view1 looks kind of vague to me.

MapboxMap.OnMapLongClickListener, LocationEngineListener, ProgressChangeListener,
MilestoneEventListener, OffRouteListener {

private static final String ACCESS_TOKEN = Mapbox.getAccessToken();
Copy link
Contributor

Choose a reason for hiding this comment

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

What about removing this constant and use Mapbox.getAccessToken() in the call sites?

Noting that we do that across the rest of the activities (examples) in the test app and even here 👀

private static final int FIRST = 0;
private static final int ONE_HUNDRED_MILLISECONDS = 100;
private static final int BOTTOMSHEET_PADDING_MULTIPLIER = 4;
private static final int TWO_SECONDS = 2000;
Copy link
Contributor

Choose a reason for hiding this comment

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

What about TWO_SECONDS_IN_MILLISECONDS instead?

private MapState mapState;

private enum MapState {
Info,
Copy link
Contributor

Choose a reason for hiding this comment

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

Enum type's fields are constants so they should be in capital letters.

👀 Enum Types documentation

Because they are constants, the names of an enum type's fields are in uppercase letters.


// Allow navigationMap clicks now that we have the current Location
navigationMap.retrieveMap().addOnMapLongClickListener(this);
showSnackbar("Long press the map to select a destination.", BaseTransientBottomBar.LENGTH_LONG);
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor thing - In order to increase readability, what about replacing magic numbers (literals in general including Strings) with constants with a particular meaning?
Further information: Replace Magic Number with Symbolic Constant.

locationEngine.addLocationEngineListener(this);
locationEngine.setFastestInterval(1000);
locationEngine.activate();
showSnackbar("Searching for GPS...", BaseTransientBottomBar.LENGTH_SHORT);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same ☝️

if (lastLocation == null) {
return;
}
CameraPosition cameraPosition = buildCameraPositionFrom(lastLocation, 0d);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment re: magic numbers

@NonNull
private CameraPosition buildCameraPositionFrom(Location location, double bearing) {
return new CameraPosition.Builder()
.zoom(12.0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment re: magic numbers

.zoom(12.0)
.target(new LatLng(location.getLatitude(), location.getLongitude()))
.bearing(bearing)
.tilt(0d)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same ☝️

int mapViewHeight = mapView.getHeight();
int bottomSheetHeight = (int) resources.getDimension(R.dimen.component_navigation_bottomsheet_height);
int topPadding = mapViewHeight - (bottomSheetHeight * BOTTOMSHEET_PADDING_MULTIPLIER);
navigationMap.retrieveMap().setPadding(0, topPadding, 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment re: magic numbers

@danesfeder danesfeder force-pushed the dan-component-navigation-example branch 2 times, most recently from df27cb1 to 70745a4 Compare August 28, 2018 15:51
@danesfeder
Copy link
Contributor Author

@Guardiola31337 this is updated and ready for another round of 👀

Are all the comments in ComponentNavigationActivity really necessary?

I know what you're saying with regard to the comments, but I think it's okay to be overly verbose in these test applications. As developers look to implement the SDK and see these examples, I believe they will make things a little more clear.

In general, we should keep public methods as clean as possible so they read like pseudocode (i.e. no conditionals, fors, etc.).

FWIW, in addition to the extra comments in the code, most of the public methods in this example are using extracted private methods that are explaining their purpose (or at least, I tried to name them this way).

@danesfeder danesfeder force-pushed the dan-component-navigation-example branch 2 times, most recently from ccecae0 to 836d53c Compare August 29, 2018 08:51
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.

I know what you're saying with regard to the comments, but I think it's okay to be overly verbose in these test applications. As developers look to implement the SDK and see these examples, I believe they will make things a little more clear.

Although, I agree with your point here, I also think that there are other ways to improve documentation in general (which would remove the necessity of adding this kind of comments) e.g. fine grained examples, add sample / usage code in Javadocs, be more descriptive in https://github.com/mapbox/android-docs, etc.

That being said, this is not a blocker here and we can discuss later.

FWIW, in addition to the extra comments in the code, most of the public methods in this example are using extracted private methods that are explaining their purpose (or at least, I tried to name them this way).

That's awesome 🚀

Thanks @danesfeder and @nitaliano this new example showcases perfectly how to build a more custom turn-by-turn navigation app with our UI components :shipit:

@danesfeder danesfeder force-pushed the dan-component-navigation-example branch from 836d53c to 755c44c Compare August 29, 2018 13:15
@danesfeder danesfeder merged commit ec0d9f1 into master Aug 29, 2018
@danesfeder danesfeder deleted the dan-component-navigation-example branch August 29, 2018 13:36
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.

3 participants