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

Drawing boundaries feature #306

Merged
merged 33 commits into from
Jul 10, 2019
Merged

Conversation

eotin
Copy link
Contributor

@eotin eotin commented Jun 25, 2019

No description provided.

eotin added 10 commits June 25, 2019 13:19
- Add MapBox annotations plugins
- Drawing Manager encapsulating the Circle/Line/Fill Manager
- Smart listeners
Refactor KujakuLayer
TODO :
- Include KujakuLayer OnClick & OnLongClick in the drawing Manager
- Add Unit tests
Refactor DrawingManager and KujakuMapview to encapsulate APIs
Update the Manifest.xml
@ekigamba ekigamba changed the title Drawing boundaries clean Drawing boundaries feature Jun 25, 2019
@coveralls
Copy link

coveralls commented Jun 25, 2019

Pull Request Test Coverage Report for Build 1450

  • 336 of 498 (67.47%) changed or added relevant lines in 11 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+12.5%) to 50.512%

Changes Missing Coverage Covered Lines Changed/Added Lines %
library/src/main/java/io/ona/kujaku/layers/ArrowLineLayer.java 0 1 0.0%
library/src/main/java/io/ona/kujaku/plugin/switcher/layer/BaseLayer.java 1 2 50.0%
library/src/main/java/io/ona/kujaku/manager/KujakuCircleOptions.java 23 25 92.0%
library/src/main/java/io/ona/kujaku/helpers/PermissionsHelper.java 3 11 27.27%
library/src/main/java/io/ona/kujaku/layers/KujakuLayer.java 25 40 62.5%
library/src/main/java/io/ona/kujaku/layers/FillBoundaryLayer.java 16 33 48.48%
library/src/main/java/io/ona/kujaku/helpers/wmts/WmtsHelper.java 31 49 63.27%
library/src/main/java/io/ona/kujaku/views/KujakuMapView.java 6 27 22.22%
library/src/main/java/io/ona/kujaku/layers/BoundaryLayer.java 14 40 35.0%
library/src/main/java/io/ona/kujaku/manager/DrawingManager.java 198 251 78.88%
Files with Coverage Reduction New Missed Lines %
library/src/main/java/io/ona/kujaku/views/KujakuMapView.java 3 23.63%
Totals Coverage Status
Change from base Build 1418: 12.5%
Covered Lines: 2613
Relevant Lines: 5173

💛 - Coveralls

@ekigamba ekigamba self-requested a review July 1, 2019 11:49
buildToolsVersion = "28.0.3"
compileSdkVersion = 27
compileSdkVersion = 28
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you test to make sure the app does not break due to https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p and https://developer.android.com/about/versions/pie/android-9.0-changes-28#tls-enabled?

You can also confirm this on the code.

Confirm and test the following also:

  1. https://developer.android.com/about/versions/pie/android-9.0-changes-all#fant-required Which affects the activity that is started by the TrackingService from the background

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I confirm that everything is working fine


Feature feature = Feature.fromGeometry(polygon);
FeatureCollection collection = FeatureCollection.fromFeature(feature);
FillBoundaryLayer layer = new FillBoundaryLayer.Builder(collection)
Copy link
Contributor

Choose a reason for hiding this comment

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

So can we reuse the same FillBoundaryLayer. Seems that this creates multiple FillBoundaryLayers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sure, we can create one if it is a new draw, and update the existing one if it is an edition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


kujakuMapView.addLayer(layer);
}
this.currentLayer = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

The issue is still evident on the updated code. I am guessing it's because of nullifying this layer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand what issue is still present ? If we use the drawing mamanger by clicking the start drawing button, we want to draw a new Layer. That is why we create a new one here.
Please advise

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the aim of the method, then it's OK

@Override
public void onClick(View view) {
// start Drawing from scratch
if (! drawingManager.isDrawingEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Check for null drawingManager in case the map was openned without internet connection. The style will not load and the DrawingManager will not be created

@Override
public void onCircleClick(@NonNull Circle circle) {
Toast.makeText(DrawingBoundariesActivity.this,
String.format("Circle clicked"),Toast.LENGTH_SHORT).show();
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this call to String.format and add the strings to strings.xml

@Override
public void onCircleNotClick(@NonNull LatLng latLng) {
Toast.makeText(DrawingBoundariesActivity.this,
String.format("Circle NOT clicked"),Toast.LENGTH_SHORT).show();
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this call to String.format and add the strings to strings.xml

@Override
public void onCircleLongClick(@NonNull Circle circle) {
Toast.makeText(DrawingBoundariesActivity.this,
String.format("Circle long clicked"),Toast.LENGTH_SHORT).show();
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this call to String.format and add the strings to strings.xml

@Override
public void onCircleNotLongClick(@NonNull LatLng point) {
Toast.makeText(DrawingBoundariesActivity.this,
String.format("Circle NOT long clicked"),Toast.LENGTH_SHORT).show();
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this call to String.format and add the strings to strings.xml

@@ -817,6 +702,9 @@ protected VisibleRegion getCurrentBounds() {
private void enableFeatureClickListenerEmitter(@NonNull MapboxMap mapboxMap) {
mapboxMap.removeOnMapClickListener(this);
mapboxMap.addOnMapClickListener(this);

mapboxMap.removeOnMapLongClickListener(this);
mapboxMap.addOnMapLongClickListener(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure why the remove and add ClickListener follow one another. Do you have an idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure too i took the example with the removeOnMapClickListener above

return true;
}

Geometry geometry = kujakuLayer.getFeatureCollection().features().get(0).geometry();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can add a check to make sure features() is not null. The IDE is complaining that there might be an NPE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image
I don't understand my IDE here ..

Copy link
Contributor

Choose a reason for hiding this comment

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

features() has been annotated as returning a nullable value. So calling get(0) on a null will introduce an NPE. Check that features is not null and reuse the validated variable to get feature at index 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you can see above, I check if features is not null and if the size >= 1.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, then the IDE has not way of figuring that out since you did not use store it in a variable and use the null-checked variable. This is OK

* @param kujakuLayer
* @return
*/
public boolean startDrawingKujakuLayer(@Nullable KujakuLayer kujakuLayer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we should the general KujakuLayer specifically?

Is this supposed to work with all KujakuLayers or BoundaryLayer or FillBoundaryLayer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, Do you want to restrict to FillBoundaryLayers only ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should restrict the drawing, right? I am not sure what it is supposed to work with but we also have BaseLayer which is a KujakuLayer. That layer basically has raster. I guess some KujakuLayers might not have feature collections and would return null when getFeatureCollection is called. Probably restrict it to what you would want it to be used on. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, i agree. I will update the code to restrict to the FillBoundaryLayer only

}
}

circleManager.update(circle);
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see that you update the circle here. Should you also update the previousCircle and nextCircle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the next and previous circle are deleted if they are not null above

return true;
}

Geometry geometry = kujakuLayer.getFeatureCollection().features().get(0).geometry();
Copy link
Contributor

Choose a reason for hiding this comment

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

features() has been annotated as returning a nullable value. So calling get(0) on a null will introduce an NPE. Check that features is not null and reuse the validated variable to get feature at index 0

* @param kujakuLayer
* @return
*/
public boolean startDrawingKujakuLayer(@Nullable KujakuLayer kujakuLayer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should restrict the drawing, right? I am not sure what it is supposed to work with but we also have BaseLayer which is a KujakuLayer. That layer basically has raster. I guess some KujakuLayers might not have feature collections and would return null when getFeatureCollection is called. Probably restrict it to what you would want it to be used on. What do you think?

@ekigamba ekigamba merged commit 2c8c1a4 into onaio:master Jul 10, 2019
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