Make search this area button appear at correct time

This commit is contained in:
neslihanturan 2019-06-03 15:19:08 +03:00
parent 5a8c137c87
commit ab7f352bd2
6 changed files with 50 additions and 24 deletions

View file

@ -28,8 +28,10 @@ import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
public class NearbyController { public class NearbyController {
private static final int MAX_RESULTS = 1000; private static final int MAX_RESULTS = 1000;
private final NearbyPlaces nearbyPlaces; private final NearbyPlaces nearbyPlaces;
public static double searchedRadius = 10.0; //in kilometers public static double currentLocationSearchRadius = 10.0; //in kilometers
public static LatLng currentLocation; 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 @Inject
public NearbyController(NearbyPlaces nearbyPlaces) { public NearbyController(NearbyPlaces nearbyPlaces) {
@ -95,11 +97,18 @@ public class NearbyController {
nearbyPlacesInfo.searchLatLng = searchLatLng; nearbyPlacesInfo.searchLatLng = searchLatLng;
nearbyPlacesInfo.placeList = places; nearbyPlacesInfo.placeList = places;
nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates; nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates;
if (!returnClosestResult && checkingAroundCurrentLocation) {
// Do not update searched radius, if controller is used for nearby card notification if (!returnClosestResult) {
searchedRadius = nearbyPlaces.radius; latestSearchLocation = searchLatLng;
latestSearchRadius = nearbyPlaces.radius*1000; // to meter
if (checkingAroundCurrentLocation) {
currentLocationSearchRadius = nearbyPlaces.radius;
currentLocation = curLatLng; currentLocation = curLatLng;
} }
}
return nearbyPlacesInfo; return nearbyPlacesInfo;
} }
else { else {

View file

@ -579,7 +579,7 @@ public class NearbyMapFragment extends DaggerFragment {
.distanceTo(new LatLng(NearbyController.currentLocation.getLatitude() .distanceTo(new LatLng(NearbyController.currentLocation.getLatitude()
, NearbyController.currentLocation.getLongitude())); , 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; checkingAround = true;
if (!searchThisAreaModeOn) { // If we are changing mode, then change click action if (!searchThisAreaModeOn) { // If we are changing mode, then change click action
searchThisAreaModeOn = true; searchThisAreaModeOn = true;

View file

@ -47,6 +47,7 @@ public interface NearbyMapContract {
void closeFabs ( boolean isFabOpen); void closeFabs ( boolean isFabOpen);
void updateMarker(boolean isBookmarked, Place place); void updateMarker(boolean isBookmarked, Place place);
LatLng getCameraTarget(); LatLng getCameraTarget();
MapboxMap getMapboxMap();
void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback); void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener); void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
} }

View file

@ -31,7 +31,7 @@ public interface NearbyParentFragmentContract {
void initializeNearbyOperations(); void initializeNearbyOperations();
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget); void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget);
void lockNearby(boolean isNearbyLocked); void lockNearby(boolean isNearbyLocked);
MapboxMap.OnCameraMoveListener onCameraMove(LatLng cameraTarget); MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap);
} }
interface ViewsAreReadyCallback { interface ViewsAreReadyCallback {

View file

@ -220,6 +220,8 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
// TODO: arrange camera positions according to all other parameters // TODO: arrange camera positions according to all other parameters
// TODO: set position depening to botom sheet position heere // TODO: set position depening to botom sheet position heere
mapboxMap.clear();
addNearbyMarkersToMapBoxMap(customBaseMarkerOptions); addNearbyMarkersToMapBoxMap(customBaseMarkerOptions);
// Re-enable mapbox gestures on custom location markers load // Re-enable mapbox gestures on custom location markers load
mapboxMap.getUiSettings().setAllGesturesEnabled(true); mapboxMap.getUiSettings().setAllGesturesEnabled(true);
@ -269,9 +271,6 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
*/ */
public void addNearbyMarkersToMapBoxMap(@Nullable List<NearbyBaseMarker> baseMarkerList) { public void addNearbyMarkersToMapBoxMap(@Nullable List<NearbyBaseMarker> baseMarkerList) {
Timber.d("addNearbyMarkersToMapBoxMap is called"); Timber.d("addNearbyMarkersToMapBoxMap is called");
mapboxMap.clear();
mapboxMap.addMarkers(baseMarkerList); mapboxMap.addMarkers(baseMarkerList);
mapboxMap.setOnInfoWindowCloseListener(marker -> { mapboxMap.setOnInfoWindowCloseListener(marker -> {
/*if (marker == selected) { /*if (marker == selected) {
@ -402,6 +401,15 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
.mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target); .mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target);
} }
/**
* Returns mapbox map current map view
* @return mapbox map
*/
@Override
public MapboxMap getMapboxMap() {
return mapboxMap;
}
@Override @Override
public void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener) { public void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener) {
mapboxMap.addOnCameraMoveListener(onCameraMoveListener); mapboxMap.addOnCameraMoveListener(onCameraMoveListener);

View file

@ -2,12 +2,9 @@ package fr.free.nrw.commons.nearby.mvp.presenter;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button;
import com.mapbox.mapboxsdk.maps.MapboxMap; 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.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager; import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.location.LocationUpdateListener; 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.nearby.mvp.contract.NearbyParentFragmentContract;
import fr.free.nrw.commons.utils.LocationUtils; import fr.free.nrw.commons.utils.LocationUtils;
import fr.free.nrw.commons.utils.NetworkUtils;
import fr.free.nrw.commons.wikidata.WikidataEditListener; import fr.free.nrw.commons.wikidata.WikidataEditListener;
import timber.log.Timber; import timber.log.Timber;
@ -97,7 +93,7 @@ public class NearbyParentFragmentPresenter
updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null); 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 // 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.nearbyParentFragmentView.addSearchThisAreaButtonAction();
this.nearbyMapFragmentView.addOnCameraMoveListener(onCameraMove(getCameraTarget())); this.nearbyMapFragmentView.addOnCameraMoveListener(onCameraMove(getMapboxMap()));
} }
@ -144,6 +140,9 @@ public class NearbyParentFragmentPresenter
public LatLng getCameraTarget() { public LatLng getCameraTarget() {
return nearbyMapFragmentView.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 * 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"); 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 our nearby markers are calculated at least once
if (NearbyController.currentLocation != null) { if (NearbyController.currentLocation != null) {
double distance = mapboxMap.getCameraPosition().target.distanceTo
(LocationUtils.commonsLatLngToMapBoxLatLng(NearbyController.latestSearchLocation));
Log.d("deneme2", "NearbyController.currentLocation != null");
if (nearbyParentFragmentView.isNetworkConnectionEstablished()) { if (nearbyParentFragmentView.isNetworkConnectionEstablished()) {
if (distance > NearbyController.latestSearchRadius) {
Log.d("deneme2", "distance:" + distance + " , searched rad:" + NearbyController.latestSearchRadius);
nearbyParentFragmentView.setSearchThisAreaButtonVisibility(true); 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()) double distance = LocationUtils.commonsLatLngToMapBoxLatLng(getCameraTarget())
.distanceTo(new com.mapbox.mapboxsdk.geometry.LatLng(NearbyController.currentLocation.getLatitude() .distanceTo(new com.mapbox.mapboxsdk.geometry.LatLng(NearbyController.currentLocation.getLatitude()
, NearbyController.currentLocation.getLongitude())); , NearbyController.currentLocation.getLongitude()));
if (distance > NearbyController.searchedRadius * 1000 * 3 / 4) { if (distance > NearbyController.currentLocationSearchRadius * 1000 * 3 / 4) {
return false; return false;
} else { } else {
return true; return true;