Skip to content

Commit 4a69bc5

Browse files
authored
Unit Tests for LocationPickerActivity (#4830)
* LocationPickerActivityUnitTests.kt class created * Unit tests for LocationPickerActivity * Unit tests for LocationPickerActivity * Added verify * verify added * Minor changes * Covered more lines * Covered more lines * addCredits test added
1 parent ea6258c commit 4a69bc5

File tree

3 files changed

+291
-103
lines changed

3 files changed

+291
-103
lines changed

app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -224,44 +224,57 @@ private void getToolbarUI() {
224224
@Override
225225
public void onMapReady(final MapboxMap mapboxMap) {
226226
this.mapboxMap = mapboxMap;
227-
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
228-
229-
if (modifyLocationButton.getVisibility() == View.VISIBLE) {
230-
initDroppedMarker(style);
231-
adjustCameraBasedOnOptions();
232-
enableLocationComponent(style);
233-
if (style.getLayer(DROPPED_MARKER_LAYER_ID) != null) {
234-
final GeoJsonSource source = style.getSourceAs("dropped-marker-source-id");
235-
if (source != null) {
236-
source.setGeoJson(Point.fromLngLat(cameraPosition.target.getLongitude(),
237-
cameraPosition.target.getLatitude()));
238-
}
239-
droppedMarkerLayer = style.getLayer(DROPPED_MARKER_LAYER_ID);
240-
if (droppedMarkerLayer != null) {
241-
droppedMarkerLayer.setProperties(visibility(VISIBLE));
242-
markerImage.setVisibility(View.GONE);
243-
shadow.setVisibility(View.GONE);
244-
}
227+
mapboxMap.setStyle(Style.MAPBOX_STREETS, this::onStyleLoaded);
228+
}
229+
230+
/**
231+
* Initializes dropped marker and layer
232+
* Handles camera position based on options
233+
* Enables location components
234+
*
235+
* @param style style
236+
*/
237+
private void onStyleLoaded(final Style style) {
238+
if (modifyLocationButton.getVisibility() == View.VISIBLE) {
239+
initDroppedMarker(style);
240+
adjustCameraBasedOnOptions();
241+
enableLocationComponent(style);
242+
if (style.getLayer(DROPPED_MARKER_LAYER_ID) != null) {
243+
final GeoJsonSource source = style.getSourceAs("dropped-marker-source-id");
244+
if (source != null) {
245+
source.setGeoJson(Point.fromLngLat(cameraPosition.target.getLongitude(),
246+
cameraPosition.target.getLatitude()));
247+
}
248+
droppedMarkerLayer = style.getLayer(DROPPED_MARKER_LAYER_ID);
249+
if (droppedMarkerLayer != null) {
250+
droppedMarkerLayer.setProperties(visibility(VISIBLE));
251+
markerImage.setVisibility(View.GONE);
252+
shadow.setVisibility(View.GONE);
245253
}
246-
} else {
247-
adjustCameraBasedOnOptions();
248-
enableLocationComponent(style);
249-
bindListeners();
250254
}
251-
modifyLocationButton.setOnClickListener(v -> {
252-
placeSelectedButton.setVisibility(View.VISIBLE);
253-
modifyLocationButton.setVisibility(View.GONE);
254-
showInMapButton.setVisibility(View.GONE);
255-
droppedMarkerLayer.setProperties(visibility(NONE));
256-
markerImage.setVisibility(View.VISIBLE);
257-
shadow.setVisibility(View.VISIBLE);
258-
largeToolbarText.setText(getResources().getString(R.string.choose_a_location));
259-
smallToolbarText.setText(getResources().getString(R.string.pan_and_zoom_to_adjust));
260-
bindListeners();
261-
});
262-
263-
showInMapButton.setOnClickListener(v -> showInMap());
264-
});
255+
} else {
256+
adjustCameraBasedOnOptions();
257+
enableLocationComponent(style);
258+
bindListeners();
259+
}
260+
261+
modifyLocationButton.setOnClickListener(v -> onClickModifyLocation());
262+
showInMapButton.setOnClickListener(v -> showInMap());
263+
}
264+
265+
/**
266+
* Handles onclick event of modifyLocationButton
267+
*/
268+
private void onClickModifyLocation() {
269+
placeSelectedButton.setVisibility(View.VISIBLE);
270+
modifyLocationButton.setVisibility(View.GONE);
271+
showInMapButton.setVisibility(View.GONE);
272+
droppedMarkerLayer.setProperties(visibility(NONE));
273+
markerImage.setVisibility(View.VISIBLE);
274+
shadow.setVisibility(View.VISIBLE);
275+
largeToolbarText.setText(getResources().getString(R.string.choose_a_location));
276+
smallToolbarText.setText(getResources().getString(R.string.pan_and_zoom_to_adjust));
277+
bindListeners();
265278
}
266279

267280
/**
@@ -290,6 +303,7 @@ private void initDroppedMarker(@NonNull final Style loadedMapStyle) {
290303
iconIgnorePlacement(true)
291304
));
292305
}
306+
293307
/**
294308
* move the location to the current media coordinates
295309
*/

app/src/test/kotlin/fr/free/nrw/commons/locationpicker/LocationPickerActivityTest.kt

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)