-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[android] Adding builder pattern for LocationComponent activation #13941
[android] Adding builder pattern for LocationComponent activation #13941
Conversation
8b6931e
to
6ae496d
Compare
Would love 👁👁 from @mapbox/maps-android I'm not sure the best way to handle all of the nasty logic inside of I'm definitely checking At least there are promising signs of (some) things working in the test app 👇 |
...ndroid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
Outdated
Show resolved
Hide resolved
...ndroid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
Outdated
Show resolved
Hide resolved
...ndroid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...ndroid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
Outdated
Show resolved
Hide resolved
7e2a513
to
d378b2a
Compare
Ok @tobrun and @LukasPaczos . Changes have been made based on your feedback.
|
The |
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Show resolved
Hide resolved
cd093d6
to
5f6f986
Compare
@LukasPaczos and @tobrun , refactoring based on your latest review is complete. I've also:
|
2226db8
to
36e1b80
Compare
crashes are Firebase instrumentation around |
c6a233a
to
ec83e2a
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.
The activation looks overly complicated to me, here's my proposition, let me know what you think:
/**
* This method initializes the component and needs to be called before any other operations are performed.
* Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}.
*
* @param activationOptions a fully built {@link LocationComponentActivationOptions} object
*/
public void activateLocationComponent(@NonNull LocationComponentActivationOptions
activationOptions) {
LocationComponentOptions options = activationOptions.locationComponentOptions();
if (options == null) {
int styleRes = activationOptions.styleRes();
if (styleRes == 0) {
styleRes = R.style.mapbox_LocationComponent;
}
options = LocationComponentOptions.createFromAttributes(activationOptions.context(), styleRes);
}
// Initialize the LocationComponent with Context, the map's `Style`, and either custom LocationComponentOptions
// or backup options created from default/custom attributes
initialize(activationOptions.context(), activationOptions.style(), options);
// Apply the LocationComponent styling
// TODO avoid doubling style initialization
applyStyle(options);
// Set the LocationEngine request if one was given to LocationComponentActivationOptions
LocationEngineRequest locationEngineRequest = activationOptions.locationEngineRequest();
if (locationEngineRequest != null) {
setLocationEngineRequest(locationEngineRequest);
}
// Set the LocationEngine if one was given to LocationComponentActivationOptions
LocationEngine locationEngine = activationOptions.locationEngine();
if (locationEngine != null) {
setLocationEngine(locationEngine);
} else if (activationOptions.useDefaultLocationEngine()) {
initializeLocationEngine(activationOptions.context());
} else {
setLocationEngine(null);
}
}
...ndroid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
Outdated
Show resolved
Hide resolved
...ndroid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
c41d10f
to
48d01ff
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.
Good progress @langsmith!
There are still docs missing in the Builder
class. It'd be great to add tests verifying if there's an exception thrown when the provided style is not fully loaded and if the useDefaultLocationEngine
flag is set to true by default.
All instrumentation tests are finally passing. As we discussed offline, some of the instrumentation tests were passing in null for the LocationEngine, but I didn't use .locationEngine(null) when I refactored the tests to use the builder. My most recent commit was to add .locationEngine(null) to the tests that needed it.
Adding only .locationEngine(null)
is still initializing the default engine, you'll need to add .useDefaultLocationEngine(false)
instead, otherwise, the tests might become flaky.
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Outdated
Show resolved
Hide resolved
...ndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
Outdated
Show resolved
Hide resolved
Ok @LukasPaczos , all feedback from your last review has been addressed.
21bf960#diff-14c9705b4a36f28b8485da302a5703c1
|
9009499
to
1cade17
Compare
...droidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
Show resolved
Hide resolved
...dSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptionsTest.java
Outdated
Show resolved
Hide resolved
...dSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptionsTest.java
Outdated
Show resolved
Hide resolved
...dSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptionsTest.java
Outdated
Show resolved
Hide resolved
...dSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptionsTest.java
Outdated
Show resolved
Hide resolved
...ndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
Outdated
Show resolved
Hide resolved
...ndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
Outdated
Show resolved
Hide resolved
...ndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
Outdated
Show resolved
Hide resolved
...ndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
Outdated
Show resolved
Hide resolved
...ndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
Outdated
Show resolved
Hide resolved
ea4ffb4
to
00673b6
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.
Hey, just FYI: The deprecated notices (what to use instead) are not visible when just opening the file via Android Studio. So I'm only seeing /** @deprecated */
@Deprecated
@RequiresPermission(
anyOf = {"android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"}
)
public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @StyleRes int styleRes) {
this.activateLocationComponent(context, style, LocationComponentOptions.createFromAttributes(context, styleRes));
} Not sure how this is solved. I would probably need to download the sources, right? There must be a better way! :) |
@carstenhag the javadoc with |
This pr adds a builder to activate the
LocationComponent
and resolves #13931.