Skip to content

Commit

Permalink
Resolves Issue commons-app#5413
Browse files Browse the repository at this point in the history
  • Loading branch information
ShashwatKedia committed Jan 3, 2024
1 parent 4b2d6d3 commit baf458c
Showing 1 changed file with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,37 +302,30 @@ public void onActivityResult(Map<String, Boolean> result) {
}
});

private ActivityResultLauncher<String[]> locationPermissionLauncher = registerForActivityResult(
new ActivityResultContracts.RequestMultiplePermissions(),
new ActivityResultCallback<Map<String, Boolean>>() {
@Override
public void onActivityResult(Map<String, Boolean> result) {
boolean areAllGranted = true;
for (final boolean b : result.values()) {
areAllGranted = areAllGranted && b;
}

if (areAllGranted) {
locationPermissionGranted();
private ActivityResultLauncher<String> locationPermissionLauncher = registerForActivityResult(
new ActivityResultContracts.RequestPermission(), isGranted ->{
if(isGranted)
{
locationPermissionGranted();
}
else {
if (shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
DialogUtil.showAlertDialog(getActivity(),
getActivity().getString(R.string.location_permission_title),
getActivity().getString(R.string.location_permission_rationale_nearby),
getActivity().getString(android.R.string.ok),
getActivity().getString(android.R.string.cancel),
() -> {
if (!(locationManager.isNetworkProviderEnabled()
|| locationManager.isGPSProviderEnabled())) {
showLocationOffDialog();
}
},
() -> isPermissionDenied = true,
null,
false);
} else {
if (shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
DialogUtil.showAlertDialog(getActivity(),
getActivity().getString(R.string.location_permission_title),
getActivity().getString(R.string.location_permission_rationale_nearby),
getActivity().getString(android.R.string.ok),
getActivity().getString(android.R.string.cancel),
() -> {
if (!(locationManager.isNetworkProviderEnabled()
|| locationManager.isGPSProviderEnabled())) {
showLocationOffDialog();
}
},
() -> isPermissionDenied = true,
null,
false);
} else {
isPermissionDenied = true;
}
isPermissionDenied = true;
}
}
});
Expand Down Expand Up @@ -1025,8 +1018,22 @@ public fr.free.nrw.commons.location.LatLng getLastMapFocus() {

@Override
public fr.free.nrw.commons.location.LatLng getMapCenter() {
fr.free.nrw.commons.location.LatLng latLnge = new fr.free.nrw.commons.location.LatLng(
mapCenter.getLatitude(), mapCenter.getLongitude(), 100);
if (applicationKvStore.getString("LastLocation") != null) {
final String[] locationLatLng
= applicationKvStore.getString("LastLocation").split(",");
lastKnownLocation
= new fr.free.nrw.commons.location.LatLng(Double.parseDouble(locationLatLng[0]),
Double.parseDouble(locationLatLng[1]), 1f);
} else {
lastKnownLocation = new fr.free.nrw.commons.location.LatLng(51.50550,
-0.07520, 1f);
}
fr.free.nrw.commons.location.LatLng latLnge = lastKnownLocation;
if(mapCenter!=null)
{
latLnge = new fr.free.nrw.commons.location.LatLng(
mapCenter.getLatitude(), mapCenter.getLongitude(), 100);
}
return latLnge;
}

Expand Down Expand Up @@ -1306,7 +1313,7 @@ public void setTabItemContributions() {
@Override
public void checkPermissionsAndPerformAction() {
Timber.d("Checking permission and perfoming action");
locationPermissionLauncher.launch(new String[]{permission.ACCESS_FINE_LOCATION});
locationPermissionLauncher.launch(permission.ACCESS_FINE_LOCATION);
}

/**
Expand Down Expand Up @@ -1611,7 +1618,7 @@ public fr.free.nrw.commons.location.LatLng getCameraTarget() {
*/
public void updateMarker(final boolean isBookmarked, final Place place,
@Nullable final fr.free.nrw.commons.location.LatLng curLatLng) {
addMarkerToMap(place, isBookmarked);
addMarkerToMap(place, isBookmarked);
}

private @DrawableRes int getIconFor(Place place, Boolean isBookmarked) {
Expand Down Expand Up @@ -1729,7 +1736,7 @@ private void removeMarker(Place place){
mapView.invalidate();
break;
}
}
}
}
}

Expand Down

0 comments on commit baf458c

Please sign in to comment.