From 048b78a03acef5c41a88901c07d00b14176213fb Mon Sep 17 00:00:00 2001 From: Srishti Rohatgi <53987325+srishti-R@users.noreply.github.com> Date: Sat, 7 Oct 2023 18:37:08 +0530 Subject: [PATCH] Fixes location issue in upload wizard (#5329) * Fixes location issue in upload wizard * Fixes blue dot disappearance on first install --- .../LocationPicker/LocationPickerActivity.java | 11 ++++++++--- .../nrw/commons/location/LocationServiceManager.java | 6 +++--- 2 files changed, 11 insertions(+), 6 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 7454c77ef9..34ee9ec419 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 @@ -314,7 +314,7 @@ private void onClickModifyLocation() { /** * Show the location in map app */ - public void showInMap(){ + public void showInMap() { Utils.handleGeoCoordinates(this, new fr.free.nrw.commons.location.LatLng(cameraPosition.target.getLatitude(), cameraPosition.target.getLongitude(), 0.0f)); @@ -387,6 +387,8 @@ public void onFailure(@NonNull Exception exception) { }); + } else { + requestLocationPermissions(); } } @@ -458,13 +460,13 @@ void placeSelected() { */ private void addCenterOnGPSButton(){ fabCenterOnLocation = findViewById(R.id.center_on_gps); - fabCenterOnLocation.setOnClickListener(view -> getCenter()); + fabCenterOnLocation.setOnClickListener(view -> requestLocationPermissions()); } /** * Center the map at user's current location */ - private void getCenter() { + private void requestLocationPermissions() { LocationPermissionsHelper.Dialog locationAccessDialog = new Dialog( R.string.location_permission_title, R.string.upload_map_location_access @@ -539,6 +541,9 @@ public void onLocationPermissionDenied(String toastMessage) { @Override public void onLocationPermissionGranted() { + if (mapboxMap.getStyle() != null) { + enableLocationComponent(mapboxMap.getStyle()); + } fr.free.nrw.commons.location.LatLng currLocation = locationManager.getLastLocation(); if (currLocation != null) { final CameraPosition position; diff --git a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java index 09a4230cc4..6d95bd9a1d 100644 --- a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java +++ b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java @@ -1,6 +1,7 @@ package fr.free.nrw.commons.location; import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext; + import android.Manifest.permission; import android.app.Activity; import android.content.Context; @@ -9,7 +10,6 @@ import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; -import android.util.Log; import androidx.core.app.ActivityCompat; import java.util.HashSet; import java.util.List; @@ -59,9 +59,9 @@ private Location getLastKnownLocation() { for (String provider : providers) { Location l=null; if (ActivityCompat.checkSelfPermission(getApplicationContext(), permission.ACCESS_FINE_LOCATION) - != PackageManager.PERMISSION_GRANTED + == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), permission.ACCESS_COARSE_LOCATION) - != PackageManager.PERMISSION_GRANTED) { + == PackageManager.PERMISSION_GRANTED) { l = locationManager.getLastKnownLocation(provider); } if (l == null) {