@@ -303,37 +303,30 @@ public void onActivityResult(Map<String, Boolean> result) {
303
303
}
304
304
});
305
305
306
- private ActivityResultLauncher <String []> locationPermissionLauncher = registerForActivityResult (
307
- new ActivityResultContracts .RequestMultiplePermissions (),
308
- new ActivityResultCallback <Map <String , Boolean >>() {
309
- @ Override
310
- public void onActivityResult (Map <String , Boolean > result ) {
311
- boolean areAllGranted = true ;
312
- for (final boolean b : result .values ()) {
313
- areAllGranted = areAllGranted && b ;
314
- }
315
-
316
- if (areAllGranted ) {
317
- locationPermissionGranted ();
306
+ private ActivityResultLauncher <String > locationPermissionLauncher = registerForActivityResult (
307
+ new ActivityResultContracts .RequestPermission (), isGranted ->{
308
+ if (isGranted )
309
+ {
310
+ locationPermissionGranted ();
311
+ }
312
+ else {
313
+ if (shouldShowRequestPermissionRationale (permission .ACCESS_FINE_LOCATION )) {
314
+ DialogUtil .showAlertDialog (getActivity (),
315
+ getActivity ().getString (R .string .location_permission_title ),
316
+ getActivity ().getString (R .string .location_permission_rationale_nearby ),
317
+ getActivity ().getString (android .R .string .ok ),
318
+ getActivity ().getString (android .R .string .cancel ),
319
+ () -> {
320
+ if (!(locationManager .isNetworkProviderEnabled ()
321
+ || locationManager .isGPSProviderEnabled ())) {
322
+ showLocationOffDialog ();
323
+ }
324
+ },
325
+ () -> isPermissionDenied = true ,
326
+ null ,
327
+ false );
318
328
} else {
319
- if (shouldShowRequestPermissionRationale (permission .ACCESS_FINE_LOCATION )) {
320
- DialogUtil .showAlertDialog (getActivity (),
321
- getActivity ().getString (R .string .location_permission_title ),
322
- getActivity ().getString (R .string .location_permission_rationale_nearby ),
323
- getActivity ().getString (android .R .string .ok ),
324
- getActivity ().getString (android .R .string .cancel ),
325
- () -> {
326
- if (!(locationManager .isNetworkProviderEnabled ()
327
- || locationManager .isGPSProviderEnabled ())) {
328
- showLocationOffDialog ();
329
- }
330
- },
331
- () -> isPermissionDenied = true ,
332
- null ,
333
- false );
334
- } else {
335
- isPermissionDenied = true ;
336
- }
329
+ isPermissionDenied = true ;
337
330
}
338
331
}
339
332
});
@@ -1037,8 +1030,22 @@ public fr.free.nrw.commons.location.LatLng getLastMapFocus() {
1037
1030
1038
1031
@ Override
1039
1032
public fr .free .nrw .commons .location .LatLng getMapCenter () {
1040
- fr .free .nrw .commons .location .LatLng latLnge = new fr .free .nrw .commons .location .LatLng (
1041
- mapCenter .getLatitude (), mapCenter .getLongitude (), 100 );
1033
+ if (applicationKvStore .getString ("LastLocation" ) != null ) {
1034
+ final String [] locationLatLng
1035
+ = applicationKvStore .getString ("LastLocation" ).split ("," );
1036
+ lastKnownLocation
1037
+ = new fr .free .nrw .commons .location .LatLng (Double .parseDouble (locationLatLng [0 ]),
1038
+ Double .parseDouble (locationLatLng [1 ]), 1f );
1039
+ } else {
1040
+ lastKnownLocation = new fr .free .nrw .commons .location .LatLng (51.50550 ,
1041
+ -0.07520 , 1f );
1042
+ }
1043
+ fr .free .nrw .commons .location .LatLng latLnge = lastKnownLocation ;
1044
+ if (mapCenter !=null )
1045
+ {
1046
+ latLnge = new fr .free .nrw .commons .location .LatLng (
1047
+ mapCenter .getLatitude (), mapCenter .getLongitude (), 100 );
1048
+ }
1042
1049
return latLnge ;
1043
1050
}
1044
1051
@@ -1318,7 +1325,7 @@ public void setTabItemContributions() {
1318
1325
@ Override
1319
1326
public void checkPermissionsAndPerformAction () {
1320
1327
Timber .d ("Checking permission and perfoming action" );
1321
- locationPermissionLauncher .launch (new String []{ permission .ACCESS_FINE_LOCATION } );
1328
+ locationPermissionLauncher .launch (permission .ACCESS_FINE_LOCATION );
1322
1329
}
1323
1330
1324
1331
/**
@@ -1623,7 +1630,7 @@ public fr.free.nrw.commons.location.LatLng getCameraTarget() {
1623
1630
*/
1624
1631
public void updateMarker (final boolean isBookmarked , final Place place ,
1625
1632
@ Nullable final fr .free .nrw .commons .location .LatLng curLatLng ) {
1626
- addMarkerToMap (place , isBookmarked );
1633
+ addMarkerToMap (place , isBookmarked );
1627
1634
}
1628
1635
1629
1636
private @ DrawableRes int getIconFor (Place place , Boolean isBookmarked ) {
@@ -1741,7 +1748,7 @@ private void removeMarker(Place place){
1741
1748
mapView .invalidate ();
1742
1749
break ;
1743
1750
}
1744
- }
1751
+ }
1745
1752
}
1746
1753
}
1747
1754
0 commit comments