From a3c6734f70e3d687ba79bdd88abc671ac96c4cac Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Thu, 12 Sep 2019 16:14:27 +0300 Subject: [PATCH] Fix the issues with updating search nearby markers and camera position together --- .../nearby/NearbyTestLayersFragment.java | 51 ++++++++++++++----- .../commons/nearby/SupportMapFragment.java | 12 +++-- .../NearbyParentFragmentContract.java | 2 +- .../mvp/fragments/NearbyParentFragment.java | 2 +- .../NearbyParentFragmentPresenter.java | 32 +++++++++--- 5 files changed, 70 insertions(+), 29 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 9fc74aa6c..efee6fe4c 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 @@ -435,23 +435,43 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple if (curlatLng.equals(searchLatLng)) { // Means we are checking around current location Log.d("denemeTestt","checking around current location1"); checkingAroundCurretLocation = true; + compositeDisposable.add(Observable.fromCallable(() -> nearbyController + .loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurretLocation)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(this::updateMapMarkers, + throwable -> { + Timber.d(throwable); + //showErrorMessage(getString(R.string.error_fetching_nearby_places)); + // TODO solve first unneeded method call here + //progressBar.setVisibility(View.GONE); + //nearbyParentFragmentPresenter.lockUnlockNearby(false); + })); } else { Log.d("denemeTestt","not checking around current location2"); checkingAroundCurretLocation = false; + compositeDisposable.add(Observable.fromCallable(() -> nearbyController + .loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurretLocation)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(this::updateMapMarkersForCustomLocation, + throwable -> { + Timber.d(throwable); + //showErrorMessage(getString(R.string.error_fetching_nearby_places)); + // TODO solve first unneeded method call here + //progressBar.setVisibility(View.GONE); + //nearbyParentFragmentPresenter.lockUnlockNearby(false); + })); } + } - compositeDisposable.add(Observable.fromCallable(() -> nearbyController - .loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurretLocation)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::updateMapMarkers, - throwable -> { - Timber.d(throwable); - //showErrorMessage(getString(R.string.error_fetching_nearby_places)); - // TODO solve first unneeded method call here - //progressBar.setVisibility(View.GONE); - //nearbyParentFragmentPresenter.lockNearby(false); - })); + /** + * Populates places for your location, should be used for finding nearby places around a + * location where you are. + * @param nearbyPlacesInfo This variable has place list information and distances. + */ + private void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { + nearbyParentFragmentPresenter.updateMapMarkers(nearbyPlacesInfo, selectedMarker); } /** @@ -459,10 +479,13 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple * location where you are not at. * @param nearbyPlacesInfo This variable has place list information and distances. */ - private void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { - nearbyParentFragmentPresenter.updateMapMarkers(nearbyPlacesInfo, selectedMarker); + private void updateMapMarkersForCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { + nearbyParentFragmentPresenter.updateMapMarkersForCustomLocation(nearbyPlacesInfo, selectedMarker); } + + + @Override public boolean isBottomSheetExpanded() { return false; diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/SupportMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/SupportMapFragment.java index 5d4929e26..5b072262e 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/SupportMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/SupportMapFragment.java @@ -23,6 +23,7 @@ import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.maps.MapFragment; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; @@ -283,9 +284,7 @@ public class SupportMapFragment extends CommonsDaggerSupportFragment bookmarkLocationDao.getAllBookmarksLocations()); mapboxMap.clear(); // TODO: set search latlang here - CameraPosition cameraPosition = new CameraPosition.Builder().target - (LocationUtils.commonsLatLngToMapBoxLatLng(latLng)).build(); - mapboxMap.setCameraPosition(cameraPosition); + /*mapboxMap.animateCamera(CameraUpdateFactory .newCameraPosition(cameraPosition), 1000);*/ // TODO: set position depening to botom sheet position heere @@ -293,12 +292,15 @@ public class SupportMapFragment extends CommonsDaggerSupportFragment addNearbyMarkersToMapBoxMap(customBaseMarkerOptions, selectedMarker, nearbyParentFragmentPresenter); // Re-enable mapbox gestures on custom location markers load mapboxMap.getUiSettings().setAllGesturesEnabled(true); - updateMapToTrackPosition(latLng); } @Override public void updateMapToTrackPosition(LatLng curLatLng) { - addCurrentLocationMarker(curLatLng); + CameraPosition cameraPosition = new CameraPosition.Builder().target + (LocationUtils.commonsLatLngToMapBoxLatLng(curLatLng)).build(); + mapboxMap.setCameraPosition(cameraPosition); + mapboxMap.animateCamera(CameraUpdateFactory + .newCameraPosition(cameraPosition), 1000); } @Override 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 c81cccdb6..2aa00a970 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 @@ -43,7 +43,7 @@ public interface NearbyParentFragmentContract { void onTabSelected(); void initializeNearbyOperations(); void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget); - void lockNearby(boolean isNearbyLocked); + void lockUnlockNearby(boolean isNearbyLocked); void setActionListeners(JsonKvStore applicationKvStore); MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap); 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 b44738d50..d9351cf11 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 @@ -224,7 +224,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment //showErrorMessage(getString(R.string.error_fetching_nearby_places)); // TODO solve first unneeded method call here progressBar.setVisibility(View.GONE); - //nearbyParentFragmentPresenter.lockNearby(false); + //nearbyParentFragmentPresenter.lockUnlockNearby(false); })); } 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 01dfbad0e..d0c146bb0 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 @@ -13,7 +13,6 @@ import fr.free.nrw.commons.location.LocationUpdateListener; import fr.free.nrw.commons.nearby.NearbyController; 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.fragments.NearbyParentFragment; import fr.free.nrw.commons.utils.LocationUtils; import fr.free.nrw.commons.wikidata.WikidataEditListener; @@ -111,7 +110,6 @@ public class NearbyParentFragmentPresenter Timber.d("performNearbyOperationsIfPermissionGiven"); //nearbyParentFragmentView.registerLocationUpdates(locationServiceManager); // Nearby buttons should be active, they should be inactive only during update - //lockNearby(false); // This will start a consequence to check GPS depending on different API //nearbyParentFragmentView.checkGps(locationServiceManager); // We will know when we went offline and online again @@ -147,7 +145,8 @@ public class NearbyParentFragmentPresenter Log.d("denemeTest","initializeMapOperations"); nearbyParentFragmentView.initViewPositions(); - lockNearby(false); + lockUnlockNearby(false); + registerUnregisterLocationListener(false); nearbyParentFragmentView.addNetworkBroadcastReceiver(); Timber.d("Nearby map view is created and ready"); @@ -193,9 +192,12 @@ public class NearbyParentFragmentPresenter * @param isNearbyLocked true means lock, false means unlock */ @Override - public void lockNearby(boolean isNearbyLocked) { + public void lockUnlockNearby(boolean isNearbyLocked) { this.isNearbyLocked = isNearbyLocked; - if (isNearbyLocked) { + } + + public void registerUnregisterLocationListener(boolean removeLocationListener) { + if (removeLocationListener) { locationServiceManager.unregisterLocationManager(); locationServiceManager.removeLocationListener(this); Timber.d("Nearby locked"); @@ -256,6 +258,7 @@ public class NearbyParentFragmentPresenter if (locationChangeType.equals(LOCATION_SIGNIFICANTLY_CHANGED) || locationChangeType.equals(MAP_UPDATED)) { Log.d("denemeTest","1"); + lockUnlockNearby(true); nearbyParentFragmentView.populatePlaces(lastLocation, lastLocation); nearbyParentFragmentView.setSearchThisAreaProgressVisibility(false); //nearbyMapFragmentView.updateMapToTrackPosition(curLatLng); @@ -264,7 +267,7 @@ public class NearbyParentFragmentPresenter } else if (locationChangeType.equals(SEARCH_CUSTOM_AREA)) { Log.d("denemeTest","2"); - + lockUnlockNearby(true); nearbyParentFragmentView.populatePlaces(lastLocation, cameraTarget); nearbyParentFragmentView.setSearchThisAreaProgressVisibility(false); searchingThisArea = false; @@ -284,7 +287,20 @@ public class NearbyParentFragmentPresenter */ public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo, Marker selectedMarker) { nearbyMapFragmentView.updateMapMarkers(nearbyPlacesInfo.curLatLng, nearbyPlacesInfo.placeList, selectedMarker, this); + nearbyMapFragmentView.addCurrentLocationMarker(nearbyPlacesInfo.curLatLng); nearbyMapFragmentView.updateMapToTrackPosition(nearbyPlacesInfo.curLatLng); + lockUnlockNearby(false); // So that new location updates wont come + } + + /** + * Populates places for custom location, should be used for finding nearby places around a + * location where you are not at. + * @param nearbyPlacesInfo This variable has place list information and distances. + */ + public void updateMapMarkersForCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo, Marker selectedMarker) { + nearbyMapFragmentView.updateMapMarkers(nearbyPlacesInfo.curLatLng, nearbyPlacesInfo.placeList, selectedMarker, this); + nearbyMapFragmentView.addCurrentLocationMarker(nearbyPlacesInfo.curLatLng); + lockUnlockNearby(false); // So that new location updates wont come } @Override @@ -343,7 +359,7 @@ public class NearbyParentFragmentPresenter public void onClick(View v) { Log.d("denemeTestt","onSearchThisAreaClicked"); // Lock map operations during search this area operation - lockNearby(true); + // TODO: test lock nearby nearbyParentFragmentView.setSearchThisAreaProgressVisibility(true); // TODO: make this invisible at somewhere nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false); @@ -353,7 +369,7 @@ public class NearbyParentFragmentPresenter updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null); } else { - Log.d("denemeTestt","!searchCloseToCurrentLocation()"); + Log.d("denemeTestt","!searchCloseToCurrentLocation()+"+getCameraTarget()); updateMapAndList(SEARCH_CUSTOM_AREA, getCameraTarget()); }