Skip to content

Commit

Permalink
Merge branch 'removelocation' of https://github.com/paco-arana/apps-a…
Browse files Browse the repository at this point in the history
…ndroid-commons into feature/fix-unit-tests
  • Loading branch information
TomerPacific committed Oct 14, 2023
2 parents 8553a96 + 0f959c3 commit d1b6c99
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
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

0 comments on commit d1b6c99

Please sign in to comment.