nearbyPlacesInfoObservable = Observable
.fromCallable(() -> nearbyController
.loadAttractionsFromLocation(curlatLng, searchLatLng,
@@ -1173,14 +1208,17 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
showErrorMessage(getString(R.string.no_nearby_places_around));
} else {
// Updating last searched location
- applicationKvStore.putString("LastLocation", searchLatLng.getLatitude() + "," + searchLatLng.getLongitude());
+ applicationKvStore.putString("LastLocation",
+ searchLatLng.getLatitude() + "," + searchLatLng.getLongitude());
updateMapMarkers(nearbyPlacesInfo, false);
- lastFocusLocation = searchLatLng;
+ lastMapFocus = new GeoPoint(searchLatLng.getLatitude(),
+ searchLatLng.getLongitude());
}
},
throwable -> {
Timber.e(throwable);
- showErrorMessage(getString(R.string.error_fetching_nearby_places)+throwable.getLocalizedMessage());
+ showErrorMessage(getString(R.string.error_fetching_nearby_places)
+ + throwable.getLocalizedMessage());
setProgressBarVisibility(false);
presenter.lockUnlockNearby(false);
setFilterState();
@@ -1190,10 +1228,13 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
/**
* 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(final NearbyController.NearbyPlacesInfo nearbyPlacesInfo, final boolean shouldUpdateSelectedMarker) {
- presenter.updateMapMarkers(nearbyPlacesInfo, selectedMarker,shouldUpdateSelectedMarker);
+ private void updateMapMarkers(final NearbyController.NearbyPlacesInfo nearbyPlacesInfo,
+ final boolean shouldUpdateSelectedMarker) {
+ presenter.updateMapMarkers(nearbyPlacesInfo, selectedMarker, shouldUpdateSelectedMarker);
+ //TODO
setFilterState();
}
@@ -1231,21 +1272,18 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
}
- @Override
- public boolean isSearchThisAreaButtonVisible() {
- return searchThisAreaButton.getVisibility() == View.VISIBLE;
- }
-
@Override
public void setRecyclerViewAdapterAllSelected() {
- if (nearbyFilterSearchRecyclerViewAdapter != null && NearbyController.currentLocation != null) {
+ if (nearbyFilterSearchRecyclerViewAdapter != null
+ && NearbyController.currentLocation != null) {
nearbyFilterSearchRecyclerViewAdapter.setRecyclerViewAdapterAllSelected();
}
}
@Override
public void setRecyclerViewAdapterItemsGreyedOut() {
- if (nearbyFilterSearchRecyclerViewAdapter != null && NearbyController.currentLocation != null) {
+ if (nearbyFilterSearchRecyclerViewAdapter != null
+ && NearbyController.currentLocation != null) {
nearbyFilterSearchRecyclerViewAdapter.setRecyclerViewAdapterItemsGreyedOut();
}
}
@@ -1261,7 +1299,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override
public void setTabItemContributions() {
- ((MainActivity)getActivity()).viewPager.setCurrentItem(0);
+ ((MainActivity) getActivity()).viewPager.setCurrentItem(0);
// TODO
}
@@ -1276,7 +1314,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
*/
@Override
public void animateFABs() {
- if (fabPlus.isShown()){
+ if (fabPlus.isShown()) {
if (isFABsExpanded) {
collapseFABs(isFABsExpanded);
} else {
@@ -1288,15 +1326,18 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
private void showFABs() {
NearbyFABUtils.addAnchorToBigFABs(fabPlus, bottomSheetDetails.getId());
fabPlus.show();
- NearbyFABUtils.addAnchorToSmallFABs(fabGallery, getView().findViewById(R.id.empty_view).getId());
- NearbyFABUtils.addAnchorToSmallFABs(fabCamera, getView().findViewById(R.id.empty_view1).getId());
+ NearbyFABUtils.addAnchorToSmallFABs(fabGallery,
+ getView().findViewById(R.id.empty_view).getId());
+ NearbyFABUtils.addAnchorToSmallFABs(fabCamera,
+ getView().findViewById(R.id.empty_view1).getId());
}
/**
* Expands camera and gallery FABs, turn forward plus FAB
+ *
* @param isFABsExpanded true if they are already expanded
*/
- private void expandFABs(final boolean isFABsExpanded){
+ private void expandFABs(final boolean isFABsExpanded) {
if (!isFABsExpanded) {
showFABs();
fabPlus.startAnimation(rotate_forward);
@@ -1322,9 +1363,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
/**
* Collapses camera and gallery FABs, turn back plus FAB
+ *
* @param isFABsExpanded
*/
- private void collapseFABs(final boolean isFABsExpanded){
+ private void collapseFABs(final boolean isFABsExpanded) {
if (isFABsExpanded) {
fabPlus.startAnimation(rotate_backward);
fabCamera.startAnimation(fab_close);
@@ -1340,48 +1382,44 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
if (applicationKvStore.getBoolean("login_skipped", false)) {
// prompt the user to login
new AlertDialog.Builder(getContext())
- .setMessage(R.string.login_alert_message)
- .setPositiveButton(R.string.login, (dialog, which) -> {
- // logout of the app
- BaseLogoutListener logoutListener = new BaseLogoutListener();
- CommonsApplication app = (CommonsApplication) getActivity().getApplication();
- app.clearApplicationData(getContext(), logoutListener);
- })
- .show();
+ .setMessage(R.string.login_alert_message)
+ .setPositiveButton(R.string.login, (dialog, which) -> {
+ // logout of the app
+ BaseLogoutListener logoutListener = new BaseLogoutListener();
+ CommonsApplication app = (CommonsApplication) getActivity().getApplication();
+ app.clearApplicationData(getContext(), logoutListener);
+ })
+ .show();
}
}
- private void handleLocationUpdate(final fr.free.nrw.commons.location.LatLng latLng, final LocationServiceManager.LocationChangeType locationChangeType){
+ private void handleLocationUpdate(final fr.free.nrw.commons.location.LatLng latLng,
+ final LocationServiceManager.LocationChangeType locationChangeType) {
lastKnownLocation = latLng;
NearbyController.currentLocation = lastKnownLocation;
presenter.updateMapAndList(locationChangeType);
}
- private boolean isUserBrowsing() {
- final boolean isUserBrowsing = lastKnownLocation!=null && !presenter.areLocationsClose(getCameraTarget(), lastKnownLocation);
- return isUserBrowsing;
- }
-
@Override
public void onLocationChangedSignificantly(final fr.free.nrw.commons.location.LatLng latLng) {
Timber.d("Location significantly changed");
- if (isMapBoxReady && latLng != null &&!isUserBrowsing()) {
- handleLocationUpdate(latLng,LOCATION_SIGNIFICANTLY_CHANGED);
+ if (latLng != null) {
+ handleLocationUpdate(latLng, LOCATION_SIGNIFICANTLY_CHANGED);
}
}
@Override
public void onLocationChangedSlightly(final fr.free.nrw.commons.location.LatLng latLng) {
Timber.d("Location slightly changed");
- if (isMapBoxReady && latLng != null &&!isUserBrowsing()) {//If the map has never ever shown the current location, lets do it know
- handleLocationUpdate(latLng,LOCATION_SLIGHTLY_CHANGED);
+ if (latLng != null) {//If the map has never ever shown the current location, lets do it know
+ handleLocationUpdate(latLng, LOCATION_SLIGHTLY_CHANGED);
}
}
@Override
public void onLocationChangedMedium(final fr.free.nrw.commons.location.LatLng latLng) {
Timber.d("Location changed medium");
- if (isMapBoxReady && latLng != null && !isUserBrowsing()) {//If the map has never ever shown the current location, lets do it know
+ if (latLng != null) {//If the map has never ever shown the current location, lets do it know
handleLocationUpdate(latLng, LOCATION_SIGNIFICANTLY_CHANGED);
}
}
@@ -1391,13 +1429,15 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
/**
- * onLogoutComplete is called after shared preferences and data stored in local database are cleared.
+ * onLogoutComplete is called after shared preferences and data stored in local database are
+ * cleared.
*/
private class BaseLogoutListener implements CommonsApplication.LogoutListener {
+
@Override
public void onLogoutComplete() {
Timber.d("Logout complete callback received.");
- final Intent nearbyIntent = new Intent( getActivity(), LoginActivity.class);
+ final Intent nearbyIntent = new Intent(getActivity(), LoginActivity.class);
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(nearbyIntent);
@@ -1426,97 +1466,51 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
/**
- * Adds a marker for the user's current position. Adds a
- * circle which uses the accuracy * 2, to draw a circle
- * which represents the user's position with an accuracy
- * of 95%.
+ * Adds a marker for the user's current position. Adds a circle which uses the accuracy * 2, to
+ * draw a circle which represents the user's position with an accuracy of 95%.
+ *
+ * Should be called only on creation of mapboxMap, there is other method to update markers
+ * location with users move.
*
- * Should be called only on creation of mapboxMap, there
- * is other method to update markers location with users
- * move.
* @param curLatLng current location
*/
@Override
public void addCurrentLocationMarker(final fr.free.nrw.commons.location.LatLng curLatLng) {
if (null != curLatLng && !isPermissionDenied && locationManager.isGPSProviderEnabled()) {
ExecutorUtils.get().submit(() -> {
- mapView.post(() -> removeCurrentLocationMarker());
Timber.d("Adds current location marker");
-
- final Icon icon = IconFactory.getInstance(getContext())
- .fromResource(R.drawable.current_location_marker);
-
- final MarkerOptions currentLocationMarkerOptions = new MarkerOptions()
- .position(new LatLng(curLatLng.getLatitude(),
- curLatLng.getLongitude()));
- currentLocationMarkerOptions.setIcon(icon); // Set custom icon
- mapView.post(
- () -> currentLocationMarker = mapBox.addMarker(currentLocationMarkerOptions));
-
- final List circle = UiUtils
- .createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
- curLatLng.getAccuracy() * 2, 100);
-
- final PolygonOptions currentLocationPolygonOptions = new PolygonOptions()
- .addAll(circle)
- .strokeColor(getResources().getColor(R.color.current_marker_stroke))
- .fillColor(getResources().getColor(R.color.current_marker_fill));
- mapView.post(
- () -> currentLocationPolygon = mapBox
- .addPolygon(currentLocationPolygonOptions));
+ recenterMarkerToPosition(
+ new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude()));
});
} else {
Timber.d("not adding current location marker..current location is null");
}
}
- private void removeCurrentLocationMarker() {
- if (currentLocationMarker != null && mapBox!=null) {
- mapBox.removeMarker(currentLocationMarker);
- if (currentLocationPolygon != null) {
- mapBox.removePolygon(currentLocationPolygon);
- }
- }
- }
-
-
/**
* Makes map camera follow users location with animation
+ *
* @param curLatLng current location of user
*/
@Override
public void updateMapToTrackPosition(final fr.free.nrw.commons.location.LatLng curLatLng) {
Timber.d("Updates map camera to track user position");
- final CameraPosition cameraPosition;
- if(isPermissionDenied){
- cameraPosition = new CameraPosition.Builder().target
- (LocationUtils.commonsLatLngToMapBoxLatLng(curLatLng)).build();
- }else{
- cameraPosition = new CameraPosition.Builder().target
- (LocationUtils.commonsLatLngToMapBoxLatLng(curLatLng))
- .zoom(ZOOM_LEVEL).build();
- }
- if(null!=mapBox) {
- mapBox.setCameraPosition(cameraPosition);
- mapBox.animateCamera(CameraUpdateFactory
- .newCameraPosition(cameraPosition), 1000);
+ if (null != mapView) {
+ recenterMap(curLatLng);
}
}
@Override
- public void updateMapMarkers(final List nearbyBaseMarkers, final Marker selectedMarker) {
- if(mapBox!=null && isMapBoxReady){
- mapBox.clear();
- addNearbyMarkersToMapBoxMap(nearbyBaseMarkers, selectedMarker);
+ public void updateMapMarkers(final List nearbyBaseMarkers,
+ final Marker selectedMarker) {
+ if (mapView != null) {
presenter.updateMapMarkersToController(nearbyBaseMarkers);
- // Re-enable mapbox gestures on custom location markers load
- mapBox.getUiSettings().setAllGesturesEnabled(true);
}
}
@Override
public void filterOutAllMarkers() {
- hideAllMarkers();
+ clearAllMarkers();
}
/**
@@ -1525,16 +1519,18 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override
public void displayAllMarkers() {
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
- updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
+ updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(),
+ NearbyController.currentLocation);
}
}
/**
* Filters markers based on selectedLabels and chips
- * @param selectedLabels label list that user clicked
- * @param displayExists chip for displaying only existing places
- * @param displayNeedsPhoto chip for displaying only places need photos
- * @param filterForPlaceState true if we filter places for place state
+ *
+ * @param selectedLabels label list that user clicked
+ * @param displayExists chip for displaying only existing places
+ * @param displayNeedsPhoto chip for displaying only places need photos
+ * @param filterForPlaceState true if we filter places for place state
* @param filterForAllNoneType true if we filter places with all none button
*/
@Override
@@ -1544,20 +1540,16 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
final boolean displayWlm,
final boolean filterForPlaceState,
final boolean filterForAllNoneType) {
-
// Remove the previous markers before updating them
- hideAllMarkers();
-
- filteredMarkers = new ArrayList<>();
-
+ clearAllMarkers();
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
final Place place = markerPlaceGroup.getPlace();
-
// When label filter is engaged
// then compare it against place's label
if (selectedLabels != null && (selectedLabels.size() != 0 || !filterForPlaceState)
&& (!selectedLabels.contains(place.getLabel())
- && !(selectedLabels.contains(Label.BOOKMARKS) && markerPlaceGroup.getIsBookmarked()))) {
+ && !(selectedLabels.contains(Label.BOOKMARKS)
+ && markerPlaceGroup.getIsBookmarked()))) {
continue;
}
@@ -1565,93 +1557,67 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
continue;
}
- boolean shouldUpdateMarker=false;
+ boolean shouldUpdateMarker = false;
if (displayWlm && place.isMonument()) {
- shouldUpdateMarker=true;
- }
- else if (displayExists && displayNeedsPhoto) {
+ shouldUpdateMarker = true;
+ } else if (displayExists && displayNeedsPhoto) {
// Exists and needs photo
if (place.exists && place.pic.trim().isEmpty()) {
- shouldUpdateMarker=true;
+ shouldUpdateMarker = true;
}
} else if (displayExists && !displayNeedsPhoto) {
// Exists and all included needs and doesn't needs photo
if (place.exists) {
- shouldUpdateMarker=true;
+ shouldUpdateMarker = true;
}
} else if (!displayExists && displayNeedsPhoto) {
// All and only needs photo
if (place.pic.trim().isEmpty()) {
- shouldUpdateMarker=true;
+ shouldUpdateMarker = true;
}
} else if (!displayExists && !displayNeedsPhoto) {
// all
- shouldUpdateMarker=true;
+ shouldUpdateMarker = true;
}
- if(shouldUpdateMarker){
- updateMarker(markerPlaceGroup.getIsBookmarked(), place, NearbyController.currentLocation);
+ if (shouldUpdateMarker) {
+ updateMarker(markerPlaceGroup.getIsBookmarked(), place,
+ NearbyController.currentLocation);
}
}
-
- mapBox.clear();
- mapBox.addMarkers(filteredMarkers);
+ if (selectedLabels == null || selectedLabels.size() == 0) {
+ ArrayList markerArrayList = new ArrayList<>();
+ for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
+ NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
+ nearbyBaseMarker.place(markerPlaceGroup.getPlace());
+ markerArrayList.add(nearbyBaseMarker);
+ }
+ addMarkersToMap(markerArrayList, null);
+ }
}
@Override
public fr.free.nrw.commons.location.LatLng getCameraTarget() {
- return mapBox==null?null:LocationUtils.mapBoxLatLngToCommonsLatLng(mapBox.getCameraPosition().target);
+ return mapView == null ? null : getMapFocus();
}
/**
* Sets marker icon according to marker status. Sets title and distance.
+ *
* @param isBookmarked true if place is bookmarked
* @param place
- * @param curLatLng current location
+ * @param curLatLng current location
*/
- public void updateMarker(final boolean isBookmarked, final Place place, @Nullable final fr.free.nrw.commons.location.LatLng curLatLng) {
- VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(
- getContext().getResources(), getIconFor(place, isBookmarked), getContext().getTheme());
-
- if(curLatLng != null) {
- for (NearbyBaseMarker nearbyMarker : allMarkers) {
- if (nearbyMarker.getMarker().getTitle() != null && nearbyMarker.getMarker().getTitle().equals(place.getName())) {
-
- final Bitmap icon = UiUtils.getBitmap(vectorDrawable);
-
- final String distance = formatDistanceBetween(curLatLng, place.location);
- place.setDistance(distance);
-
- final NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
- nearbyBaseMarker.title(place.name);
- nearbyBaseMarker.position(
- new com.mapbox.mapboxsdk.geometry.LatLng(
- place.location.getLatitude(),
- place.location.getLongitude()));
- nearbyBaseMarker.place(place);
- nearbyBaseMarker.icon(IconFactory.getInstance(getContext())
- .fromBitmap(icon));
- nearbyMarker.setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
- filteredMarkers.add(nearbyBaseMarker);
- }
- }
- } else {
- for (Marker marker : mapBox.getMarkers()) {
- if (marker.getTitle() != null && marker.getTitle().equals(place.getName())) {
-
- final Bitmap icon = UiUtils.getBitmap(vectorDrawable);
- marker.setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
- }
- }
- }
+ public void updateMarker(final boolean isBookmarked, final Place place,
+ @Nullable final fr.free.nrw.commons.location.LatLng curLatLng) {
+ addMarkerToMap(place, isBookmarked);
}
private @DrawableRes int getIconFor(Place place, Boolean isBookmarked) {
- if(place.isMonument()){
+ if (place.isMonument()) {
return R.drawable.ic_custom_map_marker_monuments;
- }
- else if (!place.pic.trim().isEmpty()) {
+ } else if (!place.pic.trim().isEmpty()) {
return (isBookmarked ?
R.drawable.ic_custom_map_marker_green_bookmarked :
R.drawable.ic_custom_map_marker_green);
@@ -1667,46 +1633,103 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
/**
- * Removes all markers except current location marker, an icon has been used
- * but it is transparent more than grey(as the name of the icon might suggest)
- * since grey icon may lead the users to believe that it is disabled or prohibited contribution
+ * Adds a marker representing a place to the map with optional bookmark icon.
+ *
+ * @param place The Place object containing information about the location.
+ * @param isBookMarked A Boolean flag indicating whether the place is bookmarked or not.
*/
- private void hideAllMarkers() {
- final VectorDrawableCompat vectorDrawable;
- vectorDrawable = VectorDrawableCompat.create(
- getContext().getResources(), R.drawable.ic_custom_greyed_out_marker, getContext().getTheme());
- final Bitmap icon = UiUtils.getBitmap(vectorDrawable);
- for (final Marker marker : mapBox.getMarkers()) {
- if (!marker.equals(currentLocationMarker)) {
- marker.setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
- }
- }
- addCurrentLocationMarker(NearbyController.currentLocation);
+ private void addMarkerToMap(Place place, Boolean isBookMarked) {
+ ArrayList items = new ArrayList<>();
+ Drawable icon = ContextCompat.getDrawable(getContext(), getIconFor(place, isBookMarked));
+ GeoPoint point = new GeoPoint(place.location.getLatitude(), place.location.getLongitude());
+ OverlayItem item = new OverlayItem(place.name, null, point);
+ item.setMarker(icon);
+ items.add(item);
+ ItemizedOverlayWithFocus overlay = new ItemizedOverlayWithFocus(items,
+ new OnItemGestureListener() {
+ @Override
+ public boolean onItemSingleTapUp(int index, OverlayItem item) {
+ passInfoToSheet(place);
+ hideBottomSheet();
+ if (clickedMarkerPlace != null) {
+ removeMarker(clickedMarkerPlace);
+ addMarkerToMap(clickedMarkerPlace,isClickedMarkerBookmarked);
+ }
+ clickedMarkerPlace = place;
+ isClickedMarkerBookmarked = isBookMarked ;
+ bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
+ return true;
+ }
+
+ @Override
+ public boolean onItemLongPress(int index, OverlayItem item) {
+ return false;
+ }
+ }, getContext());
+
+ overlay.setFocusItemsOnTap(true);
+ mapView.getOverlays().add(overlay); // Add the overlay to the map
}
- private void addNearbyMarkersToMapBoxMap(final List nearbyBaseMarkers, final Marker selectedMarker) {
- if (isMapBoxReady && mapBox != null) {
- allMarkers = new ArrayList<>(nearbyBaseMarkers);
- mapBox.addMarkers(nearbyBaseMarkers);
- setMapMarkerActions(selectedMarker);
- presenter.updateMapMarkersToController(nearbyBaseMarkers);
+ /**
+ * Adds multiple markers representing places to the map and handles item gestures.
+ *
+ * @param nearbyBaseMarkers The list of Place objects containing information about the
+ * locations.
+ */
+ private void addMarkersToMap(List nearbyBaseMarkers,
+ final Marker selectedMarker) {
+ ArrayList items = new ArrayList<>();
+ for (int i = 0; i < nearbyBaseMarkers.size(); i++) {
+ Drawable icon = ContextCompat.getDrawable(getContext(),
+ getIconFor(nearbyBaseMarkers.get(i).getPlace(), false));
+ GeoPoint point = new GeoPoint(
+ nearbyBaseMarkers.get(i).getPlace().location.getLatitude(),
+ nearbyBaseMarkers.get(i).getPlace().location.getLongitude());
+ OverlayItem item = new OverlayItem(nearbyBaseMarkers.get(i).getPlace().name, null,
+ point);
+ item.setMarker(icon);
+ items.add(item);
}
+ ItemizedOverlayWithFocus overlay = new ItemizedOverlayWithFocus(items,
+ new OnItemGestureListener() {
+ @Override
+ public boolean onItemSingleTapUp(int index, OverlayItem item) {
+ final Place place = nearbyBaseMarkers.get(index).getPlace();
+ passInfoToSheet(place);
+ hideBottomSheet();
+ if (clickedMarkerPlace != null) {
+ removeMarker(clickedMarkerPlace);
+ addMarkerToMap(clickedMarkerPlace,isClickedMarkerBookmarked);
+ }
+ clickedMarkerPlace = place ;
+ isClickedMarkerBookmarked = false ;
+ bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
+ return true;
+ }
+
+ @Override
+ public boolean onItemLongPress(int index, OverlayItem item) {
+ return false;
+ }
+ }, getContext());
+ overlay.setFocusItemsOnTap(true);
+ mapView.getOverlays().add(overlay);
}
- private void setMapMarkerActions(final Marker selectedMarker) {
- if (mapBox != null) {
- mapBox.setOnInfoWindowCloseListener(marker -> {
- if (marker == selectedMarker) {
- presenter.markerUnselected();
+ private void removeMarker(Place place){
+ List overlays = mapView.getOverlays();
+ for (int i = 0; i < overlays.size();i++){
+ if (overlays.get(i) instanceof ItemizedOverlayWithFocus){
+ ItemizedOverlayWithFocus item = (ItemizedOverlayWithFocus)overlays.get(i);
+ OverlayItem overlayItem = item.getItem(0);
+ fr.free.nrw.commons.location.LatLng diffLatLang = new fr.free.nrw.commons.location.LatLng(overlayItem.getPoint().getLatitude(),overlayItem.getPoint().getLongitude(),100);
+ if (place.location.getLatitude() == overlayItem.getPoint().getLatitude() && place.location.getLongitude() == overlayItem.getPoint().getLongitude()){
+ mapView.getOverlays().remove(i);
+ mapView.invalidate();
+ break;
}
- });
-
- mapBox.setOnMarkerClickListener(marker -> {
- if (marker instanceof NearbyMarker) {
- presenter.markerSelected(marker);
- }
- return false;
- });
+ }
}
}
@@ -1715,45 +1738,44 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
if (isPermissionDenied || curLatLng == null) {
recenterToUserLocation = true;
checkPermissionsAndPerformAction();
- if (!isPermissionDenied && !(locationManager.isNetworkProviderEnabled() || locationManager.isGPSProviderEnabled())) {
+ if (!isPermissionDenied && !(locationManager.isNetworkProviderEnabled()
+ || locationManager.isGPSProviderEnabled())) {
showLocationOffDialog();
}
return;
}
addCurrentLocationMarker(curLatLng);
- final CameraPosition position;
-
- if (ViewUtil.isPortrait(getActivity())) {
- position = new CameraPosition.Builder()
- .target(isListBottomSheetExpanded() ?
- new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
- curLatLng.getLongitude())
- : new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude(), 0)) // Sets the new camera position
- .zoom(isListBottomSheetExpanded() ?
- ZOOM_LEVEL
- : mapBox.getCameraPosition().zoom) // Same zoom level
- .build();
- } else {
- position = new CameraPosition.Builder()
- .target(isListBottomSheetExpanded() ?
- new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
- curLatLng.getLongitude())
- : new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude(), 0)) // Sets the new camera position
- .zoom(isListBottomSheetExpanded() ?
- ZOOM_LEVEL
- : mapBox.getCameraPosition().zoom) // Same zoom level
- .build();
+ mapView.getController()
+ .animateTo(new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude()));
+ if (lastMapFocus != null) {
+ Location mylocation = new Location("");
+ Location dest_location = new Location("");
+ dest_location.setLatitude(mapView.getMapCenter().getLatitude());
+ dest_location.setLongitude(mapView.getMapCenter().getLongitude());
+ mylocation.setLatitude(lastMapFocus.getLatitude());
+ mylocation.setLongitude(lastMapFocus.getLongitude());
+ Float distance = mylocation.distanceTo(dest_location);//in meters
+ if (lastMapFocus != null) {
+ if (isNetworkConnectionEstablished()) {
+ if (distance > 2000.0) {
+ setSearchThisAreaButtonVisibility(true);
+ } else {
+ setSearchThisAreaButtonVisibility(false);
+ }
+ }
+ } else {
+ setSearchThisAreaButtonVisibility(false);
+ }
}
-
- mapBox.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
}
@Override
public void showLocationOffDialog() {
// This creates a dialog box that prompts the user to enable location
DialogUtil
- .showAlertDialog(getActivity(), getString(R.string.ask_to_turn_location_on), getString(R.string.nearby_needs_location),
- getString(R.string.yes), getString(R.string.no), this::openLocationSettings, null);
+ .showAlertDialog(getActivity(), getString(R.string.ask_to_turn_location_on),
+ getString(R.string.nearby_needs_location),
+ getString(R.string.yes), getString(R.string.no), this::openLocationSettings, null);
}
@Override
@@ -1762,11 +1784,13 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
final PackageManager packageManager = getActivity().getPackageManager();
- if (intent.resolveActivity(packageManager)!= null) {
+ if (intent.resolveActivity(packageManager) != null) {
startActivity(intent);
- Toast.makeText(getContext(), R.string.recommend_high_accuracy_mode, Toast.LENGTH_LONG).show();
+ Toast.makeText(getContext(), R.string.recommend_high_accuracy_mode, Toast.LENGTH_LONG)
+ .show();
} else {
- Toast.makeText(getContext(), R.string.cannot_open_location_settings, Toast.LENGTH_LONG).show();
+ Toast.makeText(getContext(), R.string.cannot_open_location_settings, Toast.LENGTH_LONG)
+ .show();
}
}
@@ -1790,15 +1814,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
- @Override
- public void addOnCameraMoveListener() {
- mapBox.addOnCameraMoveListener(cameraMoveListener);
- }
-
/**
- * If nearby details bottom sheet state is collapsed: show fab plus
- * If nearby details bottom sheet state is expanded: show fab plus
- * If nearby details bottom sheet state is hidden: hide all fabs
+ * If nearby details bottom sheet state is collapsed: show fab plus If nearby details bottom
+ * sheet state is expanded: show fab plus If nearby details bottom sheet state is hidden: hide
+ * all fabs
+ *
* @param bottomSheetState see bottom sheet states
*/
public void prepareViewsForSheetPosition(final int bottomSheetState) {
@@ -1811,9 +1831,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
break;
case (BottomSheetBehavior.STATE_HIDDEN):
- if (null != mapBox) {
- mapBox.deselectMarkers();
- }
transparentView.setClickable(false);
transparentView.setAlpha(0);
collapseFABs(isFABsExpanded);
@@ -1825,6 +1842,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
/**
* Same bottom sheet carries information for all nearby places, so we need to pass information
* (title, description, distance and links) to view on nearby marker click
+ *
* @param place Place of clicked nearby marker
*/
private void passInfoToSheet(final Place place) {
@@ -1835,19 +1853,23 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
final boolean isBookmarked = bookmarkLocationDao.updateBookmarkLocation(selectedPlace);
updateBookmarkButtonImage(selectedPlace);
updateMarker(isBookmarked, selectedPlace, locationManager.getLastLocation());
+ mapView.invalidate();
});
- wikipediaButton.setVisibility(place.hasWikipediaLink()?View.VISIBLE:View.GONE);
- wikipediaButton.setOnClickListener(view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikipediaLink()));
+ wikipediaButton.setVisibility(place.hasWikipediaLink() ? View.VISIBLE : View.GONE);
+ wikipediaButton.setOnClickListener(
+ view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikipediaLink()));
- wikidataButton.setVisibility(place.hasWikidataLink()?View.VISIBLE:View.GONE);
- wikidataButton.setOnClickListener(view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikidataLink()));
+ wikidataButton.setVisibility(place.hasWikidataLink() ? View.VISIBLE : View.GONE);
+ wikidataButton.setOnClickListener(
+ view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikidataLink()));
directionsButton.setOnClickListener(view -> Utils.handleGeoCoordinates(getActivity(),
selectedPlace.getLocation()));
- commonsButton.setVisibility(selectedPlace.hasCommonsLink()?View.VISIBLE:View.GONE);
- commonsButton.setOnClickListener(view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getCommonsLink()));
+ commonsButton.setVisibility(selectedPlace.hasCommonsLink() ? View.VISIBLE : View.GONE);
+ commonsButton.setOnClickListener(
+ view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getCommonsLink()));
icon.setImageResource(selectedPlace.getLabel().getIcon());
@@ -1855,8 +1877,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
distance.setText(selectedPlace.distance);
// Remove label since it is double information
String descriptionText = selectedPlace.getLongDescription()
- .replace(selectedPlace.getName() + " (","");
- descriptionText = (descriptionText.equals(selectedPlace.getLongDescription()) ? descriptionText : descriptionText.replaceFirst(".$",""));
+ .replace(selectedPlace.getName() + " (", "");
+ descriptionText = (descriptionText.equals(selectedPlace.getLongDescription())
+ ? descriptionText : descriptionText.replaceFirst(".$", ""));
// Set the short description after we remove place name from long description
description.setText(descriptionText);
@@ -1910,7 +1933,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override
public void onWikidataEditSuccessful() {
- if (mapBox != null && presenter != null && locationManager != null) {
+ if (presenter != null && locationManager != null) {
presenter.updateMapAndList(MAP_UPDATED);
}
}
@@ -1930,7 +1953,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
locationManager.registerLocationManager();
Timber.d("Location service manager added and registered");
}
- }catch (final Exception e){
+ } catch (final Exception e) {
Timber.e(e);
//Broadcasts are tricky, should be catchedonR
}
@@ -1939,7 +1962,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override
public void setUserVisibleHint(final boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
- this.isVisibleToUser=isVisibleToUser;
+ this.isVisibleToUser = isVisibleToUser;
if (isResumed() && isVisibleToUser) {
startTheMap();
} else {
@@ -1954,15 +1977,134 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
private void startTheMap() {
- mapView.onStart();
performMapReadyActions();
}
- public interface NearbyParentFragmentInstanceReadyCallback{
+ /**
+ * Clears all markers from the map and resets certain map overlays and gestures. After clearing
+ * markers, it re-adds a scale bar overlay and rotation gesture overlay to the map.
+ */
+ @Override
+ public void clearAllMarkers() {
+ mapView.getOverlayManager().clear();
+ mapView.invalidate();
+ GeoPoint geoPoint = mapCenter;
+ if (geoPoint != null) {
+ List overlays = mapView.getOverlays();
+ ScaleDiskOverlay diskOverlay =
+ new ScaleDiskOverlay(this.getContext(),
+ geoPoint, 2000, GeoConstants.UnitOfMeasure.foot);
+ Paint circlePaint = new Paint();
+ circlePaint.setColor(Color.rgb(128, 128, 128));
+ circlePaint.setStyle(Paint.Style.STROKE);
+ circlePaint.setStrokeWidth(2f);
+ diskOverlay.setCirclePaint2(circlePaint);
+ Paint diskPaint = new Paint();
+ diskPaint.setColor(Color.argb(40, 128, 128, 128));
+ diskPaint.setStyle(Paint.Style.FILL_AND_STROKE);
+ diskOverlay.setCirclePaint1(diskPaint);
+ diskOverlay.setDisplaySizeMin(900);
+ diskOverlay.setDisplaySizeMax(1700);
+ mapView.getOverlays().add(diskOverlay);
+ org.osmdroid.views.overlay.Marker startMarker = new org.osmdroid.views.overlay.Marker(
+ mapView);
+ startMarker.setPosition(geoPoint);
+ startMarker.setAnchor(org.osmdroid.views.overlay.Marker.ANCHOR_CENTER,
+ org.osmdroid.views.overlay.Marker.ANCHOR_BOTTOM);
+ startMarker.setIcon(
+ ContextCompat.getDrawable(this.getContext(), R.drawable.current_location_marker));
+ startMarker.setTitle("Your Location");
+ startMarker.setTextLabelFontSize(24);
+ mapView.getOverlays().add(startMarker);
+ }
+ ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(mapView);
+ scaleBarOverlay.setScaleBarOffset(15, 25);
+ Paint barPaint = new Paint();
+ barPaint.setARGB(200, 255, 250, 250);
+ scaleBarOverlay.setBackgroundPaint(barPaint);
+ scaleBarOverlay.enableScaleBar();
+ mapView.getOverlays().add(scaleBarOverlay);
+ mapView.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() {
+ @Override
+ public boolean singleTapConfirmedHelper(GeoPoint p) {
+ if (clickedMarkerPlace != null){
+ removeMarker(clickedMarkerPlace);
+ addMarkerToMap(clickedMarkerPlace,isClickedMarkerBookmarked);
+ }else {
+ Timber.e("CLICKED MARKER IS NULL");
+ }
+ if (isListBottomSheetExpanded()) {
+ // Back should first hide the bottom sheet if it is expanded
+ hideBottomSheet();
+ } else if (isDetailsBottomSheetVisible()) {
+ hideBottomDetailsSheet();
+ }
+ return true;
+ }
+
+ @Override
+ public boolean longPressHelper(GeoPoint p) {
+ return false;
+ }
+ }));
+ mapView.setMultiTouchControls(true);
+ }
+
+ /**
+ * Recenters the map to the Center and adds a scale disk overlay and a marker at the position.
+ *
+ * @param geoPoint The GeoPoint representing the new center position of the map.
+ */
+ private void recenterMarkerToPosition(GeoPoint geoPoint) {
+ if (geoPoint != null) {
+ mapView.getController().setCenter(geoPoint);
+ List overlays = mapView.getOverlays();
+ for (int i = 0; i < overlays.size(); i++) {
+ if (overlays.get(i) instanceof org.osmdroid.views.overlay.Marker) {
+ mapView.getOverlays().remove(i);
+ } else if (overlays.get(i) instanceof ScaleDiskOverlay) {
+ mapView.getOverlays().remove(i);
+ }
+ }
+ ScaleDiskOverlay diskOverlay =
+ new ScaleDiskOverlay(this.getContext(),
+ geoPoint, 2000, GeoConstants.UnitOfMeasure.foot);
+ Paint circlePaint = new Paint();
+ circlePaint.setColor(Color.rgb(128, 128, 128));
+ circlePaint.setStyle(Paint.Style.STROKE);
+ circlePaint.setStrokeWidth(2f);
+ diskOverlay.setCirclePaint2(circlePaint);
+ Paint diskPaint = new Paint();
+ diskPaint.setColor(Color.argb(40, 128, 128, 128));
+ diskPaint.setStyle(Paint.Style.FILL_AND_STROKE);
+ diskOverlay.setCirclePaint1(diskPaint);
+ diskOverlay.setDisplaySizeMin(900);
+ diskOverlay.setDisplaySizeMax(1700);
+ mapView.getOverlays().add(diskOverlay);
+ org.osmdroid.views.overlay.Marker startMarker = new org.osmdroid.views.overlay.Marker(
+ mapView);
+ startMarker.setPosition(geoPoint);
+ startMarker.setAnchor(org.osmdroid.views.overlay.Marker.ANCHOR_CENTER,
+ org.osmdroid.views.overlay.Marker.ANCHOR_BOTTOM);
+ startMarker.setIcon(
+ ContextCompat.getDrawable(this.getContext(), R.drawable.current_location_marker));
+ startMarker.setTitle("Your Location");
+ startMarker.setTextLabelFontSize(24);
+ mapView.getOverlays().add(startMarker);
+ }
+ }
+
+ private void moveCameraToPosition(GeoPoint geoPoint) {
+ mapView.getController().animateTo(geoPoint);
+ }
+
+ public interface NearbyParentFragmentInstanceReadyCallback {
+
void onReady();
}
- public void setNearbyParentFragmentInstanceReadyCallback(NearbyParentFragmentInstanceReadyCallback nearbyParentFragmentInstanceReadyCallback) {
+ public void setNearbyParentFragmentInstanceReadyCallback(
+ NearbyParentFragmentInstanceReadyCallback nearbyParentFragmentInstanceReadyCallback) {
this.nearbyParentFragmentInstanceReadyCallback = nearbyParentFragmentInstanceReadyCallback;
}
@@ -1970,9 +2112,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
public void onConfigurationChanged(@NonNull final Configuration newConfig) {
super.onConfigurationChanged(newConfig);
ViewGroup.LayoutParams rlBottomSheetLayoutParams = rlBottomSheet.getLayoutParams();
- rlBottomSheetLayoutParams.height = getActivity().getWindowManager().getDefaultDisplay().getHeight() / 16 * 9;
+ rlBottomSheetLayoutParams.height =
+ getActivity().getWindowManager().getDefaultDisplay().getHeight() / 16 * 9;
rlBottomSheet.setLayoutParams(rlBottomSheetLayoutParams);
- }
+ }
@OnClick(R.id.tv_learn_more)
public void onLearnMoreClicked() {
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 4019aa9fc..d7f2919a5 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
@@ -1,31 +1,5 @@
package fr.free.nrw.commons.nearby.presenter;
-import android.view.View;
-
-import androidx.annotation.MainThread;
-import androidx.annotation.Nullable;
-import com.mapbox.mapboxsdk.annotations.Marker;
-
-import fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType;
-import java.lang.reflect.Proxy;
-import java.util.HashMap;
-import java.util.List;
-
-import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
-import fr.free.nrw.commons.kvstore.JsonKvStore;
-import fr.free.nrw.commons.location.LatLng;
-import fr.free.nrw.commons.location.LocationUpdateListener;
-import fr.free.nrw.commons.nearby.CheckBoxTriStates;
-import fr.free.nrw.commons.nearby.Label;
-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.contract.NearbyParentFragmentContract;
-import fr.free.nrw.commons.utils.LocationUtils;
-import fr.free.nrw.commons.wikidata.WikidataEditListener;
-import timber.log.Timber;
-
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.CUSTOM_QUERY;
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED;
@@ -36,10 +10,34 @@ import static fr.free.nrw.commons.nearby.CheckBoxTriStates.UNCHECKED;
import static fr.free.nrw.commons.nearby.CheckBoxTriStates.UNKNOWN;
import static fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT;
+import android.location.Location;
+import android.view.View;
+import androidx.annotation.MainThread;
+import androidx.annotation.Nullable;
+import com.mapbox.mapboxsdk.annotations.Marker;
+import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
+import fr.free.nrw.commons.kvstore.JsonKvStore;
+import fr.free.nrw.commons.location.LatLng;
+import fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType;
+import fr.free.nrw.commons.location.LocationUpdateListener;
+import fr.free.nrw.commons.nearby.CheckBoxTriStates;
+import fr.free.nrw.commons.nearby.Label;
+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.contract.NearbyParentFragmentContract;
+import fr.free.nrw.commons.utils.LocationUtils;
+import fr.free.nrw.commons.wikidata.WikidataEditListener;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.List;
+import timber.log.Timber;
+
public class NearbyParentFragmentPresenter
- implements NearbyParentFragmentContract.UserActions,
- WikidataEditListener.WikidataP18EditListener,
- LocationUpdateListener {
+ implements NearbyParentFragmentContract.UserActions,
+ WikidataEditListener.WikidataP18EditListener,
+ LocationUpdateListener {
private boolean isNearbyLocked;
private LatLng curLatLng;
@@ -51,40 +49,40 @@ public class NearbyParentFragmentPresenter
private @Nullable String customQuery;
private static final NearbyParentFragmentContract.View DUMMY = (NearbyParentFragmentContract.View) Proxy.newProxyInstance(
- NearbyParentFragmentContract.View.class.getClassLoader(),
- new Class[]{NearbyParentFragmentContract.View.class}, (proxy, method, args) -> {
- if (method.getName().equals("onMyEvent")) {
- return null;
- } else if (String.class == method.getReturnType()) {
- return "";
- } else if (Integer.class == method.getReturnType()) {
- return Integer.valueOf(0);
- } else if (int.class == method.getReturnType()) {
- return 0;
- } else if (Boolean.class == method.getReturnType()) {
- return Boolean.FALSE;
- } else if (boolean.class == method.getReturnType()) {
- return false;
- } else {
- return null;
- }
+ NearbyParentFragmentContract.View.class.getClassLoader(),
+ new Class[]{NearbyParentFragmentContract.View.class}, (proxy, method, args) -> {
+ if (method.getName().equals("onMyEvent")) {
+ return null;
+ } else if (String.class == method.getReturnType()) {
+ return "";
+ } else if (Integer.class == method.getReturnType()) {
+ return Integer.valueOf(0);
+ } else if (int.class == method.getReturnType()) {
+ return 0;
+ } else if (Boolean.class == method.getReturnType()) {
+ return Boolean.FALSE;
+ } else if (boolean.class == method.getReturnType()) {
+ return false;
+ } else {
+ return null;
}
+ }
);
private NearbyParentFragmentContract.View nearbyParentFragmentView = DUMMY;
- public NearbyParentFragmentPresenter(BookmarkLocationsDao bookmarkLocationDao){
- this.bookmarkLocationDao=bookmarkLocationDao;
+ public NearbyParentFragmentPresenter(BookmarkLocationsDao bookmarkLocationDao) {
+ this.bookmarkLocationDao = bookmarkLocationDao;
}
@Override
- public void attachView(NearbyParentFragmentContract.View view){
- this.nearbyParentFragmentView=view;
+ public void attachView(NearbyParentFragmentContract.View view) {
+ this.nearbyParentFragmentView = view;
}
@Override
- public void detachView(){
- this.nearbyParentFragmentView=DUMMY;
+ public void detachView() {
+ this.nearbyParentFragmentView = DUMMY;
}
@Override
@@ -109,13 +107,13 @@ public class NearbyParentFragmentPresenter
if (applicationKvStore.getBoolean("login_skipped", false)) {
// prompt the user to login
nearbyParentFragmentView.displayLoginSkippedWarning();
- }else {
+ } else {
nearbyParentFragmentView.animateFABs();
}
});
nearbyParentFragmentView.setFABRecenterAction(v -> {
- nearbyParentFragmentView.recenterMap(curLatLng);
+ nearbyParentFragmentView.recenterMap(curLatLng);
});
}
@@ -125,8 +123,7 @@ public class NearbyParentFragmentPresenter
if (nearbyParentFragmentView.isAdvancedQueryFragmentVisible()) {
nearbyParentFragmentView.showHideAdvancedQueryFragment(false);
return true;
- }
- else if(nearbyParentFragmentView.isListBottomSheetExpanded()) {
+ } else if (nearbyParentFragmentView.isListBottomSheetExpanded()) {
// Back should first hide the bottom sheet if it is expanded
nearbyParentFragmentView.listOptionMenuItemClicked();
return true;
@@ -150,6 +147,7 @@ public class NearbyParentFragmentPresenter
/**
* Nearby updates takes time, since they are network operations. During update time, we don't
* want to get any other calls from user. So locking nearby.
+ *
* @param isNearbyLocked true means lock, false means unlock
*/
@Override
@@ -163,8 +161,8 @@ public class NearbyParentFragmentPresenter
}
/**
- * This method should be the single point to update Map and List. Triggered by location
- * changes
+ * This method should be the single point to update Map and List. Triggered by location changes
+ *
* @param locationChangeType defines if location changed significantly or slightly
*/
@Override
@@ -180,9 +178,12 @@ public class NearbyParentFragmentPresenter
return;
}
- LatLng lastLocation = nearbyParentFragmentView.getLastLocation();
- curLatLng = lastLocation;
-
+ LatLng lastLocation = nearbyParentFragmentView.getLastMapFocus();
+ if (nearbyParentFragmentView.getMapCenter() != null) {
+ curLatLng = nearbyParentFragmentView.getMapCenter();
+ } else {
+ curLatLng = lastLocation;
+ }
if (curLatLng == null) {
Timber.d("Skipping update of nearby places as location is unavailable");
return;
@@ -192,31 +193,29 @@ public class NearbyParentFragmentPresenter
* Significant changed - Markers and current location will be updated together
* Slightly changed - Only current position marker will be updated
*/
- if(locationChangeType.equals(CUSTOM_QUERY)){
+ if (locationChangeType.equals(CUSTOM_QUERY)) {
Timber.d("ADVANCED_QUERY_SEARCH");
lockUnlockNearby(true);
nearbyParentFragmentView.setProgressBarVisibility(true);
- LatLng updatedLocationByUser = LocationUtils.deriveUpdatedLocationFromSearchQuery(customQuery);
+ LatLng updatedLocationByUser = LocationUtils.deriveUpdatedLocationFromSearchQuery(
+ customQuery);
if (updatedLocationByUser == null) {
updatedLocationByUser = lastLocation;
}
nearbyParentFragmentView.populatePlaces(updatedLocationByUser, customQuery);
- }
- else if (locationChangeType.equals(LOCATION_SIGNIFICANTLY_CHANGED)
- || locationChangeType.equals(MAP_UPDATED)) {
- Timber.d("LOCATION_SIGNIFICANTLY_CHANGED");
+ } else if (locationChangeType.equals(LOCATION_SIGNIFICANTLY_CHANGED)
+ || locationChangeType.equals(MAP_UPDATED)) {
lockUnlockNearby(true);
nearbyParentFragmentView.setProgressBarVisibility(true);
- nearbyParentFragmentView.populatePlaces(lastLocation);
-
+ nearbyParentFragmentView.populatePlaces(nearbyParentFragmentView.getMapCenter());
} else if (locationChangeType.equals(SEARCH_CUSTOM_AREA)) {
Timber.d("SEARCH_CUSTOM_AREA");
lockUnlockNearby(true);
nearbyParentFragmentView.setProgressBarVisibility(true);
- nearbyParentFragmentView.populatePlaces(nearbyParentFragmentView.getCameraTarget());
+ nearbyParentFragmentView.populatePlaces(nearbyParentFragmentView.getMapFocus());
} else { // Means location changed slightly, ie user is walking or driving.
Timber.d("Means location changed slightly");
- if (nearbyParentFragmentView.isCurrentLocationMarkerVisible()){ // Means user wants to see their live location
+ if (nearbyParentFragmentView.isCurrentLocationMarkerVisible()) { // Means user wants to see their live location
nearbyParentFragmentView.recenterMap(curLatLng);
}
}
@@ -225,31 +224,29 @@ public class NearbyParentFragmentPresenter
/**
* 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 placeToCenter list information and distances.
*/
- public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo, Marker selectedMarker, boolean shouldTrackPosition) {
- if(null!=nearbyParentFragmentView) {
+ public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo,
+ Marker selectedMarker, boolean shouldTrackPosition) {
+ if (null != nearbyParentFragmentView) {
+ nearbyParentFragmentView.clearAllMarkers();
List nearbyBaseMarkers = NearbyController
- .loadAttractionsFromLocationToBaseMarkerOptions(nearbyPlacesInfo.curLatLng, // Curlatlang will be used to calculate distances
- nearbyPlacesInfo.placeList,
- nearbyParentFragmentView.getContext(),
- bookmarkLocationDao.getAllBookmarksLocations());
+ .loadAttractionsFromLocationToBaseMarkerOptions(nearbyPlacesInfo.curLatLng,
+ // Curlatlang will be used to calculate distances
+ nearbyPlacesInfo.placeList,
+ nearbyParentFragmentView.getContext(),
+ bookmarkLocationDao.getAllBookmarksLocations());
nearbyParentFragmentView.updateMapMarkers(nearbyBaseMarkers, selectedMarker);
- nearbyParentFragmentView.addCurrentLocationMarker(nearbyPlacesInfo.curLatLng);
- if(shouldTrackPosition){
- nearbyParentFragmentView.updateMapToTrackPosition(nearbyPlacesInfo.curLatLng);
- }
lockUnlockNearby(false); // So that new location updates wont come
nearbyParentFragmentView.setProgressBarVisibility(false);
nearbyParentFragmentView.updateListFragment(nearbyPlacesInfo.placeList);
- handleCenteringTaskIfAny();
- nearbyParentFragmentView.centerMapToPosition(nearbyPlacesInfo.searchLatLng);
}
}
/**
- * Some centering task may need to wait for map to be ready, if they are requested before
- * map is ready. So we will remember it when the map is ready
+ * Some centering task may need to wait for map to be ready, if they are requested before map is
+ * ready. So we will remember it when the map is ready
*/
private void handleCenteringTaskIfAny() {
if (!placesLoadedOnce) {
@@ -282,31 +279,32 @@ 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
- (LocationUtils.commonsLatLngToMapBoxLatLng(NearbyController.latestSearchLocation));
- if (nearbyParentFragmentView.isNetworkConnectionEstablished()) {
- if (distance > NearbyController.latestSearchRadius) {
- nearbyParentFragmentView.setSearchThisAreaButtonVisibility(true);
- } else {
- nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false);
- }
+ // If our nearby markers are calculated at least once
+ if (NearbyController.latestSearchLocation != null) {
+ double distance = latLng.distanceTo
+ (LocationUtils.commonsLatLngToMapBoxLatLng(NearbyController.latestSearchLocation));
+ if (nearbyParentFragmentView.isNetworkConnectionEstablished()) {
+ if (distance > NearbyController.latestSearchRadius) {
+ //nearbyParentFragmentView.setSearchThisAreaButtonVisibility(true);
+ } else {
+ nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false);
}
- } else {
- nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false);
}
+ } else {
+ nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false);
+ }
}
@Override
- public void filterByMarkerType(List