8000 Resolves Issue #5413 · commons-app/apps-android-commons@baf458c · GitHub
Skip to content
Sign in

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit baf458c

Browse files
committed
Resolves Issue #5413
1 parent 4b2d6d3 commit baf458c

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

+42-35
Original file line numberDiff line numberDiff line change
@@ -302,37 +302,30 @@ public void onActivityResult(Map<String, Boolean> result) {
302302
}
303303
});
304304

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);
317327
} 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;
336329
}
337330
}
338331
});
@@ -1025,8 +1018,22 @@ public fr.free.nrw.commons.location.LatLng getLastMapFocus() {
10251018

10261019
@Override
10271020
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+
}
10301037
return latLnge;
10311038
}
10321039

@@ -1306,7 +1313,7 @@ public void setTabItemContributions() {
13061313
@Override
13071314
public void checkPermissionsAndPerformAction() {
13081315
Timber.d("Checking permission and perfoming action");
1309-
locationPermissionLauncher.launch(new String[]{permission.ACCESS_FINE_LOCATION});
1316+
locationPermissionLauncher.launch(permission.ACCESS_FINE_LOCATION);
13101317
}
13111318

13121319
/**
@@ -1611,7 +1618,7 @@ public fr.free.nrw.commons.location.LatLng getCameraTarget() {
16111618
*/
16121619
public void updateMarker(final boolean isBookmarked, final Place place,
16131620
@Nullable final fr.free.nrw.commons.location.LatLng curLatLng) {
1614-
addMarkerToMap(place, isBookmarked);
1621+
addMarkerToMap(place, isBookmarked);
16151622
}
16161623

16171624
private @DrawableRes int getIconFor(Place place, Boolean isBookmarked) {
@@ -1729,7 +1736,7 @@ private void removeMarker(Place place){
17291736
mapView.invalidate();
17301737
break;
17311738
}
1732-
}
1739+
}
17331740
}
17341741
}
17351742

0 commit comments

Comments
 (0)