From 102fbfbeea6d817dc99ec994d6ff3d4e72b506dd Mon Sep 17 00:00:00 2001 From: Jason Whitmore Date: Fri, 6 Sep 2024 18:07:14 -0700 Subject: [PATCH] LocationPickerActivity.java: fix bug with permissions menu moving map Prior to this change, if the menu asking for permissions to access the device's GPS was accepted, the map would automatically move to the most recent or current GPS location, rather than staying at the uploaded image's available EXIF location. After this change, the map will stay centered at the image's available EXIF location, as intended. The relevant method name and javadoc have been changed to more accurately describe the method's behavior. --- .../LocationPicker/LocationPickerActivity.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java index f34fec6af..5966e2279 100644 --- a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java @@ -40,12 +40,10 @@ import fr.free.nrw.commons.R; import fr.free.nrw.commons.Utils; import fr.free.nrw.commons.auth.SessionManager; import fr.free.nrw.commons.auth.csrf.CsrfTokenClient; -import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException; import fr.free.nrw.commons.coordinates.CoordinateEditHelper; import fr.free.nrw.commons.filepicker.Constants; import fr.free.nrw.commons.kvstore.BasicKvStore; import fr.free.nrw.commons.kvstore.JsonKvStore; -import fr.free.nrw.commons.location.LatLng; import fr.free.nrw.commons.location.LocationPermissionsHelper; import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermissionCallback; import fr.free.nrw.commons.location.LocationServiceManager; @@ -606,9 +604,9 @@ public class LocationPickerActivity extends BaseActivity implements locationManager.requestLocationUpdatesFromProvider( LocationManager.NETWORK_PROVIDER); locationManager.requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER); - getLocation(); + addMarkerAtGPSLocation(); } else { - getLocation(); + addMarkerAtGPSLocation(); locationPermissionsHelper.showLocationOffDialog(this, R.string.ask_to_turn_location_on_text); } @@ -616,16 +614,15 @@ public class LocationPickerActivity extends BaseActivity implements } /** - * Gets new location if locations services are on, else gets last location + * Adds a marker to the map at the most recent GPS location + * (which may be the current GPS location). */ - private void getLocation() { + private void addMarkerAtGPSLocation() { fr.free.nrw.commons.location.LatLng currLocation = locationManager.getLastLocation(); if (currLocation != null) { GeoPoint currLocationGeopoint = new GeoPoint(currLocation.getLatitude(), currLocation.getLongitude()); addLocationMarker(currLocationGeopoint); - mapView.getController().setCenter(currLocationGeopoint); - mapView.getController().animateTo(currLocationGeopoint); markerImage.setTranslationY(0); } }