@@ -304,37 +304,28 @@ public void onActivityResult(Map<String, Boolean> result) {
304
304
}
305
305
});
306
306
307
- private ActivityResultLauncher <String []> locationPermissionLauncher = registerForActivityResult (
308
- new ActivityResultContracts .RequestMultiplePermissions (),
309
- new ActivityResultCallback <Map <String , Boolean >>() {
310
- @ Override
311
- public void onActivityResult (Map <String , Boolean > result ) {
312
- boolean areAllGranted = true ;
313
- for (final boolean b : result .values ()) {
314
- areAllGranted = areAllGranted && b ;
315
- }
316
-
317
- if (areAllGranted ) {
318
- locationPermissionGranted ();
307
+ private ActivityResultLauncher <String > locationPermissionLauncher = registerForActivityResult (
308
+ new ActivityResultContracts .RequestPermission (), isGranted -> {
309
+ if (isGranted ) {
310
+ locationPermissionGranted ();
311
+ } else {
312
+ if (shouldShowRequestPermissionRationale (permission .ACCESS_FINE_LOCATION )) {
313
+ DialogUtil .showAlertDialog (getActivity (),
314
+ getActivity ().getString (R .string .location_permission_title ),
315
+ getActivity ().getString (R .string .location_permission_rationale_nearby ),
316
+ getActivity ().getString (android .R .string .ok ),
317
+ getActivity ().getString (android .R .string .cancel ),
318
+ () -> {
319
+ if (!(locationManager .isNetworkProviderEnabled ()
320
+ || locationManager .isGPSProviderEnabled ())) {
321
+ showLocationOffDialog ();
322
+ }
323
+ },
324
+ () -> isPermissionDenied = true ,
325
+ null ,
326
+ false );
319
327
} else {
320
- if (shouldShowRequestPermissionRationale (permission .ACCESS_FINE_LOCATION )) {
321
- DialogUtil .showAlertDialog (getActivity (),
322
- getActivity ().getString (R .string .location_permission_title ),
323
- getActivity ().getString (R .string .location_permission_rationale_nearby ),
324
- getActivity ().getString (android .R .string .ok ),
325
- getActivity ().getString (android .R .string .cancel ),
326
- () -> {
327
- if (!(locationManager .isNetworkProviderEnabled ()
328
- || locationManager .isGPSProviderEnabled ())) {
329
- showLocationOffDialog ();
330
- }
331
- },
332
- () -> isPermissionDenied = true ,
333
- null ,
334
- false );
335
- } else {
336
- isPermissionDenied = true ;
337
- }
328
+ isPermissionDenied = true ;
338
329
}
339
330
}
340
331
});
@@ -1037,10 +1028,28 @@ public fr.free.nrw.commons.location.LatLng getLastMapFocus() {
1037
1028
return latLng ;
1038
1029
}
1039
1030
1031
+ /**
1032
+ * Computes location where map should be centered
1033
+ *
1034
+ * @return returns the last location, if available, else returns default location
1035
+ */
1040
1036
@ Override
1041
1037
public fr .free .nrw .commons .location .LatLng getMapCenter () {
1042
- fr .free .nrw .commons .location .LatLng latLnge = new fr .free .nrw .commons .location .LatLng (
1043
- mapCenter .getLatitude (), mapCenter .getLongitude (), 100 );
1038
+ if (applicationKvStore .getString ("LastLocation" ) != null ) {
1039
+ final String [] locationLatLng
1040
+ = applicationKvStore .getString ("LastLocation" ).split ("," );
1041
+ lastKnownLocation
1042
+ = new fr .free .nrw .commons .location .LatLng (Double .parseDouble (locationLatLng [0 ]),
1043
+ Double .parseDouble (locationLatLng [1 ]), 1f );
1044
+ } else {
1045
+ lastKnownLocation = new fr .free .nrw .commons .location .LatLng (51.50550 ,
1046
+ -0.07520 , 1f );
1047
+ }
1048
+ fr .free .nrw .commons .location .LatLng latLnge = lastKnownLocation ;
1049
+ if (mapCenter != null ) {
1050
+ latLnge = new fr .free .nrw .commons .location .LatLng (
1051
+ mapCenter .getLatitude (), mapCenter .getLongitude (), 100 );
1052
+ }
1044
1053
return latLnge ;
1045
1054
}
1046
1055
@@ -1320,7 +1329,7 @@ public void setTabItemContributions() {
1320
1329
@ Override
1321
1330
public void checkPermissionsAndPerformAction () {
1322
1331
Timber .d ("Checking permission and perfoming action" );
1323
- locationPermissionLauncher .launch (new String []{ permission .ACCESS_FINE_LOCATION } );
1332
+ locationPermissionLauncher .launch (permission .ACCESS_FINE_LOCATION );
1324
1333
}
1325
1334
1326
1335
/**
@@ -1625,7 +1634,7 @@ public fr.free.nrw.commons.location.LatLng getCameraTarget() {
1625
1634
*/
1626
1635
public void updateMarker (final boolean isBookmarked , final Place place ,
1627
1636
@ Nullable final fr .free .nrw .commons .location .LatLng curLatLng ) {
1628
- addMarkerToMap (place , isBookmarked );
1637
+ addMarkerToMap (place , isBookmarked );
1629
1638
}
1630
1639
1631
1640
/**
@@ -1770,7 +1779,7 @@ private void removeMarker(Place place){
1770
1779
mapView .invalidate ();
1771
1780
break ;
1772
1781
}
1773
- }
1782
+ }
1774
1783
}
1775
1784
}
1776
1785
0 commit comments