|
6 | 6 | import android.content.Context;
|
7 | 7 | import android.content.Intent;
|
8 | 8 | import android.content.IntentFilter;
|
| 9 | +import android.content.pm.PackageManager; |
9 | 10 | import android.content.res.Configuration;
|
10 | 11 | import android.graphics.Bitmap;
|
11 | 12 | import android.os.Bundle;
|
| 13 | +import android.provider.Settings; |
12 | 14 | import android.util.Log;
|
13 | 15 | import android.view.Gravity;
|
14 | 16 | import android.view.LayoutInflater;
|
|
56 | 58 | import com.mapbox.pluginscalebar.ScaleBarPlugin;
|
57 | 59 | import com.pedrogomez.renderers.RVRendererAdapter;
|
58 | 60 |
|
| 61 | +import fr.free.nrw.commons.utils.DialogUtil; |
59 | 62 | import java.util.ArrayList;
|
60 | 63 | import java.util.List;
|
61 | 64 | import java.util.concurrent.TimeUnit;
|
@@ -1251,6 +1254,9 @@ private void setMapMarkerActions(Marker selectedMarker) {
|
1251 | 1254 | @Override
|
1252 | 1255 | public void recenterMap(fr.free.nrw.commons.location.LatLng curLatLng) {
|
1253 | 1256 | if (curLatLng == null) {
|
| 1257 | + if (!(locationManager.isNetworkProviderEnabled() || locationManager.isGPSProviderEnabled())) { |
| 1258 | + showLocationOffDialog(); |
| 1259 | + } |
1254 | 1260 | return;
|
1255 | 1261 | }
|
1256 | 1262 | addCurrentLocationMarker(curLatLng);
|
@@ -1281,6 +1287,28 @@ public void recenterMap(fr.free.nrw.commons.location.LatLng curLatLng) {
|
1281 | 1287 | mapBox.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
|
1282 | 1288 | }
|
1283 | 1289 |
|
| 1290 | + @Override |
| 1291 | + public void showLocationOffDialog() { |
| 1292 | + // This creates a dialog box that prompts the user to enable location |
| 1293 | + DialogUtil |
| 1294 | + .showAlertDialog(getActivity(), getString(R.string.ask_to_turn_location_on), getString(R.string.nearby_needs_location), |
| 1295 | + getString(R.string.yes), getString(R.string.no), this::openLocationSettings, null); |
| 1296 | + } |
| 1297 | + |
| 1298 | + @Override |
| 1299 | + public void openLocationSettings() { |
| 1300 | + // This method opens the location settings of the device along with a followup toast. |
| 1301 | + Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); |
| 1302 | + PackageManager packageManager = getActivity().getPackageManager(); |
| 1303 | + |
| 1304 | + if (intent.resolveActivity(packageManager)!= null) { |
| 1305 | + startActivity(intent); |
| 1306 | + Toast.makeText(getContext(), R.string.recommend_high_accuracy_mode, Toast.LENGTH_LONG).show(); |
| 1307 | + } else { |
| 1308 | + Toast.makeText(getContext(), R.string.cannot_open_location_settings, Toast.LENGTH_LONG).show(); |
| 1309 | + } |
| 1310 | + } |
| 1311 | + |
1284 | 1312 | @Override
|
1285 | 1313 | public void hideBottomSheet() {
|
1286 | 1314 | bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
0 commit comments