mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
* Added ability to access nearby tab without location permissions * added ability to remember user choice if the permission is denied. * fixed the issue with permission dialog box in contribution tab. * changed name for stored variables * minor change Co-authored-by: Pratham2305 <Pratham2305@users.noreply.github.com>
This commit is contained in:
parent
ba000eb26e
commit
630c2a5dcd
4 changed files with 90 additions and 36 deletions
|
|
@ -454,6 +454,7 @@ public class ContributionsFragment
|
||||||
onLocationPermissionGranted();
|
onLocationPermissionGranted();
|
||||||
} else if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)
|
} else if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||||
&& store.getBoolean("displayLocationPermissionForCardView", true)
|
&& store.getBoolean("displayLocationPermissionForCardView", true)
|
||||||
|
&& !store.getBoolean("doNotAskForLocationPermission", false)
|
||||||
&& (((MainActivity) getActivity()).activeFragment == ActiveFragment.CONTRIBUTIONS)) {
|
&& (((MainActivity) getActivity()).activeFragment == ActiveFragment.CONTRIBUTIONS)) {
|
||||||
nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.ENABLE_LOCATION_PERMISSION;
|
nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.ENABLE_LOCATION_PERMISSION;
|
||||||
showNearbyCardPermissionRationale();
|
showNearbyCardPermissionRationale();
|
||||||
|
|
@ -486,6 +487,7 @@ public class ContributionsFragment
|
||||||
|
|
||||||
private void displayYouWontSeeNearbyMessage() {
|
private void displayYouWontSeeNearbyMessage() {
|
||||||
ViewUtil.showLongToast(getActivity(), getResources().getString(R.string.unable_to_display_nearest_place));
|
ViewUtil.showLongToast(getActivity(), getResources().getString(R.string.unable_to_display_nearest_place));
|
||||||
|
store.putBoolean("doNotAskForLocationPermission", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public interface NearbyParentFragmentContract {
|
||||||
void listOptionMenuItemClicked();
|
void listOptionMenuItemClicked();
|
||||||
void populatePlaces(LatLng curlatLng);
|
void populatePlaces(LatLng curlatLng);
|
||||||
boolean isListBottomSheetExpanded();
|
boolean isListBottomSheetExpanded();
|
||||||
void checkPermissionsAndPerformAction(Runnable runnable);
|
void checkPermissionsAndPerformAction();
|
||||||
void displayLoginSkippedWarning();
|
void displayLoginSkippedWarning();
|
||||||
void setFABPlusAction(android.view.View.OnClickListener onClickListener);
|
void setFABPlusAction(android.view.View.OnClickListener onClickListener);
|
||||||
void setFABRecenterAction(android.view.View.OnClickListener onClickListener);
|
void setFABRecenterAction(android.view.View.OnClickListener onClickListener);
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
private Animation rotate_forward;
|
private Animation rotate_forward;
|
||||||
|
|
||||||
private static final float ZOOM_LEVEL = 14f;
|
private static final float ZOOM_LEVEL = 14f;
|
||||||
|
private static final float ZOOM_OUT = 0f;
|
||||||
private final String NETWORK_INTENT_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
|
private final String NETWORK_INTENT_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
|
||||||
private BroadcastReceiver broadcastReceiver;
|
private BroadcastReceiver broadcastReceiver;
|
||||||
private boolean isNetworkErrorOccurred;
|
private boolean isNetworkErrorOccurred;
|
||||||
|
|
@ -206,6 +207,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004;
|
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004;
|
||||||
|
|
||||||
private boolean isMapBoxReady;
|
private boolean isMapBoxReady;
|
||||||
|
private boolean isPermissionDenied;
|
||||||
|
private boolean recenterToUserLocation;
|
||||||
private MapboxMap mapBox;
|
private MapboxMap mapBox;
|
||||||
IntentFilter intentFilter = new IntentFilter(NETWORK_INTENT_ACTION);
|
IntentFilter intentFilter = new IntentFilter(NETWORK_INTENT_ACTION);
|
||||||
private Marker currentLocationMarker;
|
private Marker currentLocationMarker;
|
||||||
|
|
@ -259,6 +262,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
cameraMoveListener= () -> presenter.onCameraMove(mapBox.getCameraPosition().target);
|
cameraMoveListener= () -> presenter.onCameraMove(mapBox.getCameraPosition().target);
|
||||||
addCheckBoxCallback();
|
addCheckBoxCallback();
|
||||||
presenter.attachView(this);
|
presenter.attachView(this);
|
||||||
|
isPermissionDenied = false;
|
||||||
|
recenterToUserLocation = false;
|
||||||
initRvNearbyList();
|
initRvNearbyList();
|
||||||
initThemePreferences();
|
initThemePreferences();
|
||||||
mapView.onCreate(savedInstanceState);
|
mapView.onCreate(savedInstanceState);
|
||||||
|
|
@ -281,7 +286,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
performMapReadyActions();
|
performMapReadyActions();
|
||||||
final CameraPosition cameraPosition = new CameraPosition.Builder()
|
final CameraPosition cameraPosition = new CameraPosition.Builder()
|
||||||
.target(new LatLng(51.50550, -0.07520))
|
.target(new LatLng(51.50550, -0.07520))
|
||||||
.zoom(ZOOM_LEVEL)
|
.zoom(ZOOM_OUT)
|
||||||
.build();
|
.build();
|
||||||
mapBoxMap.setCameraPosition(cameraPosition);
|
mapBoxMap.setCameraPosition(cameraPosition);
|
||||||
|
|
||||||
|
|
@ -342,7 +347,20 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
private void performMapReadyActions() {
|
private void performMapReadyActions() {
|
||||||
if (((MainActivity)getActivity()).activeFragment == ActiveFragment.NEARBY && isMapBoxReady) {
|
if (((MainActivity)getActivity()).activeFragment == ActiveFragment.NEARBY && isMapBoxReady) {
|
||||||
checkPermissionsAndPerformAction(() -> {
|
if(!applicationKvStore.getBoolean("doNotAskForLocationPermission", false) ||
|
||||||
|
PermissionUtils.hasPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)){
|
||||||
|
checkPermissionsAndPerformAction();
|
||||||
|
}else{
|
||||||
|
isPermissionDenied = true;
|
||||||
|
addOnCameraMoveListener();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void locationPermissionGranted() {
|
||||||
|
isPermissionDenied = false;
|
||||||
|
|
||||||
|
applicationKvStore.putBoolean("doNotAskForLocationPermission", false);
|
||||||
lastKnownLocation = locationManager.getLastLocation();
|
lastKnownLocation = locationManager.getLastLocation();
|
||||||
fr.free.nrw.commons.location.LatLng target=lastFocusLocation;
|
fr.free.nrw.commons.location.LatLng target=lastFocusLocation;
|
||||||
if(null==lastFocusLocation){
|
if(null==lastFocusLocation){
|
||||||
|
|
@ -366,8 +384,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
presenter.onMapReady();
|
presenter.onMapReady();
|
||||||
registerUnregisterLocationListener(false);
|
registerUnregisterLocationListener(false);
|
||||||
addOnCameraMoveListener();
|
addOnCameraMoveListener();
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -377,9 +393,30 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
presenter.attachView(this);
|
presenter.attachView(this);
|
||||||
registerNetworkReceiver();
|
registerNetworkReceiver();
|
||||||
if (isResumed() && ((MainActivity)getActivity()).activeFragment == ActiveFragment.NEARBY) {
|
if (isResumed() && ((MainActivity)getActivity()).activeFragment == ActiveFragment.NEARBY) {
|
||||||
|
if(!isPermissionDenied && !applicationKvStore.getBoolean("doNotAskForLocationPermission", false)){
|
||||||
startTheMap();
|
startTheMap();
|
||||||
|
}else{
|
||||||
|
startMapWithoutPermission();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startMapWithoutPermission() {
|
||||||
|
mapView.onStart();
|
||||||
|
|
||||||
|
applicationKvStore.putBoolean("doNotAskForLocationPermission", true);
|
||||||
|
lastKnownLocation = new fr.free.nrw.commons.location.LatLng(51.50550,-0.07520,1f);
|
||||||
|
final CameraPosition position = new CameraPosition.Builder()
|
||||||
|
.target(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation))
|
||||||
|
.zoom(ZOOM_OUT)
|
||||||
|
.build();
|
||||||
|
if(mapBox != null){
|
||||||
|
mapBox.moveCamera(CameraUpdateFactory.newCameraPosition(position));
|
||||||
|
addOnCameraMoveListener();
|
||||||
|
}
|
||||||
|
presenter.onMapReady();
|
||||||
|
removeCurrentLocationMarker();
|
||||||
|
}
|
||||||
|
|
||||||
private void registerNetworkReceiver() {
|
private void registerNetworkReceiver() {
|
||||||
if (getActivity() != null) {
|
if (getActivity() != null) {
|
||||||
|
|
@ -795,11 +832,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void populatePlaces(final fr.free.nrw.commons.location.LatLng curlatLng) {
|
public void populatePlaces(final fr.free.nrw.commons.location.LatLng curlatLng) {
|
||||||
if (curlatLng.equals(lastFocusLocation)|| lastFocusLocation==null) { // Means we are checking around current location
|
if (curlatLng.equals(lastFocusLocation) || lastFocusLocation == null || recenterToUserLocation) { // Means we are checking around current location
|
||||||
populatePlacesForCurrentLocation(lastKnownLocation, curlatLng);
|
populatePlacesForCurrentLocation(lastKnownLocation, curlatLng);
|
||||||
} else {
|
} else {
|
||||||
populatePlacesForAnotherLocation(lastKnownLocation, curlatLng);
|
populatePlacesForAnotherLocation(lastKnownLocation, curlatLng);
|
||||||
}
|
}
|
||||||
|
if(recenterToUserLocation) {
|
||||||
|
recenterToUserLocation = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populatePlacesForCurrentLocation(final fr.free.nrw.commons.location.LatLng curlatLng,
|
private void populatePlacesForCurrentLocation(final fr.free.nrw.commons.location.LatLng curlatLng,
|
||||||
|
|
@ -918,12 +958,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkPermissionsAndPerformAction(final Runnable runnable) {
|
public void checkPermissionsAndPerformAction() {
|
||||||
Timber.d("Checking permission and perfoming action");
|
Timber.d("Checking permission and perfoming action");
|
||||||
PermissionUtils.checkPermissionsAndPerformAction(getActivity(),
|
PermissionUtils.checkPermissionsAndPerformAction(getActivity(),
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||||
runnable,
|
() -> locationPermissionGranted(),
|
||||||
() -> ((MainActivity) getActivity()).setSelectedItemId(NavTab.CONTRIBUTIONS.code()),
|
() -> isPermissionDenied = true,
|
||||||
R.string.location_permission_title,
|
R.string.location_permission_title,
|
||||||
R.string.location_permission_rationale_nearby);
|
R.string.location_permission_rationale_nearby);
|
||||||
}
|
}
|
||||||
|
|
@ -1095,7 +1135,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addCurrentLocationMarker(final fr.free.nrw.commons.location.LatLng curLatLng) {
|
public void addCurrentLocationMarker(final fr.free.nrw.commons.location.LatLng curLatLng) {
|
||||||
if (null != curLatLng) {
|
if (null != curLatLng && !isPermissionDenied) {
|
||||||
ExecutorUtils.get().submit(() -> {
|
ExecutorUtils.get().submit(() -> {
|
||||||
mapView.post(() -> removeCurrentLocationMarker());
|
mapView.post(() -> removeCurrentLocationMarker());
|
||||||
Timber.d("Adds current location marker");
|
Timber.d("Adds current location marker");
|
||||||
|
|
@ -1141,8 +1181,15 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
@Override
|
@Override
|
||||||
public void updateMapToTrackPosition(final fr.free.nrw.commons.location.LatLng curLatLng) {
|
public void updateMapToTrackPosition(final fr.free.nrw.commons.location.LatLng curLatLng) {
|
||||||
Timber.d("Updates map camera to track user position");
|
Timber.d("Updates map camera to track user position");
|
||||||
final CameraPosition cameraPosition = new CameraPosition.Builder().target
|
final CameraPosition cameraPosition;
|
||||||
|
if(isPermissionDenied){
|
||||||
|
cameraPosition = new CameraPosition.Builder().target
|
||||||
(LocationUtils.commonsLatLngToMapBoxLatLng(curLatLng)).build();
|
(LocationUtils.commonsLatLngToMapBoxLatLng(curLatLng)).build();
|
||||||
|
}else{
|
||||||
|
cameraPosition = new CameraPosition.Builder().target
|
||||||
|
(LocationUtils.commonsLatLngToMapBoxLatLng(curLatLng))
|
||||||
|
.zoom(ZOOM_LEVEL).build();
|
||||||
|
}
|
||||||
if(null!=mapBox) {
|
if(null!=mapBox) {
|
||||||
mapBox.setCameraPosition(cameraPosition);
|
mapBox.setCameraPosition(cameraPosition);
|
||||||
mapBox.animateCamera(CameraUpdateFactory
|
mapBox.animateCamera(CameraUpdateFactory
|
||||||
|
|
@ -1326,8 +1373,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recenterMap(final fr.free.nrw.commons.location.LatLng curLatLng) {
|
public void recenterMap(final fr.free.nrw.commons.location.LatLng curLatLng) {
|
||||||
if (curLatLng == null) {
|
if (isPermissionDenied || curLatLng == null) {
|
||||||
if (!(locationManager.isNetworkProviderEnabled() || locationManager.isGPSProviderEnabled())) {
|
recenterToUserLocation = true;
|
||||||
|
checkPermissionsAndPerformAction();
|
||||||
|
if (!isPermissionDenied && !(locationManager.isNetworkProviderEnabled() || locationManager.isGPSProviderEnabled())) {
|
||||||
showLocationOffDialog();
|
showLocationOffDialog();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,10 @@ public class PermissionUtils {
|
||||||
activity.getString(rationaleMessage),
|
activity.getString(rationaleMessage),
|
||||||
activity.getString(android.R.string.ok),
|
activity.getString(android.R.string.ok),
|
||||||
activity.getString(android.R.string.cancel),
|
activity.getString(android.R.string.cancel),
|
||||||
token::continuePermissionRequest, token::cancelPermissionRequest);
|
token::continuePermissionRequest,
|
||||||
|
token::cancelPermissionRequest,
|
||||||
|
null,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.check();
|
.check();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue