From 5eba2b3b7aa008e305e65eb0a5f9d1eef363a64e Mon Sep 17 00:00:00 2001 From: Neslihan Date: Sat, 21 Mar 2020 22:49:55 +0300 Subject: [PATCH 1/3] Add method to check if curr location marker is vsible or not --- .../fragments/NearbyParentFragment.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index 55e0483a93..3919b20b98 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -50,6 +50,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.Style; @@ -201,6 +202,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment private boolean isVisibleToUser; private MapboxMap.OnCameraMoveListener cameraMoveListener; private fr.free.nrw.commons.location.LatLng lastFocusLocation; + private LatLngBounds latLngBounds; @Override @@ -632,6 +634,22 @@ public LatLng getLastFocusLocation() { return lastFocusLocation==null?null:LocationUtils.commonsLatLngToMapBoxLatLng(lastFocusLocation); } + @Override + public boolean isCurrentLocationMarkerVisible() { + if (latLngBounds == null) { + Timber.d("Map projection bounds are null"); + return false; + } else { + Timber.d("Current location marker %s" , latLngBounds.contains(currentLocationMarker.getPosition()) ? "visible" : "invisible"); + return latLngBounds.contains(currentLocationMarker.getPosition()); + } + } + + @Override + public void setProjectorLatLngBounds() { + latLngBounds = mapBox.getProjection().getVisibleRegion().latLngBounds; + } + @Override public boolean isNetworkConnectionEstablished() { return NetworkUtils.isInternetConnectionEstablished(getActivity()); @@ -906,9 +924,8 @@ public void displayLoginSkippedWarning() { } private void handleLocationUpdate(fr.free.nrw.commons.location.LatLng latLng, LocationServiceManager.LocationChangeType locationChangeType){ - setMapBoxPosition(latLng); - this.lastKnownLocation=latLng; - NearbyController.currentLocation=lastKnownLocation; + this.lastKnownLocation = latLng; + NearbyController.currentLocation = lastKnownLocation; presenter.updateMapAndList(locationChangeType); } @@ -941,14 +958,6 @@ public void onLocationChangedMedium(fr.free.nrw.commons.location.LatLng latLng) } } - void setMapBoxPosition(fr.free.nrw.commons.location.LatLng latLng){ - CameraPosition position = new CameraPosition.Builder() - .target(LocationUtils.commonsLatLngToMapBoxLatLng(latLng)) // Sets the new camera position - .zoom(ZOOM_LEVEL) // Same zoom level - .build(); - mapBox.moveCamera(CameraUpdateFactory.newCameraPosition(position)); - } - public void backButtonClicked() { presenter.backButtonClicked(); } From 8c1825546458be4f3be94f93c30ca62d73bea756 Mon Sep 17 00:00:00 2001 From: Neslihan Date: Sat, 21 Mar 2020 22:52:19 +0300 Subject: [PATCH 2/3] Recenter map if users see their current location marker --- .../nearby/presenter/NearbyParentFragmentPresenter.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.java b/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.java index 44c8a549a7..770039295b 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.java @@ -8,8 +8,6 @@ import java.util.HashMap; import java.util.List; -import javax.inject.Inject; - import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao; import fr.free.nrw.commons.kvstore.JsonKvStore; import fr.free.nrw.commons.location.LatLng; @@ -21,9 +19,7 @@ import fr.free.nrw.commons.nearby.NearbyBaseMarker; import fr.free.nrw.commons.nearby.NearbyController; import fr.free.nrw.commons.nearby.NearbyFilterState; -import fr.free.nrw.commons.nearby.Place; import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract; -import fr.free.nrw.commons.upload.UploadContract; import fr.free.nrw.commons.utils.LocationUtils; import fr.free.nrw.commons.wikidata.WikidataEditListener; import timber.log.Timber; @@ -194,7 +190,7 @@ public void updateMapAndList(LocationServiceManager.LocationChangeType locationC nearbyParentFragmentView.populatePlaces(nearbyParentFragmentView.getCameraTarget()); } else { // Means location changed slightly, ie user is walking or driving. Timber.d("Means location changed slightly"); - if (!nearbyParentFragmentView.isSearchThisAreaButtonVisible()) { // Do not track users position if the user is checking around + if (nearbyParentFragmentView.isCurrentLocationMarkerVisible()){ // Means user wants to see their live location nearbyParentFragmentView.recenterMap(curLatLng); } } @@ -259,6 +255,7 @@ public void onLocationChangedMedium(LatLng latLng) { @Override public void onCameraMove(com.mapbox.mapboxsdk.geometry.LatLng latLng) { + nearbyParentFragmentView.setProjectorLatLngBounds(); // If our nearby markers are calculated at least once if (NearbyController.latestSearchLocation != null) { double distance =latLng.distanceTo From f6b9b0d89a36a548863f5c47541cf4cebbe7b078 Mon Sep 17 00:00:00 2001 From: Neslihan Date: Sat, 21 Mar 2020 22:52:51 +0300 Subject: [PATCH 3/3] Add new methods to Contract --- .../commons/nearby/contract/NearbyParentFragmentContract.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java b/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java index 1034ab4370..6c71b07645 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java @@ -71,6 +71,9 @@ interface View { LatLng getLastLocation(); com.mapbox.mapboxsdk.geometry.LatLng getLastFocusLocation(); + + boolean isCurrentLocationMarkerVisible(); + void setProjectorLatLngBounds(); } interface NearbyListView {