Skip to content

Commit 4055243

Browse files
committed
Resolves Issue #5413
1 parent b7090d9 commit 4055243

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -303,37 +303,30 @@ public void onActivityResult(Map<String, Boolean> result) {
303303
}
304304
});
305305

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);
318328
} 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;
337330
}
338331
}
339332
});
@@ -1037,8 +1030,22 @@ public fr.free.nrw.commons.location.LatLng getLastMapFocus() {
10371030

10381031
@Override
10391032
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+
}
10421049
return latLnge;
10431050
}
10441051

@@ -1318,7 +1325,7 @@ public void setTabItemContributions() {
13181325
@Override
13191326
public void checkPermissionsAndPerformAction() {
13201327
Timber.d("Checking permission and perfoming action");
1321-
locationPermissionLauncher.launch(new String[]{permission.ACCESS_FINE_LOCATION});
1328+
locationPermissionLauncher.launch(permission.ACCESS_FINE_LOCATION);
13221329
}
13231330

13241331
/**
@@ -1623,7 +1630,7 @@ public fr.free.nrw.commons.location.LatLng getCameraTarget() {
16231630
*/
16241631
public void updateMarker(final boolean isBookmarked, final Place place,
16251632
@Nullable final fr.free.nrw.commons.location.LatLng curLatLng) {
1626-
addMarkerToMap(place, isBookmarked);
1633+
addMarkerToMap(place, isBookmarked);
16271634
}
16281635

16291636
private @DrawableRes int getIconFor(Place place, Boolean isBookmarked) {
@@ -1741,7 +1748,7 @@ private void removeMarker(Place place){
17411748
mapView.invalidate();
17421749
break;
17431750
}
1744-
}
1751+
}
17451752
}
17461753
}
17471754

0 commit comments

Comments
 (0)