Skip to content

Conversation

@Ph0tonic
Copy link
Contributor

@Ph0tonic Ph0tonic commented May 6, 2020

This is a proposal for fixing #863 and #883.

They are kind of linked together and I foud the solution of the second one during my work so I added it in this PR.

I know that it's not perfect but at least is a simple solution which allow multiple manager to be draggable.

@LukasPaczos and @langsmith I would be happy to have your feedback. 👍

@LukasPaczos
Copy link
Contributor

Hey @Ph0tonic, thanks for your contribution again!

Unfortunately, I don't think this is an approach that we'd like to take. Having multiple detectors running is going to get inefficient.

To resolve the issue, I'd rather explore the option of having one, public instance of the draggable controller into which we can inject multiple annotation managers, instead of each annotation manager creating its own draggable controller.

@Ph0tonic
Copy link
Contributor Author

Ph0tonic commented May 7, 2020

Ok, I see, I will try to turn draggable controller into a singleton such has to minimize the number of detectors.

@Ph0tonic
Copy link
Contributor Author

Ph0tonic commented May 7, 2020

@LukasPaczos Here is a completely new implementation which turns DraggableController into a singleton. Would this be closer to an approach you would take ?

The tests are failing because I'm not able to run make generate-annotation-code locally.

@Ph0tonic Ph0tonic force-pushed the p0-annotation-plugin-draggable-manager branch from c60d6d3 to 84e258d Compare May 7, 2020 13:02
@Ph0tonic
Copy link
Contributor Author

Ph0tonic commented May 8, 2020

I had a look at the make generate-annotation-code and the underlying scripts and I think that some of the .ejs needs to be updated but as those are annotated with:

// This file is generated.

I let those like they currently are. Please let me know if I can do anything else @langsmith and @LukasPaczos. Thanks

@Ph0tonic
Copy link
Contributor Author

Ph0tonic commented May 15, 2020

The limitations resolved by this PR would really help me for one of my side project. If we find a viable solution, do you think we might be able to do a release for those next weeks ?
@LukasPaczos and @langsmith Thank you very much for your time.

@kikothemaster
Copy link

When can we expect this fix in production?

@Ph0tonic
Copy link
Contributor Author

Any updates about this PR ? @LukasPaczos and @langsmith

Ph0tonic added a commit to Ph0tonic/mapbox-plugins-android that referenced this pull request Jul 18, 2020
I wrote a seperate PR for this issue such as to simplify the review of mapbox#1125.
- Fixes mapbox#883

Any review and comment would be much appreciated 👍 @LukasPaczos and @langsmith.
Copy link
Contributor

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

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

Sorry for a delayed response, this looks great @Ph0tonic!

Would you also be able to add one test to the DraggableAnnotationControllerTest that runs multiple managers at once? When this and the last comment below is addressed I can rerun the code generation for you to make the CI pass.

Comment on lines 26 to 31
public static synchronized DraggableAnnotationController getInstance(MapView mapView, MapboxMap mapboxMap) {
if(INSTANCE == null){
INSTANCE = new DraggableAnnotationController(mapView, mapboxMap);
}
return INSTANCE;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

An issue with this singleton approach might occur when the map is recreated, for example in a recycler view, or when transitioning between fragments/activites.

We might need to do something like this, to additionally ensure that we're using the correct instance:

Suggested change
public static synchronized DraggableAnnotationController getInstance(MapView mapView, MapboxMap mapboxMap) {
if(INSTANCE == null){
INSTANCE = new DraggableAnnotationController(mapView, mapboxMap);
}
return INSTANCE;
}
public static synchronized DraggableAnnotationController getInstance(MapView mapView, MapboxMap mapboxMap) {
if(INSTANCE == null || this.mapView != mapview || this.mapboxMap != mapboxMap){
INSTANCE = new DraggableAnnotationController(mapView, mapboxMap);
}
return INSTANCE;
}

The strong references to mapView and mapboxMap should be dropped when the last removeAnnotationManager is called and the instance is nullified so we shouldn't leak. It'd be great to test this scenario though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right I did not think about that 👍. I updated the code to reflect what you said. Regarding the testing of the last part of your remark, I'm not sure how I can do it.

LukasPaczos pushed a commit that referenced this pull request Jul 22, 2020
I wrote a seperate PR for this issue such as to simplify the review of #1125.
- Fixes #883

Any review and comment would be much appreciated 👍 @LukasPaczos and @langsmith.
@Ph0tonic Ph0tonic force-pushed the p0-annotation-plugin-draggable-manager branch from a88bb8d to 0c13d6f Compare July 23, 2020 20:28
@LukasPaczos LukasPaczos mentioned this pull request Jul 28, 2020
@LukasPaczos
Copy link
Contributor

Amazing work here, thanks @Ph0tonic! Let's continue in #1147.

@Ph0tonic
Copy link
Contributor Author

Amazing work here, thanks @Ph0tonic! Let's continue in #1147.

You are welcome

@Ph0tonic Ph0tonic deleted the p0-annotation-plugin-draggable-manager branch July 29, 2020 18:25
@pengdev pengdev mentioned this pull request Aug 13, 2020
14 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.

3 participants