diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java index 0956a61be..c4ee0f067 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java @@ -28,8 +28,10 @@ import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween; public class NearbyController { private static final int MAX_RESULTS = 1000; private final NearbyPlaces nearbyPlaces; - public static double searchedRadius = 10.0; //in kilometers - public static LatLng currentLocation; + public static double currentLocationSearchRadius = 10.0; //in kilometers + public static LatLng currentLocation; // Users latest fetched location + public static LatLng latestSearchLocation; // Can be current and camera target on search this area button is used + public static double latestSearchRadius = 10.0; // Any last search radius except closest result search @Inject public NearbyController(NearbyPlaces nearbyPlaces) { @@ -95,11 +97,18 @@ public class NearbyController { nearbyPlacesInfo.searchLatLng = searchLatLng; nearbyPlacesInfo.placeList = places; nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates; - if (!returnClosestResult && checkingAroundCurrentLocation) { - // Do not update searched radius, if controller is used for nearby card notification - searchedRadius = nearbyPlaces.radius; - currentLocation = curLatLng; + + if (!returnClosestResult) { + latestSearchLocation = searchLatLng; + latestSearchRadius = nearbyPlaces.radius*1000; // to meter + + if (checkingAroundCurrentLocation) { + currentLocationSearchRadius = nearbyPlaces.radius; + currentLocation = curLatLng; + } } + + return nearbyPlacesInfo; } else { diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java index c701c3aae..2b4080dce 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java @@ -579,7 +579,7 @@ public class NearbyMapFragment extends DaggerFragment { .distanceTo(new LatLng(NearbyController.currentLocation.getLatitude() , NearbyController.currentLocation.getLongitude())); - if (distance > NearbyController.searchedRadius*1000*3/4) { //Convert to meter, and compare if our distance is bigger than 3/4 or our searched area + if (distance > NearbyController.currentLocationSearchRadius *1000*3/4) { //Convert to meter, and compare if our distance is bigger than 3/4 or our searched area checkingAround = true; if (!searchThisAreaModeOn) { // If we are changing mode, then change click action searchThisAreaModeOn = true; diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java index 53f110159..b7d531cba 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java @@ -47,6 +47,7 @@ public interface NearbyMapContract { void closeFabs ( boolean isFabOpen); void updateMarker(boolean isBookmarked, Place place); LatLng getCameraTarget(); + MapboxMap getMapboxMap(); void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback); void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener); } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java index bb4da052e..94e4099bc 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java @@ -31,7 +31,7 @@ public interface NearbyParentFragmentContract { void initializeNearbyOperations(); void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget); void lockNearby(boolean isNearbyLocked); - MapboxMap.OnCameraMoveListener onCameraMove(LatLng cameraTarget); + MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap); } interface ViewsAreReadyCallback { diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java index 92329d84e..b34fa1a1f 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java @@ -220,6 +220,8 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N // TODO: arrange camera positions according to all other parameters // TODO: set position depening to botom sheet position heere + mapboxMap.clear(); + addNearbyMarkersToMapBoxMap(customBaseMarkerOptions); // Re-enable mapbox gestures on custom location markers load mapboxMap.getUiSettings().setAllGesturesEnabled(true); @@ -269,9 +271,6 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N */ public void addNearbyMarkersToMapBoxMap(@Nullable List baseMarkerList) { Timber.d("addNearbyMarkersToMapBoxMap is called"); - - mapboxMap.clear(); - mapboxMap.addMarkers(baseMarkerList); mapboxMap.setOnInfoWindowCloseListener(marker -> { /*if (marker == selected) { @@ -402,6 +401,15 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N .mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target); } + /** + * Returns mapbox map current map view + * @return mapbox map + */ + @Override + public MapboxMap getMapboxMap() { + return mapboxMap; + } + @Override public void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener) { mapboxMap.addOnCameraMoveListener(onCameraMoveListener); diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java index f30949714..18661f479 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java @@ -2,12 +2,9 @@ package fr.free.nrw.commons.nearby.mvp.presenter; import android.util.Log; import android.view.View; -import android.widget.Button; import com.mapbox.mapboxsdk.maps.MapboxMap; -import ch.qos.logback.core.util.LocationUtil; -import fr.free.nrw.commons.R; import fr.free.nrw.commons.location.LatLng; import fr.free.nrw.commons.location.LocationServiceManager; import fr.free.nrw.commons.location.LocationUpdateListener; @@ -16,7 +13,6 @@ import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract; import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract; import fr.free.nrw.commons.utils.LocationUtils; -import fr.free.nrw.commons.utils.NetworkUtils; import fr.free.nrw.commons.wikidata.WikidataEditListener; import timber.log.Timber; @@ -97,7 +93,7 @@ public class NearbyParentFragmentPresenter updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null); // TODO: document this prpoblem, if updateMapAndList is not called at checkGPS then this method never called, setup map view never ends this.nearbyParentFragmentView.addSearchThisAreaButtonAction(); - this.nearbyMapFragmentView.addOnCameraMoveListener(onCameraMove(getCameraTarget())); + this.nearbyMapFragmentView.addOnCameraMoveListener(onCameraMove(getMapboxMap())); } @@ -144,6 +140,9 @@ public class NearbyParentFragmentPresenter public LatLng getCameraTarget() { return nearbyMapFragmentView.getCameraTarget(); } + public MapboxMap getMapboxMap() { + return nearbyMapFragmentView.getMapboxMap(); + } /** * This method should be the single point to update Map and List. Triggered by location @@ -234,17 +233,26 @@ public class NearbyParentFragmentPresenter Timber.d("Location changed medium"); } - public MapboxMap.OnCameraMoveListener onCameraMove(LatLng cameraTarget) { + public MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap) { + return () -> { - return new MapboxMap.OnCameraMoveListener() { - @Override - public void onCameraMove() { - // If our nearby markers are calculated at least once - if (NearbyController.currentLocation != null) { - if (nearbyParentFragmentView.isNetworkConnectionEstablished()) { + // If our nearby markers are calculated at least once + if (NearbyController.currentLocation != null) { + double distance = mapboxMap.getCameraPosition().target.distanceTo + (LocationUtils.commonsLatLngToMapBoxLatLng(NearbyController.latestSearchLocation)); + Log.d("deneme2", "NearbyController.currentLocation != null"); + if (nearbyParentFragmentView.isNetworkConnectionEstablished()) { + if (distance > NearbyController.latestSearchRadius) { + Log.d("deneme2", "distance:" + distance + " , searched rad:" + NearbyController.latestSearchRadius); nearbyParentFragmentView.setSearchThisAreaButtonVisibility(true); + } else { + Log.d("deneme2", "distance:" + distance + " , searched rad:" + NearbyController.latestSearchRadius); + + nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false); } } + } else { + nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false); } }; } @@ -279,7 +287,7 @@ public class NearbyParentFragmentPresenter double distance = LocationUtils.commonsLatLngToMapBoxLatLng(getCameraTarget()) .distanceTo(new com.mapbox.mapboxsdk.geometry.LatLng(NearbyController.currentLocation.getLatitude() , NearbyController.currentLocation.getLongitude())); - if (distance > NearbyController.searchedRadius * 1000 * 3 / 4) { + if (distance > NearbyController.currentLocationSearchRadius * 1000 * 3 / 4) { return false; } else { return true;