@@ -302,37 +302,30 @@ public void onActivityResult(Map<String, Boolean> result) {
302
302
}
303
303
});
304
304
305
- private ActivityResultLauncher <String []> locationPermissionLauncher = registerForActivityResult (
306
- new ActivityResultContracts .RequestMultiplePermissions (),
307
- new ActivityResultCallback <Map <String , Boolean >>() {
308
- @ Override
309
- public void onActivityResult (Map <String , Boolean > result ) {
310
- boolean areAllGranted = true ;
311
- for (final boolean b : result .values ()) {
312
- areAllGranted = areAllGranted && b ;
313
- }
314
-
315
- if (areAllGranted ) {
316
- locationPermissionGranted ();
305
+ private ActivityResultLauncher <String > locationPermissionLauncher = registerForActivityResult (
306
+ new ActivityResultContracts .RequestPermission (), isGranted ->{
307
+ if (isGranted )
308
+ {
309
+ locationPermissionGranted ();
310
+ }
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 );
317
327
} else {
318
- if (shouldShowRequestPermissionRationale (permission .ACCESS_FINE_LOCATION )) {
319
- DialogUtil .showAlertDialog (getActivity (),
320
- getActivity ().getString (R .string .location_permission_title ),
321
- getActivity ().getString (R .string .location_permission_rationale_nearby ),
322
- getActivity ().getString (android .R .string .ok ),
323
- getActivity ().getString (android .R .string .cancel ),
324
- () -> {
325
- if (!(locationManager .isNetworkProviderEnabled ()
326
- || locationManager .isGPSProviderEnabled ())) {
327
- showLocationOffDialog ();
328
- }
329
- },
330
- () -> isPermissionDenied = true ,
331
- null ,
332
- false );
333
- } else {
334
- isPermissionDenied = true ;
335
- }
328
+ isPermissionDenied = true ;
336
329
}
337
330
}
338
331
});
@@ -1025,8 +1018,22 @@ public fr.free.nrw.commons.location.LatLng getLastMapFocus() {
1025
1018
1026
1019
@ Override
1027
1020
public fr .free .nrw .commons .location .LatLng getMapCenter () {
1028
- fr .free .nrw .commons .location .LatLng latLnge = new fr .free .nrw .commons .location .LatLng (
1029
- mapCenter .getLatitude (), mapCenter .getLongitude (), 100 );
1021
+ if (applicationKvStore .getString ("LastLocation" ) != null ) {
1022
+ final String [] locationLatLng
1023
+ = applicationKvStore .getString ("LastLocation" ).split ("," );
1024
+ lastKnownLocation
1025
+ = new fr .free .nrw .commons .location .LatLng (Double .parseDouble (locationLatLng [0 ]),
1026
+ Double .parseDouble (locationLatLng [1 ]), 1f );
1027
+ } else {
1028
+ lastKnownLocation = new fr .free .nrw .commons .location .LatLng (51.50550 ,
1029
+ -0.07520 , 1f );
1030
+ }
1031
+ fr .free .nrw .commons .location .LatLng latLnge = lastKnownLocation ;
1032
+ if (mapCenter !=null )
1033
+ {
1034
+ latLnge = new fr .free .nrw .commons .location .LatLng (
1035
+ mapCenter .getLatitude (), mapCenter .getLongitude (), 100 );
1036
+ }
1030
1037
return latLnge ;
1031
1038
}
1032
1039
@@ -1306,7 +1313,7 @@ public void setTabItemContributions() {
1306
1313
@ Override
1307
1314
public void checkPermissionsAndPerformAction () {
1308
1315
Timber .d ("Checking permission and perfoming action" );
1309
- locationPermissionLauncher .launch (new String []{ permission .ACCESS_FINE_LOCATION } );
1316
+ locationPermissionLauncher .launch (permission .ACCESS_FINE_LOCATION );
1310
1317
}
1311
1318
1312
1319
/**
@@ -1611,7 +1618,7 @@ public fr.free.nrw.commons.location.LatLng getCameraTarget() {
1611
1618
*/
1612
1619
public void updateMarker (final boolean isBookmarked , final Place place ,
1613
1620
@ Nullable final fr .free .nrw .commons .location .LatLng curLatLng ) {
1614
- addMarkerToMap (place , isBookmarked );
1621
+ addMarkerToMap (place , isBookmarked );
1615
1622
}
1616
1623
1617
1624
private @ DrawableRes int getIconFor (Place place , Boolean isBookmarked ) {
@@ -1729,7 +1736,7 @@ private void removeMarker(Place place){
1729
1736
mapView .invalidate ();
1730
1737
break ;
1731
1738
}
1732
- }
1739
+ }
1733
1740
}
1734
1741
}
1735
1742
0 commit comments