From 13695fdb2b1b786dd30c760b1223158c3c0ace95 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Wed, 11 Sep 2019 16:18:31 +0300 Subject: [PATCH] Fix search this area button visibility issue --- .../nearby/NearbyTestLayersFragment.java | 12 +++++++- .../NearbyParentFragmentContract.java | 3 +- .../mvp/fragments/NearbyParentFragment.java | 2 +- .../NearbyParentFragmentPresenter.java | 28 ++++++++----------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestLayersFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestLayersFragment.java index 01eee6651..9fc74aa6c 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestLayersFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestLayersFragment.java @@ -346,6 +346,7 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple @Override public void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener) { + Log.d("denemeTestt","on camera move listener is set"); mapFragment.getMapboxMap().addOnCameraMoveListener(onCameraMoveListener); } @@ -430,8 +431,17 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple @Override public void populatePlaces(fr.free.nrw.commons.location.LatLng curlatLng, fr.free.nrw.commons.location.LatLng searchLatLng) { + boolean checkingAroundCurretLocation; + if (curlatLng.equals(searchLatLng)) { // Means we are checking around current location + Log.d("denemeTestt","checking around current location1"); + checkingAroundCurretLocation = true; + } else { + Log.d("denemeTestt","not checking around current location2"); + checkingAroundCurretLocation = false; + } + compositeDisposable.add(Observable.fromCallable(() -> nearbyController - .loadAttractionsFromLocation(curlatLng, searchLatLng, false, true)) + .loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurretLocation)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::updateMapMarkers, 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 a5bdb4667..c81cccdb6 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 @@ -44,10 +44,9 @@ public interface NearbyParentFragmentContract { void initializeNearbyOperations(); void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget); void lockNearby(boolean isNearbyLocked); - MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap); void setActionListeners(JsonKvStore applicationKvStore); - 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/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java index ec60f2f89..b44738d50 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java @@ -174,7 +174,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment @Override public void addSearchThisAreaButtonAction() { - searchThisAreaButton.setOnClickListener(nearbyParentFragmentPresenter.onSearchThisAreaClicked()); + //searchThisAreaButton.setOnClickListener(nearbyParentFragmentPresenter.onSearchThisAreaClicked()); } @Override 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 8e427e4c0..01dfbad0e 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 @@ -119,7 +119,7 @@ public class NearbyParentFragmentPresenter //nearbyMapFragmentView.setupMapView(null); //nearbyOperationsInitialized(); this.nearbyParentFragmentView.addSearchThisAreaButtonAction(); - this.nearbyParentFragmentView.addOnCameraMoveListener(onCameraMove(getCameraTarget())); + this.nearbyParentFragmentView.addOnCameraMoveListener(onCameraMove(getMapboxMap())); initializeMapOperations(); } @@ -177,21 +177,6 @@ public class NearbyParentFragmentPresenter } - public MapboxMap.OnCameraMoveListener onCameraMove(LatLng cameraTarget) { - - return new MapboxMap.OnCameraMoveListener() { - @Override - public void onCameraMove() { - // If our nearby markers are calculated at least once - if (NearbyController.currentLocation != null) { - if (nearbyParentFragmentView.isNetworkConnectionEstablished()) { - nearbyParentFragmentView.setSearchThisAreaButtonVisibility(true); - } - } - } - }; - } - public void markerUnselected() { nearbyParentFragmentView.hideBottomSheet(); } @@ -325,17 +310,24 @@ public class NearbyParentFragmentPresenter Timber.d("Location changed medium"); } + @Override public MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap) { + Log.d("denemeTestt","cameramoving1"); + return () -> { + Log.d("denemeTestt","cameramoving2"); // If our nearby markers are calculated at least once if (NearbyController.currentLocation != null) { + Log.d("denemeTestt","NearbyController.currentLocation != null"); double distance = mapboxMap.getCameraPosition().target.distanceTo (LocationUtils.commonsLatLngToMapBoxLatLng(NearbyController.latestSearchLocation)); if (nearbyParentFragmentView.isNetworkConnectionEstablished()) { if (distance > NearbyController.latestSearchRadius) { + Log.d("denemeTestt","distance > NearbyController.latestSearchRadius"); nearbyParentFragmentView.setSearchThisAreaButtonVisibility(true); } else { + Log.d("denemeTestt","distance < NearbyController.latestSearchRadius"); nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false); } } @@ -349,6 +341,7 @@ public class NearbyParentFragmentPresenter return new View.OnClickListener() { @Override public void onClick(View v) { + Log.d("denemeTestt","onSearchThisAreaClicked"); // Lock map operations during search this area operation lockNearby(true); nearbyParentFragmentView.setSearchThisAreaProgressVisibility(true); @@ -356,9 +349,11 @@ public class NearbyParentFragmentPresenter nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false); if (searchCloseToCurrentLocation()){ + Log.d("denemeTestt","searchCloseToCurrentLocation()"); updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null); } else { + Log.d("denemeTestt","!searchCloseToCurrentLocation()"); updateMapAndList(SEARCH_CUSTOM_AREA, getCameraTarget()); } @@ -372,6 +367,7 @@ public class NearbyParentFragmentPresenter * @return Returns true if search this area button is used around our current location */ public boolean searchCloseToCurrentLocation() { + Log.d("denemeTestt","searchCloseToCurrentLocation method"); double distance = LocationUtils.commonsLatLngToMapBoxLatLng(getCameraTarget()) .distanceTo(new com.mapbox.mapboxsdk.geometry.LatLng(NearbyController.currentLocation.getLatitude() , NearbyController.currentLocation.getLongitude()));