mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
* Add method to check if curr location marker is vsible or not * Recenter map if users see their current location marker * Add new methods to Contract
This commit is contained in:
parent
350e95b56a
commit
e7efd7e162
3 changed files with 25 additions and 16 deletions
|
|
@ -71,6 +71,9 @@ public interface NearbyParentFragmentContract {
|
|||
LatLng getLastLocation();
|
||||
|
||||
com.mapbox.mapboxsdk.geometry.LatLng getLastFocusLocation();
|
||||
|
||||
boolean isCurrentLocationMarkerVisible();
|
||||
void setProjectorLatLngBounds();
|
||||
}
|
||||
|
||||
interface NearbyListView {
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
|||
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 class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
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 class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
|
||||
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 class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ import java.lang.reflect.Proxy;
|
|||
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.MarkerPlaceGroup;
|
|||
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 class NearbyParentFragmentPresenter
|
|||
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 class NearbyParentFragmentPresenter
|
|||
|
||||
@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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue