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

Feature/fix unit tests for #5262 ("Remove location" button for new uploads) #5337

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e0d0e77
Added styling for "remove location" button to be shown when opening l…
paco-arana Jul 24, 2023
a1be991
Added english language strings for remove location button and popup
paco-arana Jul 24, 2023
210bf23
Merge branch 'commons-app:master' into removelocation
paco-arana Jul 24, 2023
7160d6a
Added code to display remove button whenever the edit button is prese…
paco-arana Jul 24, 2023
d96be6b
Merge remote-tracking branch 'origin/removelocation' into removelocation
paco-arana Jul 24, 2023
01f3654
Added popup to be displayed when clicking on "remove location" button…
paco-arana Jul 24, 2023
34b3013
Added contents of removeLocationFromPicture() method
paco-arana Jul 24, 2023
818fc74
Modified removeLocationFromPicture() to save and exit
paco-arana Jul 24, 2023
df90bde
Methods now set coords to null instead of 0,0.
paco-arana Jul 27, 2023
8e596c6
Merge branch 'commons-app:master' into removelocation
paco-arana Jul 27, 2023
ec0d9b6
Simplified removeLocationFromPicture()
paco-arana Jul 28, 2023
efa657b
Attempt 1: Added removeLocationButton to tests
paco-arana Jul 28, 2023
968cb49
Attempt 2: Moved loc removal to placeSelected()
paco-arana Jul 29, 2023
8b92253
Attempt 3: Testing without method.invoke()
paco-arana Jul 30, 2023
230a1d4
Attempt 4: Placing camera loc to 0,0 and using boolean to remove it e…
paco-arana Jul 30, 2023
5f9feb9
Rolling back changes to tests
paco-arana Jul 30, 2023
1e8049d
Rolling back changes to activity
paco-arana Jul 31, 2023
0f959c3
Attempt 5: Simplified method. Made Style Nullable
paco-arana Jul 31, 2023
d1b6c99
Merge branch 'removelocation' of https://github.com/paco-arana/apps-a…
TomerPacific Oct 14, 2023
14d9096
feature/fix-unit-tests adding mock for removeLocationButton
TomerPacific Oct 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermissionCallback;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.SystemThemeUtils;
import javax.inject.Inject;
import javax.inject.Named;
Expand Down Expand Up @@ -111,6 +112,14 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
* modifyLocationButton : button for start editing location
*/
Button modifyLocationButton;
/**
* removeLocationButton : button for removing location metadata
*/
Button removeLocationButton;
/**
* isRemovedByUser : used to flag when a location is intentionally removed by the user
*/
private boolean isRemovedByUser = false;
/**
* showInMapButton : button for showing in map
*/
Expand Down Expand Up @@ -190,6 +199,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
if ("UploadActivity".equals(activity)) {
placeSelectedButton.setVisibility(View.GONE);
modifyLocationButton.setVisibility(View.VISIBLE);
removeLocationButton.setVisibility(View.VISIBLE);
showInMapButton.setVisibility(View.VISIBLE);
largeToolbarText.setText(getResources().getString(R.string.image_location));
smallToolbarText.setText(getResources().
Expand Down Expand Up @@ -225,6 +235,7 @@ private void bindViews() {
markerImage = findViewById(R.id.location_picker_image_view_marker);
tvAttribution = findViewById(R.id.tv_attribution);
modifyLocationButton = findViewById(R.id.modify_location);
removeLocationButton = findViewById(R.id.remove_location);
showInMapButton = findViewById(R.id.show_in_map);
showInMapButton.setText(getResources().getString(R.string.show_in_map_app).toUpperCase());
shadow = findViewById(R.id.location_picker_image_view_shadow);
Expand Down Expand Up @@ -267,7 +278,7 @@ public void onMapReady(final MapboxMap mapboxMap) {
*
* @param style style
*/
private void onStyleLoaded(final Style style) {
private void onStyleLoaded(@Nullable final Style style) {
if (modifyLocationButton.getVisibility() == View.VISIBLE) {
initDroppedMarker(style);
adjustCameraBasedOnOptions();
Expand All @@ -292,6 +303,7 @@ private void onStyleLoaded(final Style style) {
}

modifyLocationButton.setOnClickListener(v -> onClickModifyLocation());
removeLocationButton.setOnClickListener(v -> onClickRemoveLocation());
showInMapButton.setOnClickListener(v -> showInMap());
}

Expand All @@ -301,6 +313,7 @@ private void onStyleLoaded(final Style style) {
private void onClickModifyLocation() {
placeSelectedButton.setVisibility(View.VISIBLE);
modifyLocationButton.setVisibility(View.GONE);
removeLocationButton.setVisibility(View.GONE);
showInMapButton.setVisibility(View.GONE);
droppedMarkerLayer.setProperties(visibility(NONE));
markerImage.setVisibility(View.VISIBLE);
Expand All @@ -311,6 +324,27 @@ private void onClickModifyLocation() {
fabCenterOnLocation.setVisibility(View.VISIBLE);
}

/**
* Handles onclick event of removeLocationButton
*/
private void onClickRemoveLocation(){
DialogUtil.showAlertDialog(this,
getString(R.string.no_location_selected),
getString(R.string.no_location_selected_warning_desc),
getString(R.string.continue_message),
getString(R.string.cancel), () -> removeLocationFromPicture(), null);
}

/**
* Method to remove the location from the picture and exit the location picker activity
*/
private void removeLocationFromPicture() {
// Exit with intent lacking position data
final Intent returningIntent = new Intent();
setResult(AppCompatActivity.RESULT_OK, returningIntent);
finish();
}

/**
* Show the location in map app
*/
Expand Down Expand Up @@ -451,7 +485,7 @@ void placeSelected() {
}
final Intent returningIntent = new Intent();
returningIntent.putExtra(LocationPickerConstants.MAP_CAMERA_POSITION,
mapboxMap.getCameraPosition());
mapboxMap.getCameraPosition());
setResult(AppCompatActivity.RESULT_OK, returningIntent);
finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ public void onActivityResult(final int requestCode, final int resultCode,
isMissingLocationDialog = false;
onNextButtonClicked();
}
} else {
// Location removed by user.
removeLocation();
}
}
}
Expand All @@ -544,6 +547,14 @@ public void editLocation(final String latitude, final String longitude, final do

}

/**
* Update the old coordinates with new one
*/
public void removeLocation(){
editableUploadItem.getGpsCoords().setDecimalCoords(null);
Toast.makeText(getContext(), "Location Removed", Toast.LENGTH_LONG).show();
}

@Override
public void updateMediaDetails(List<UploadMediaDetail> uploadMediaDetails) {
uploadMediaDetailAdapter.setItems(uploadMediaDetails);
Expand Down
28 changes: 25 additions & 3 deletions app/src/main/res/layout/bottom_container_location_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,46 @@
app:layout_constraintStart_toStartOf="parent">

<Button
android:id="@+id/modify_location"
android:id="@+id/remove_location"
style="@style/Widget.AppCompat.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/deleteRed"
android:text="@string/remove_location"
android:textColor="@color/white"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/map_bottom_layout"
app:layout_constraintEnd_toStartOf="@+id/guideline2"
app:layout_constraintStart_toStartOf="@id/map_bottom_layout"
app:layout_constraintTop_toTopOf="@id/map_bottom_layout" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.30" />

<Button
android:id="@+id/modify_location"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="@string/modify_location"
android:textColor="@color/white"
android:visibility="gone"
android:layout_margin="5dp"
app:layout_constraintBottom_toBottomOf="@id/map_bottom_layout"
app:layout_constraintEnd_toStartOf="@+id/guideline3"
app:layout_constraintStart_toStartOf="@id/map_bottom_layout"
app:layout_constraintStart_toEndOf="@+id/guideline2"
app:layout_constraintTop_toTopOf="@id/map_bottom_layout" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
app:layout_constraintGuide_percent="0.70" />

<TextView
android:id="@+id/show_in_map"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ Upload your first media by tapping on the add button.</string>
<string name="no_depictions_selected">No Depictions Selected</string>
<string name="no_depictions_selected_warning_desc">Images with depictions are more easily found and more likely to be used. Are you sure you want to continue without selecting depictions?</string>

<string name="no_location_selected">Removing Location</string>
<string name="no_location_selected_warning_desc">Location makes pictures more useful and findable. Do you really wish to remove location from this picture?</string>

<string name="back_button_warning">Cancel Upload</string>
<string name="back_button_warning_desc">Using the back button will cancel this upload and you will lose your progress</string>
<string name="back_button_continue">Continue Upload</string>
Expand Down Expand Up @@ -698,6 +701,7 @@ Upload your first media by tapping on the add button.</string>
<string name="select_location_location_picker">Select location</string>
<string name="show_in_map_app">Show in map app</string>
<string name="modify_location">Edit location</string>
<string name="remove_location">Remove location</string>
<string name="location_picker_image_view">The image view of the location picker</string>
<string name="location_picker_image_view_shadow">
The shadow of the image view of the location picker</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class LocationPickerActivityUnitTests {
@Mock
private lateinit var style: Style

@Mock
private lateinit var removeLocationButton: Button

@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
Expand All @@ -111,6 +114,7 @@ class LocationPickerActivityUnitTests {
Whitebox.setInternalState(activity, "smallToolbarText", smallToolbarText)
Whitebox.setInternalState(activity, "fabCenterOnLocation", fabCenterOnLocation)
Whitebox.setInternalState(activity, "tvAttribution", tvAttribution)
Whitebox.setInternalState(activity, "removeLocationButton", removeLocationButton)
}

@Test
Expand Down