|
57 | 57 | import fr.free.nrw.commons.R;
|
58 | 58 | import fr.free.nrw.commons.Utils;
|
59 | 59 | import fr.free.nrw.commons.kvstore.JsonKvStore;
|
| 60 | +import fr.free.nrw.commons.location.LocationPermissionsHelper; |
| 61 | +import fr.free.nrw.commons.location.LocationPermissionsHelper.Dialog; |
| 62 | +import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermissionCallback; |
| 63 | +import fr.free.nrw.commons.location.LocationServiceManager; |
60 | 64 | import fr.free.nrw.commons.theme.BaseActivity;
|
61 | 65 | import fr.free.nrw.commons.utils.SystemThemeUtils;
|
62 | 66 | import javax.inject.Inject;
|
@@ -148,6 +152,9 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
148 | 152 | SystemThemeUtils systemThemeUtils;
|
149 | 153 | private boolean isDarkTheme;
|
150 | 154 |
|
| 155 | + @Inject |
| 156 | + LocationServiceManager locationManager; |
| 157 | + |
151 | 158 | @Override
|
152 | 159 | protected void onCreate(@Nullable final Bundle savedInstanceState) {
|
153 | 160 | getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
|
@@ -452,11 +459,40 @@ private void addCenterOnGPSButton(){
|
452 | 459 | fabCenterOnLocation = findViewById(R.id.center_on_gps);
|
453 | 460 | fabCenterOnLocation.setOnClickListener(view -> getCenter());
|
454 | 461 | }
|
| 462 | + |
455 | 463 | /**
|
456 |
| - * Animate map to move to desired Latitude and Longitude |
| 464 | + * Center the map at user's current location |
457 | 465 | */
|
458 |
| - void getCenter() { |
459 |
| - mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()),15.0)); |
| 466 | + private void getCenter() { |
| 467 | + LocationPermissionsHelper.Dialog locationAccessDialog = new Dialog( |
| 468 | + R.string.location_permission_title, |
| 469 | + R.string.upload_map_location_access |
| 470 | + ); |
| 471 | + |
| 472 | + LocationPermissionsHelper.Dialog locationOffDialog = new Dialog( |
| 473 | + R.string.ask_to_turn_location_on, |
| 474 | + R.string.upload_map_location_access |
| 475 | + ); |
| 476 | + LocationPermissionsHelper locationPermissionsHelper = new LocationPermissionsHelper( |
| 477 | + this, locationManager, new LocationPermissionCallback() { |
| 478 | + @Override |
| 479 | + public void onLocationPermissionDenied(String toastMessage) { |
| 480 | + // Do nothing |
| 481 | + } |
| 482 | + |
| 483 | + @Override |
| 484 | + public void onLocationPermissionGranted() { |
| 485 | + fr.free.nrw.commons.location.LatLng currLocation = locationManager.getLastLocation(); |
| 486 | + final CameraPosition position; |
| 487 | + position = new CameraPosition.Builder() |
| 488 | + .target(new com.mapbox.mapboxsdk.geometry.LatLng(currLocation.getLatitude(), currLocation.getLongitude(), 0)) // Sets the new camera position |
| 489 | + .zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level |
| 490 | + .build(); |
| 491 | + |
| 492 | + mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000); |
| 493 | + } |
| 494 | + }); |
| 495 | + locationPermissionsHelper.handleLocationPermissions(locationAccessDialog, locationOffDialog); |
460 | 496 | }
|
461 | 497 |
|
462 | 498 | @Override
|
|
0 commit comments