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

Abstract the location engine from a specific provider #269

Merged
merged 16 commits into from
Jan 12, 2017
Merged

Conversation

zugaldia
Copy link
Member

/cc: @cammace

@zugaldia zugaldia added this to the v2.0.0 milestone Jan 11, 2017
@zugaldia zugaldia self-assigned this Jan 11, 2017
@mention-bot
Copy link

@zugaldia, thanks for your PR! By analyzing the history of the files in this pull request, we identified @cammace to be a potential reviewer.

@zugaldia
Copy link
Member Author

zugaldia commented Jan 12, 2017

This PR is ready is for a first round of feedback.

The main goal of this PR is to create a new abstract LocationEngine that can be implemented by different location providers (open source or proprietary), and decouple it from other components so that it can be used for telemetry, user tracking (map), navigation, or mocking use-cases.

In particular, this PR includes:

  • A new PermissionsManager and PermissionsListener that replaces the old PermissionsUtils to be more flexible checking for any kind of permission, not just location, at runtime.
  • A new set of LocationEngine and LocationEngineListener interfaces that abstract a high level API for a location provider engine. Priority is set via a generic LocationEnginePriority that encapsulates common priorities in Android.
  • Sample implementations for Lost (LostLocationEngine), Google Play Services (GoogleLocationEngine) and of a Mock provider (MockLocationEngine) using a Handler to simulate GPS updates.
  • A new LocationEngineActivity in the test app that shows how to switch between providers. The test app has been updated to the latest Lost version and it now includes a Google Play Services dependency.
  • GeocodingServiceActivity and GeocodingWidgetActivity are updated to use the latest Lost version too.
  • Some tail work from Remove deprecated v4 directions #260 that was left due to a failed rebase that was breaking the app build.

Still WIP, required next actions:

  • Review of the current approach by @mapbox/android
  • Fix Javadoc

Related mapbox/mapbox-gl-native#4331.


private final int REQUEST_PERMISSIONS_CODE = 0;

private Activity activity;
Copy link

Choose a reason for hiding this comment

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

use weak references just in case?

Copy link
Member

Choose a reason for hiding this comment

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

would it be possible to remove activity completely? it's used for 2 items: permissions granted checks and requesting permissions. Imo I think callers of those method won't mind passing an reference to the Activity.

Copy link
Contributor

@cammace cammace left a comment

Choose a reason for hiding this comment

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

All looks good so far.


/**
* Created by antonio on 1/11/17.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

cough cough

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, sorry, fixed.


/**
* Created by antonio on 1/11/17.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

cough

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, too

Copy link
Member

@tobrun tobrun left a comment

Choose a reason for hiding this comment

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

Looks great, small nits added

.build();
}

public static LocationEngine getLocationEngine(Context context) {
Copy link
Member

Choose a reason for hiding this comment

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

synchronised keyword for thread safety to avoid creating 2 instances?

Copy link
Member Author

Choose a reason for hiding this comment

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

good call, done.

.build();
}

public static LocationEngine getLocationEngine(Context context) {
Copy link
Member

Choose a reason for hiding this comment

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

synchronised keyword for thread safety to avoid creating 2 instances?

Copy link
Member Author

Choose a reason for hiding this comment

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

good call, done.


public interface PermissionsListener {

void onExplanationNeeded(List<String> permissionsToExplain);
Copy link
Member

Choose a reason for hiding this comment

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

what does this method do?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let the developer know that they need to provide an explanation to the user as indicated in the docs. Basically, it covers the ActivityCompat.shouldShowRequestPermissionRationale() == true flow.

/**
* Helps request permissions at runtime
*/

Copy link
Member

Choose a reason for hiding this comment

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

nit enter

Copy link
Member Author

Choose a reason for hiding this comment

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

done.


private final int REQUEST_PERMISSIONS_CODE = 0;

private Activity activity;
Copy link
Member

Choose a reason for hiding this comment

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

would it be possible to remove activity completely? it's used for 2 items: permissions granted checks and requesting permissions. Imo I think callers of those method won't mind passing an reference to the Activity.

@zugaldia
Copy link
Member Author

@cammace All comments addressed, care to 👍 / 👎 ?

@zugaldia zugaldia merged commit 89d0ca4 into master Jan 12, 2017
@zugaldia zugaldia deleted the location-engine branch January 12, 2017 20:37
@zugaldia zugaldia changed the title [WIP] Abstract the location engine from a specific provider Abstract the location engine from a specific provider Jan 13, 2017
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