Removed MapBox related imports (#5631)

* Fixed Grey empty screen at Upload wizard caption step after denying files permission

* Empty commit

* Fixed loop issue

* Created docs for earlier commits

* Fixed javadoc

* Fixed spaces

* Added added basic features to OSM Maps

* Added search location feature

* Added filter to Open Street Maps

* Fixed chipGroup in Open Street Maps

* Removed mapBox code

* Removed mapBox's code

* Reformat code

* Reformatted code

* Removed rotation feature to map

* Removed rotation files and Fixed Marker click problem

* Ignored failing tests

* Added voice input feature

* Fixed test cases

* Changed caption and description text

* Replaced mapbox to osmdroid in upload activity

* Fixed Unit Tests

* Made selected marker to be fixed on map

* Changed color of map marker

* Fixes #5439 by capitalizing first letter of voice input

* Removed mapbox code1

* Removed mapbox code2

* Fixed failing tests

* Fixed failing due to merging
This commit is contained in:
Kanahia 2024-03-21 19:13:22 +05:30 committed by GitHub
parent 9041e1bc0c
commit d112be04db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 261 additions and 831 deletions

View file

@ -0,0 +1,64 @@
package fr.free.nrw.commons
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import fr.free.nrw.commons.location.LatLng
import fr.free.nrw.commons.nearby.Place
class BaseMarker {
private var _position: LatLng = LatLng(0.0, 0.0, 0f)
private var _title: String = ""
private var _place: Place = Place()
private var _icon: Bitmap? = null
var position: LatLng
get() = _position
set(value) {
_position = value
}
var title: String
get() = _title
set(value) {
_title = value
}
var place: Place
get() = _place
set(value) {
_place = value
}
var icon: Bitmap?
get() = _icon
set(value) {
_icon = value
}
constructor() {
}
fun fromResource(context: Context, drawableResId: Int) {
val drawable: Drawable = context.resources.getDrawable(drawableResId)
icon = if (drawable is BitmapDrawable) {
(drawable as BitmapDrawable).bitmap
} else {
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight, Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
bitmap
}
}
}

View file

@ -0,0 +1,33 @@
package fr.free.nrw.commons
import android.os.Parcel
import android.os.Parcelable
class CameraPosition(val latitude: Double, val longitude: Double, val zoom: Double) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readDouble(),
parcel.readDouble(),
parcel.readDouble()
)
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeDouble(latitude)
parcel.writeDouble(longitude)
parcel.writeDouble(zoom)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<CameraPosition> {
override fun createFromParcel(parcel: Parcel): CameraPosition {
return CameraPosition(parcel)
}
override fun newArray(size: Int): Array<CameraPosition?> {
return arrayOfNulls(size)
}
}
}

View file

@ -2,7 +2,7 @@ package fr.free.nrw.commons.LocationPicker;
import android.app.Activity;
import android.content.Intent;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import fr.free.nrw.commons.CameraPosition;
import fr.free.nrw.commons.Media;
/**

View file

@ -29,8 +29,7 @@ import androidx.appcompat.widget.AppCompatTextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import fr.free.nrw.commons.CameraPosition;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
@ -43,7 +42,6 @@ import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermission
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.utils.SystemThemeUtils;
import fr.free.nrw.commons.utils.ViewUtilWrapper;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.List;
@ -214,9 +212,9 @@ public class LocationPickerActivity extends BaseActivity implements
fabCenterOnLocation.setVisibility(View.GONE);
markerImage.setVisibility(View.GONE);
shadow.setVisibility(View.GONE);
assert cameraPosition.target != null;
showSelectedLocationMarker(new GeoPoint(cameraPosition.target.getLatitude(),
cameraPosition.target.getLongitude()));
assert cameraPosition != null;
showSelectedLocationMarker(new GeoPoint(cameraPosition.getLatitude(),
cameraPosition.getLongitude()));
}
setupMapView();
}
@ -295,9 +293,11 @@ public class LocationPickerActivity extends BaseActivity implements
smallToolbarText.setText(getResources().getString(R.string.pan_and_zoom_to_adjust));
fabCenterOnLocation.setVisibility(View.VISIBLE);
removeSelectedLocationMarker();
if (cameraPosition.target != null) {
mapView.getController().animateTo(new GeoPoint(cameraPosition.target.getLatitude(),
cameraPosition.target.getLongitude()));
if (cameraPosition != null && mapView != null) {
if (mapView.getController() != null) {
mapView.getController().animateTo(new GeoPoint(cameraPosition.getLatitude(),
cameraPosition.getLongitude()));
}
}
}
@ -314,9 +314,9 @@ public class LocationPickerActivity extends BaseActivity implements
* move the location to the current media coordinates
*/
private void adjustCameraBasedOnOptions() {
if (cameraPosition.target != null) {
mapView.getController().setCenter(new GeoPoint(cameraPosition.target.getLatitude(),
cameraPosition.target.getLongitude()));
if (cameraPosition != null) {
mapView.getController().setCenter(new GeoPoint(cameraPosition.getLatitude(),
cameraPosition.getLongitude()));
}
}
@ -343,8 +343,8 @@ public class LocationPickerActivity extends BaseActivity implements
if (media == null) {
final Intent returningIntent = new Intent();
returningIntent.putExtra(LocationPickerConstants.MAP_CAMERA_POSITION,
new CameraPosition(new LatLng(mapView.getMapCenter().getLatitude(),
mapView.getMapCenter().getLongitude()), 14f, 0, 0));
new CameraPosition(mapView.getMapCenter().getLatitude(),
mapView.getMapCenter().getLongitude(), 14.0));
setResult(AppCompatActivity.RESULT_OK, returningIntent);
} else {
updateCoordinates(String.valueOf(mapView.getMapCenter().getLatitude()),
@ -408,8 +408,8 @@ public class LocationPickerActivity extends BaseActivity implements
for (int i = 0; i < overlays.size(); i++) {
if (overlays.get(i) instanceof Marker) {
Marker item = (Marker) overlays.get(i);
if (cameraPosition.target.getLatitude() == item.getPosition().getLatitude()
&& cameraPosition.target.getLongitude() == item.getPosition().getLongitude()) {
if (cameraPosition.getLatitude() == item.getPosition().getLatitude()
&& cameraPosition.getLongitude() == item.getPosition().getLongitude()) {
mapView.getOverlays().remove(i);
mapView.invalidate();
break;

View file

@ -4,7 +4,7 @@ import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import fr.free.nrw.commons.CameraPosition;
import org.jetbrains.annotations.NotNull;
import retrofit2.Call;
import retrofit2.Callback;

View file

@ -1,12 +0,0 @@
package fr.free.nrw.commons;
import com.mapbox.mapboxsdk.maps.Style;
/**
* Constants for various map styles
*/
public final class MapStyle {
public static final String DARK = Style.getPredefinedStyle("Dark");
public static final String OUTDOORS = Style.getPredefinedStyle("Outdoors");
public static final String STREETS = Style.getPredefinedStyle("Streets");
}

View file

@ -427,8 +427,6 @@ public class MainActivity extends BaseActivity
public void centerMapToPlace(Place place) {
setSelectedItemId(NavTab.NEARBY.code());
nearbyParentFragment.setNearbyParentFragmentInstanceReadyCallback(new NearbyParentFragmentInstanceReadyCallback() {
// if mapBox initialize in nearbyParentFragment then MapReady() function called
// so that nearbyParentFragemt.centerMaptoPlace(place) not throw any null pointer exception
@Override
public void onReady() {
nearbyParentFragment.centerMapToPlace(place);

View file

@ -1,11 +1,10 @@
package fr.free.nrw.commons.explore.map;
import android.content.Context;
import com.mapbox.mapboxsdk.annotations.Marker;
import fr.free.nrw.commons.BaseMarker;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
import java.util.List;
public class ExploreMapContract {
@ -18,11 +17,10 @@ public class ExploreMapContract {
void showLocationOffDialog();
void openLocationSettings();
void hideBottomDetailsSheet();
void displayBottomSheetWithInfo(Marker marker);
LatLng getMapCenter();
LatLng getMapFocus();
LatLng getLastMapFocus();
void addMarkersToMap(final List<NearbyBaseMarker> nearbyBaseMarkers);
void addMarkersToMap(final List<BaseMarker> nearbyBaseMarkers);
void clearAllMarkers();
void addSearchThisAreaButtonAction();
void setSearchThisAreaButtonVisibility(boolean isVisible);

View file

@ -14,13 +14,11 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
import fr.free.nrw.commons.BaseMarker;
import fr.free.nrw.commons.MapController;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.utils.ImageUtils;
import fr.free.nrw.commons.utils.LocationUtils;
@ -107,8 +105,8 @@ public class ExploreMapController extends MapController {
// Sets latestSearchRadius to maximum distance among boundaries and search location
for (LatLng bound : boundaryCoordinates) {
double distance = LocationUtils.commonsLatLngToMapBoxLatLng(bound)
.distanceTo(LocationUtils.commonsLatLngToMapBoxLatLng(latestSearchLocation));
double distance = LocationUtils.calculateDistance(bound.getLatitude(),
bound.getLongitude(), searchLatLng.getLatitude(), searchLatLng.getLongitude());
if (distance > latestSearchRadius) {
latestSearchRadius = distance;
}
@ -130,17 +128,16 @@ public class ExploreMapController extends MapController {
*
* @return baseMarkerOptions list that holds nearby places with their icons
*/
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
public static List<BaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
LatLng curLatLng,
final List<Place> placeList,
Context context,
NearbyBaseMarkerThumbCallback callback,
Marker selectedMarker,
ExplorePlacesInfo explorePlacesInfo) {
List<NearbyBaseMarker> baseMarkerOptions = new ArrayList<>();
List<BaseMarker> baseMarkerList = new ArrayList<>();
if (placeList == null) {
return baseMarkerOptions;
return baseMarkerList;
}
VectorDrawableCompat vectorDrawable = null;
@ -153,17 +150,17 @@ public class ExploreMapController extends MapController {
}
if (vectorDrawable != null) {
for (Place explorePlace : placeList) {
final NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
final BaseMarker baseMarker = new BaseMarker();
String distance = formatDistanceBetween(curLatLng, explorePlace.location);
explorePlace.setDistance(distance);
nearbyBaseMarker.title(
baseMarker.setTitle(
explorePlace.name.substring(5, explorePlace.name.lastIndexOf(".")));
nearbyBaseMarker.position(
new com.mapbox.mapboxsdk.geometry.LatLng(
baseMarker.setPosition(
new fr.free.nrw.commons.location.LatLng(
explorePlace.location.getLatitude(),
explorePlace.location.getLongitude()));
nearbyBaseMarker.place(explorePlace);
explorePlace.location.getLongitude(), 0));
baseMarker.setPlace(explorePlace);
Glide.with(context)
.asBitmap()
@ -175,13 +172,13 @@ public class ExploreMapController extends MapController {
@Override
public void onResourceReady(@NonNull Bitmap resource,
@Nullable Transition<? super Bitmap> transition) {
nearbyBaseMarker.setIcon(IconFactory.getInstance(context).fromBitmap(
ImageUtils.addRedBorder(resource, 6, context)));
baseMarkerOptions.add(nearbyBaseMarker);
if (baseMarkerOptions.size()
baseMarker.setIcon(
ImageUtils.addRedBorder(resource, 6, context));
baseMarkerList.add(baseMarker);
if (baseMarkerList.size()
== placeList.size()) { // if true, we added all markers to list and can trigger thumbs ready callback
callback.onNearbyBaseMarkerThumbsReady(baseMarkerOptions,
explorePlacesInfo, selectedMarker);
callback.onNearbyBaseMarkerThumbsReady(baseMarkerList,
explorePlacesInfo);
}
}
@ -193,25 +190,24 @@ public class ExploreMapController extends MapController {
@Override
public void onLoadFailed(@Nullable final Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
nearbyBaseMarker.setIcon(IconFactory.getInstance(context)
.fromResource(R.drawable.image_placeholder_96));
baseMarkerOptions.add(nearbyBaseMarker);
if (baseMarkerOptions.size()
baseMarker.fromResource(context, R.drawable.image_placeholder_96);
baseMarkerList.add(baseMarker);
if (baseMarkerList.size()
== placeList.size()) { // if true, we added all markers to list and can trigger thumbs ready callback
callback.onNearbyBaseMarkerThumbsReady(baseMarkerOptions,
explorePlacesInfo, selectedMarker);
callback.onNearbyBaseMarkerThumbsReady(baseMarkerList,
explorePlacesInfo);
}
}
});
}
}
return baseMarkerOptions;
return baseMarkerList;
}
interface NearbyBaseMarkerThumbCallback {
// Callback to notify thumbnails of explore markers are added as icons and ready
void onNearbyBaseMarkerThumbsReady(List<NearbyBaseMarker> baseMarkers,
ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker);
void onNearbyBaseMarkerThumbsReady(List<BaseMarker> baseMarkers,
ExplorePlacesInfo explorePlacesInfo);
}
}

View file

@ -38,7 +38,7 @@ import androidx.core.content.ContextCompat;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.mapbox.mapboxsdk.annotations.Marker;
import fr.free.nrw.commons.BaseMarker;
import fr.free.nrw.commons.MapController;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R;
@ -53,8 +53,6 @@ import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.location.LocationUpdateListener;
import fr.free.nrw.commons.media.MediaClient;
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
import fr.free.nrw.commons.nearby.NearbyMarker;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.MapUtils;
@ -101,8 +99,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
private fr.free.nrw.commons.location.LatLng lastFocusLocation; // last location that map is focused
public List<Media> mediaList;
private boolean recenterToUserLocation; // true is recenter is needed (ie. when current location is in visible map boundaries)
private NearbyBaseMarker clickedMarker;
private Marker selectedMarker; // the marker that user selected
private BaseMarker clickedMarker;
private GeoPoint mapCenter;
private GeoPoint lastMapFocus;
IntentFilter intentFilter = new IntentFilter(MapUtils.NETWORK_INTENT_ACTION);
@ -436,7 +433,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
* @param explorePlacesInfo holds several information as current location, marker list etc.
*/
private void updateMapMarkers(final MapController.ExplorePlacesInfo explorePlacesInfo) {
presenter.updateMapMarkers(explorePlacesInfo, selectedMarker);
presenter.updateMapMarkers(explorePlacesInfo);
}
private void showErrorMessage(final String message) {
@ -547,15 +544,6 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
@Override
public void displayBottomSheetWithInfo(final Marker marker) {
selectedMarker = marker;
final NearbyMarker nearbyMarker = (NearbyMarker) marker;
final Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
passInfoToSheet(place);
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
/**
* 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
@ -644,7 +632,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
* @param nearbyBaseMarkers The NearbyBaseMarker object representing the markers to be added.
*/
@Override
public void addMarkersToMap(List<NearbyBaseMarker> nearbyBaseMarkers) {
public void addMarkersToMap(List<BaseMarker> nearbyBaseMarkers) {
clearAllMarkers();
for (int i = 0; i < nearbyBaseMarkers.size(); i++) {
addMarkerToMap(nearbyBaseMarkers.get(i));
@ -657,9 +645,9 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
*
* @param nearbyBaseMarker The NearbyBaseMarker object representing the marker to be added.
*/
private void addMarkerToMap(NearbyBaseMarker nearbyBaseMarker) {
private void addMarkerToMap(BaseMarker nearbyBaseMarker) {
ArrayList<OverlayItem> items = new ArrayList<>();
Bitmap icon = nearbyBaseMarker.getMarker().getIcon().getBitmap();
Bitmap icon = nearbyBaseMarker.getIcon();
Drawable d = new BitmapDrawable(getResources(), icon);
GeoPoint point = new GeoPoint(
nearbyBaseMarker.getPlace().location.getLatitude(),
@ -699,7 +687,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
*
* @param nearbyBaseMarker The NearbyBaseMarker object representing the marker to be removed.
*/
private void removeMarker(NearbyBaseMarker nearbyBaseMarker) {
private void removeMarker(BaseMarker nearbyBaseMarker) {
Place place = nearbyBaseMarker.getPlace();
List<Overlay> overlays = binding.mapView.getOverlays();
ItemizedOverlayWithFocus item;

View file

@ -6,7 +6,7 @@ import static fr.free.nrw.commons.location.LocationServiceManager.LocationChange
import android.location.Location;
import android.view.View;
import com.mapbox.mapboxsdk.annotations.Marker;
import fr.free.nrw.commons.BaseMarker;
import fr.free.nrw.commons.MapController;
import fr.free.nrw.commons.MapController.ExplorePlacesInfo;
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
@ -14,7 +14,6 @@ import fr.free.nrw.commons.explore.map.ExploreMapController.NearbyBaseMarkerThum
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.nearby.NearbyBaseMarker;
import io.reactivex.Observable;
import java.lang.reflect.Proxy;
import java.util.List;
@ -159,30 +158,28 @@ public class ExploreMapPresenter
* @param explorePlacesInfo This variable has placeToCenter list information and distances.
*/
public void updateMapMarkers(
MapController.ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker) {
MapController.ExplorePlacesInfo explorePlacesInfo) {
if (explorePlacesInfo.mediaList != null) {
prepareNearbyBaseMarkers(explorePlacesInfo, selectedMarker);
prepareNearbyBaseMarkers(explorePlacesInfo);
} else {
lockUnlockNearby(false); // So that new location updates wont come
exploreMapFragmentView.setProgressBarVisibility(false);
}
}
void prepareNearbyBaseMarkers(MapController.ExplorePlacesInfo explorePlacesInfo,
Marker selectedMarker) {
void prepareNearbyBaseMarkers(MapController.ExplorePlacesInfo explorePlacesInfo) {
exploreMapController
.loadAttractionsFromLocationToBaseMarkerOptions(explorePlacesInfo.curLatLng,
// Curlatlang will be used to calculate distances
explorePlacesInfo.explorePlaceList,
exploreMapFragmentView.getContext(),
this,
selectedMarker,
explorePlacesInfo);
}
@Override
public void onNearbyBaseMarkerThumbsReady(List<NearbyBaseMarker> baseMarkers,
ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker) {
public void onNearbyBaseMarkerThumbsReady(List<BaseMarker> baseMarkers,
ExplorePlacesInfo explorePlacesInfo) {
if (null != exploreMapFragmentView) {
exploreMapFragmentView.addMarkersToMap(baseMarkers);
lockUnlockNearby(false); // So that new location updates wont come

View file

@ -47,9 +47,8 @@ import com.facebook.drawee.controller.ControllerListener;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.imagepipeline.image.ImageInfo;
import com.facebook.imagepipeline.request.ImageRequest;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.CameraPosition;
import fr.free.nrw.commons.LocationPicker.LocationPicker;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.MediaDataExtractor;
@ -872,9 +871,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
startActivity(new LocationPicker.IntentBuilder()
.defaultLocation(new CameraPosition.Builder()
.target(new LatLng(defaultLatitude, defaultLongitude))
.zoom(16).build())
.defaultLocation(new CameraPosition(defaultLatitude,defaultLongitude,16.0))
.activityKey("MediaActivity")
.media(media)
.build(getActivity()));

View file

@ -1,26 +1,18 @@
package fr.free.nrw.commons.nearby;
import com.mapbox.mapboxsdk.annotations.Marker;
/**
* This class groups visual map item Marker with the reated data of displayed place and information
* of bookmark
*/
public class MarkerPlaceGroup {
private Marker marker; // Marker item from the map
private boolean isBookmarked; // True if user bookmarked the place
private Place place; // Place of the location displayed by the marker
public MarkerPlaceGroup(Marker marker, boolean isBookmarked, Place place) {
this.marker = marker;
public MarkerPlaceGroup(boolean isBookmarked, Place place) {
this.isBookmarked = isBookmarked;
this.place = place;
}
public Marker getMarker() {
return marker;
}
public Place getPlace() {
return place;
}

View file

@ -1,93 +0,0 @@
package fr.free.nrw.commons.nearby;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import java.util.Objects;
public class NearbyBaseMarker extends BaseMarkerOptions<NearbyMarker, NearbyBaseMarker> {
public static final Parcelable.Creator<NearbyBaseMarker> CREATOR = new Parcelable.Creator<NearbyBaseMarker>() {
@Override
public NearbyBaseMarker createFromParcel(Parcel in) {
return new NearbyBaseMarker(in);
}
@Override
public NearbyBaseMarker[] newArray(int size) {
return new NearbyBaseMarker[size];
}
};
private Place place;
public NearbyBaseMarker() {
}
private NearbyBaseMarker(Parcel in) {
position(in.readParcelable(LatLng.class.getClassLoader()));
snippet(in.readString());
String iconId = in.readString();
Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());
Icon icon = IconFactory.recreate(iconId, iconBitmap);
icon(icon);
title(in.readString());
place(in.readParcelable(Place.class.getClassLoader()));
}
public NearbyBaseMarker place(Place place) {
this.place = place;
return this;
}
@Override
public NearbyBaseMarker getThis() {
return this;
}
@Override
public NearbyMarker getMarker() {
return new NearbyMarker(this, place);
}
public Place getPlace() {
return place;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(position, flags);
dest.writeString(snippet);
dest.writeString(icon.getId());
dest.writeParcelable(icon.getBitmap(), flags);
dest.writeString(title);
dest.writeParcelable(place, 0);
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final NearbyBaseMarker that = (NearbyBaseMarker) o;
return Objects.equals(place.location, that.place.location);
}
@Override
public int hashCode() {
return Objects.hash(place);
}
}

View file

@ -1,18 +1,11 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import androidx.annotation.MainThread;
import androidx.annotation.Nullable;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
import fr.free.nrw.commons.BaseMarker;
import fr.free.nrw.commons.MapController;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.utils.UiUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -36,8 +29,6 @@ public class NearbyController extends MapController {
public static double latestSearchRadius = 10.0; // Any last search radius except closest result search
public static List<MarkerPlaceGroup> markerLabelList = new ArrayList<>();
public static Map<Boolean, Marker> markerExistsMap;
public static Map<Boolean, Marker> markerNeedPicMap;
@Inject
public NearbyController(NearbyPlaces nearbyPlaces) {
@ -151,80 +142,32 @@ public class NearbyController extends MapController {
* @param placeList list of nearby places in Place data type
* @return BaseMarkerOptions list that holds nearby places
*/
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
public static List<BaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
LatLng curLatLng,
List<Place> placeList,
Context context,
List<Place> bookmarkplacelist) {
List<NearbyBaseMarker> baseMarkerOptions = new ArrayList<>();
List<Place> placeList) {
List<BaseMarker> baseMarkersList = new ArrayList<>();
if (placeList == null) {
return baseMarkerOptions;
return baseMarkersList;
}
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
VectorDrawableCompat vectorDrawable = null;
VectorDrawableCompat vectorDrawableGreen = null;
VectorDrawableCompat vectorDrawableGrey = null;
VectorDrawableCompat vectorDrawableMonuments = null;
vectorDrawable = null;
try {
vectorDrawable = VectorDrawableCompat.create(
context.getResources(), R.drawable.ic_custom_map_marker, context.getTheme());
vectorDrawableGreen = VectorDrawableCompat.create(
context.getResources(), R.drawable.ic_custom_map_marker_green, context.getTheme());
vectorDrawableGrey = VectorDrawableCompat.create(
context.getResources(), R.drawable.ic_custom_map_marker_grey, context.getTheme());
vectorDrawableMonuments = VectorDrawableCompat
.create(context.getResources(), R.drawable.ic_custom_map_marker_monuments,
context.getTheme());
} catch (Resources.NotFoundException e) {
// ignore when running tests.
}
if (vectorDrawable != null) {
Bitmap icon = UiUtils.getBitmap(vectorDrawable);
Bitmap iconGreen = UiUtils.getBitmap(vectorDrawableGreen);
Bitmap iconGrey = UiUtils.getBitmap(vectorDrawableGrey);
Bitmap iconMonuments = UiUtils.getBitmap(vectorDrawableMonuments);
for (Place place : placeList) {
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
BaseMarker baseMarker = new BaseMarker();
String distance = formatDistanceBetween(curLatLng, place.location);
place.setDistance(distance);
nearbyBaseMarker.title(place.name);
nearbyBaseMarker.position(
new com.mapbox.mapboxsdk.geometry.LatLng(
baseMarker.setTitle(place.name);
baseMarker.setPosition(
new fr.free.nrw.commons.location.LatLng(
place.location.getLatitude(),
place.location.getLongitude()));
nearbyBaseMarker.place(place);
// Check if string is only spaces or empty, if so place doesn't have any picture
if (place.isMonument()) {
nearbyBaseMarker.icon(IconFactory.getInstance(context)
.fromBitmap(iconMonuments));
}
else if (!place.pic.trim().isEmpty()) {
if (iconGreen != null) {
nearbyBaseMarker.icon(IconFactory.getInstance(context)
.fromBitmap(iconGreen));
}
} else if (!place.exists) { // Means that the topic of the Wikidata item does not exist in the real world anymore, for instance it is a past event, or a place that was destroyed
if (iconGrey != null) {
nearbyBaseMarker.icon(IconFactory.getInstance(context)
.fromBitmap(iconGrey));
}
} else {
nearbyBaseMarker.icon(IconFactory.getInstance(context)
.fromBitmap(icon));
}
baseMarkerOptions.add(nearbyBaseMarker);
place.location.getLongitude(),0));
baseMarker.setPlace(place);
baseMarkersList.add(baseMarker);
}
return baseMarkersList;
}
return baseMarkerOptions;
}
/**
* Updates makerLabelList item isBookmarked value
@ -236,7 +179,7 @@ public class NearbyController extends MapController {
for (ListIterator<MarkerPlaceGroup> iter = markerLabelList.listIterator(); iter.hasNext();) {
MarkerPlaceGroup markerPlaceGroup = iter.next();
if (markerPlaceGroup.getPlace().getWikiDataEntityId().equals(place.getWikiDataEntityId())) {
iter.set(new MarkerPlaceGroup(markerPlaceGroup.getMarker(), isBookmarked, place));
iter.set(new MarkerPlaceGroup(isBookmarked, place));
}
}
}

View file

@ -1,27 +0,0 @@
package fr.free.nrw.commons.nearby;
import com.mapbox.mapboxsdk.annotations.Marker;
public class NearbyMarker extends Marker {
private final Place place;
private NearbyBaseMarker nearbyBaseMarker;
/**
* Creates a instance of {@link Marker} using the builder of Marker.
*
* @param baseMarkerOptions The builder used to construct the Marker.
*/
NearbyMarker(NearbyBaseMarker baseMarkerOptions, Place place) {
super(baseMarkerOptions);
this.place = place;
this.nearbyBaseMarker = baseMarkerOptions;
}
public NearbyBaseMarker getNearbyBaseMarker() {
return nearbyBaseMarker;
}
public Place getPlace() {
return place;
}
}

View file

@ -2,12 +2,11 @@ package fr.free.nrw.commons.nearby.contract;
import android.content.Context;
import androidx.annotation.Nullable;
import com.mapbox.mapboxsdk.annotations.Marker;
import fr.free.nrw.commons.BaseMarker;
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.nearby.Label;
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
import fr.free.nrw.commons.nearby.Place;
import java.util.List;
@ -45,16 +44,12 @@ public interface NearbyParentFragmentContract {
void hideBottomDetailsSheet();
void displayBottomSheetWithInfo(Marker marker);
void addSearchThisAreaButtonAction();
void setSearchThisAreaButtonVisibility(boolean isVisible);
void setProgressBarVisibility(boolean isVisible);
void setTabItemContributions();
boolean isDetailsBottomSheetVisible();
void setBottomSheetDetailsSmaller();
@ -75,18 +70,14 @@ public interface NearbyParentFragmentContract {
void addCurrentLocationMarker(LatLng curLatLng);
void updateMapToTrackPosition(LatLng curLatLng);
void clearAllMarkers();
Context getContext();
void updateMapMarkers(List<NearbyBaseMarker> nearbyBaseMarkers, Marker selectedMarker);
void updateMapMarkers(List<BaseMarker> BaseMarkers);
void filterOutAllMarkers();
void displayAllMarkers();
void filterMarkersByLabels(List<Label> selectedLabels, boolean existsSelected,
boolean needPhotoSelected, boolean wlmSelected, boolean filterForPlaceState,
boolean filterForAllNoneType);
@ -105,15 +96,9 @@ public interface NearbyParentFragmentContract {
LatLng getMapFocus();
com.mapbox.mapboxsdk.geometry.LatLng getLastFocusLocation();
boolean isCurrentLocationMarkerVisible();
boolean isAdvancedQueryFragmentVisible();
void showHideAdvancedQueryFragment(boolean shouldShow);
void centerMapToPosition(@Nullable LatLng searchLatLng);
}
interface NearbyListView {
@ -137,12 +122,10 @@ public interface NearbyParentFragmentContract {
boolean backButtonClicked();
void onCameraMove(com.mapbox.mapboxsdk.geometry.LatLng latLng);
void filterByMarkerType(List<Label> selectedLabels, int state, boolean filterForPlaceState,
boolean filterForAllNoneType);
void updateMapMarkersToController(List<NearbyBaseMarker> nearbyBaseMarkers);
void updateMapMarkersToController(List<BaseMarker> baseMarkers);
void searchViewGainedFocus();

View file

@ -68,9 +68,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.jakewharton.rxbinding2.view.RxView;
import com.jakewharton.rxbinding3.appcompat.RxSearchView;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import fr.free.nrw.commons.BaseMarker;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.MapController.NearbyPlacesInfo;
import fr.free.nrw.commons.R;
@ -87,11 +85,9 @@ 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.NearbyFilterSearchRecyclerViewAdapter;
import fr.free.nrw.commons.nearby.NearbyFilterState;
import fr.free.nrw.commons.nearby.NearbyMarker;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
import fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback;
@ -100,7 +96,6 @@ import fr.free.nrw.commons.upload.FileUtils;
import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.ExecutorUtils;
import fr.free.nrw.commons.utils.LayoutUtils;
import fr.free.nrw.commons.utils.LocationUtils;
import fr.free.nrw.commons.utils.NearbyFABUtils;
import fr.free.nrw.commons.utils.NetworkUtils;
import fr.free.nrw.commons.utils.PermissionUtils;
@ -259,7 +254,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
private NearbyParentFragmentPresenter presenter;
private boolean isDarkTheme;
private boolean isFABsExpanded;
private Marker selectedMarker;
private Place selectedPlace;
private Place clickedMarkerPlace;
private boolean isClickedMarkerBookmarked;
@ -269,12 +263,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
private boolean recenterToUserLocation;
private GeoPoint mapCenter;
IntentFilter intentFilter = new IntentFilter(NETWORK_INTENT_ACTION);
private Marker currentLocationMarker;
private Place lastPlaceToCenter;
private fr.free.nrw.commons.location.LatLng lastKnownLocation;
private boolean isVisibleToUser;
private fr.free.nrw.commons.location.LatLng lastFocusLocation;
private LatLngBounds latLngBounds;
private PlaceAdapter adapter;
private GeoPoint lastMapFocus;
private NearbyParentFragmentInstanceReadyCallback nearbyParentFragmentInstanceReadyCallback;
@ -1060,22 +1052,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
return mapFocusedLatLng;
}
@Override
public LatLng getLastFocusLocation() {
return lastFocusLocation == null ? null
: LocationUtils.commonsLatLngToMapBoxLatLng(lastFocusLocation);
}
@Override
public boolean isCurrentLocationMarkerVisible() {
if (latLngBounds == null || currentLocationMarker == null) {
Timber.d("Map projection bounds are null");
return false;
} else {
return latLngBounds.contains(currentLocationMarker.getPosition());
}
}
@Override
public boolean isAdvancedQueryFragmentVisible() {
return isAdvancedQueryFragmentVisible;
@ -1088,16 +1064,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
isAdvancedQueryFragmentVisible = shouldShow;
}
@Override
public void centerMapToPosition(fr.free.nrw.commons.location.LatLng searchLatLng) {
if (null != searchLatLng && !(
mapView.getMapCenter().getLatitude() == searchLatLng.getLatitude()
&& mapView.getMapCenter().getLongitude() == searchLatLng.getLongitude())) {
recenterMarkerToPosition(
new GeoPoint(searchLatLng.getLatitude(), searchLatLng.getLongitude()));
}
}
@Override
public boolean isNetworkConnectionEstablished() {
return NetworkUtils.isInternetConnectionEstablished(getActivity());
@ -1256,8 +1222,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
*/
private void updateMapMarkers(final NearbyController.NearbyPlacesInfo nearbyPlacesInfo,
final boolean shouldUpdateSelectedMarker) {
presenter.updateMapMarkers(nearbyPlacesInfo, selectedMarker, shouldUpdateSelectedMarker);
//TODO
presenter.updateMapMarkers(nearbyPlacesInfo, shouldUpdateSelectedMarker);
setFilterState();
}
@ -1320,7 +1285,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
}
@Override
public void setTabItemContributions() {
((MainActivity) getActivity()).binding.pager.setCurrentItem(0);
// TODO
@ -1492,7 +1456,7 @@ 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%.
* <p>
* Should be called only on creation of mapboxMap, there is other method to update markers
* Should be called only on creation of Map, there is other method to update markers
* location with users move.
*
* @param curLatLng current location
@ -1510,24 +1474,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
}
/**
* 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");
if (null != mapView) {
recenterMap(curLatLng);
}
}
@Override
public void updateMapMarkers(final List<NearbyBaseMarker> nearbyBaseMarkers,
final Marker selectedMarker) {
public void updateMapMarkers(final List<BaseMarker> BaseMarkers) {
if (mapView != null) {
presenter.updateMapMarkersToController(nearbyBaseMarkers);
presenter.updateMapMarkersToController(BaseMarkers);
}
}
@ -1536,17 +1486,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
clearAllMarkers();
}
/**
* Displays all markers
*/
@Override
public void displayAllMarkers() {
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(),
NearbyController.currentLocation);
}
}
/**
* Filters markers based on selectedLabels and chips
*
@ -1610,13 +1549,13 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
}
if (selectedLabels == null || selectedLabels.size() == 0) {
ArrayList<NearbyBaseMarker> markerArrayList = new ArrayList<>();
ArrayList<BaseMarker> markerArrayList = new ArrayList<>();
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
nearbyBaseMarker.place(markerPlaceGroup.getPlace());
BaseMarker nearbyBaseMarker = new BaseMarker();
nearbyBaseMarker.setPlace(markerPlaceGroup.getPlace());
markerArrayList.add(nearbyBaseMarker);
}
addMarkersToMap(markerArrayList, null);
addMarkersToMap(markerArrayList);
}
}
@ -1727,8 +1666,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
* @param nearbyBaseMarkers The list of Place objects containing information about the
* locations.
*/
private void addMarkersToMap(List<NearbyBaseMarker> nearbyBaseMarkers,
final Marker selectedMarker) {
private void addMarkersToMap(List<BaseMarker> nearbyBaseMarkers) {
ArrayList<OverlayItem> items = new ArrayList<>();
for (int i = 0; i < nearbyBaseMarkers.size(); i++) {
Drawable icon = ContextCompat.getDrawable(getContext(),
@ -1854,16 +1792,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
@Override
public void displayBottomSheetWithInfo(final Marker marker) {
selectedMarker = marker;
final NearbyMarker nearbyMarker = (NearbyMarker) marker;
final Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
passInfoToSheet(place);
hideBottomSheet();
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
/**
* 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

View file

@ -14,7 +14,7 @@ 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.BaseMarker;
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
@ -23,14 +23,12 @@ 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;
@ -138,12 +136,6 @@ public class NearbyParentFragmentPresenter
nearbyParentFragmentView.hideBottomSheet();
}
public void markerSelected(Marker marker) {
nearbyParentFragmentView.displayBottomSheetWithInfo(marker);
}
/**
* 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.
@ -215,9 +207,6 @@ public class NearbyParentFragmentPresenter
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
nearbyParentFragmentView.recenterMap(curLatLng);
}
}
}
@ -227,17 +216,14 @@ public class NearbyParentFragmentPresenter
*
* @param nearbyPlacesInfo This variable has placeToCenter list information and distances.
*/
public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo,
Marker selectedMarker, boolean shouldTrackPosition) {
public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo, boolean shouldTrackPosition) {
if (null != nearbyParentFragmentView) {
nearbyParentFragmentView.clearAllMarkers();
List<NearbyBaseMarker> nearbyBaseMarkers = NearbyController
List<BaseMarker> baseMarkers = NearbyController
.loadAttractionsFromLocationToBaseMarkerOptions(nearbyPlacesInfo.curLatLng,
// Curlatlang will be used to calculate distances
nearbyPlacesInfo.placeList,
nearbyParentFragmentView.getContext(),
bookmarkLocationDao.getAllBookmarksLocations());
nearbyParentFragmentView.updateMapMarkers(nearbyBaseMarkers, selectedMarker);
nearbyPlacesInfo.placeList);
nearbyParentFragmentView.updateMapMarkers(baseMarkers);
lockUnlockNearby(false); // So that new location updates wont come
nearbyParentFragmentView.setProgressBarVisibility(false);
nearbyParentFragmentView.updateListFragment(nearbyPlacesInfo.placeList);
@ -277,24 +263,6 @@ public class NearbyParentFragmentPresenter
Timber.d("Location changed medium");
}
@Override
public void onCameraMove(com.mapbox.mapboxsdk.geometry.LatLng latLng) {
// 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);
}
}
@Override
public void filterByMarkerType(List<Label> selectedLabels, int state,
boolean filterForPlaceState, boolean filterForAllNoneType) {
@ -329,23 +297,14 @@ public class NearbyParentFragmentPresenter
@Override
@MainThread
public void updateMapMarkersToController(List<NearbyBaseMarker> nearbyBaseMarkers) {
NearbyController.markerExistsMap = new HashMap<>();
NearbyController.markerNeedPicMap = new HashMap<>();
public void updateMapMarkersToController(List<BaseMarker> baseMarkers) {
NearbyController.markerLabelList.clear();
for (int i = 0; i < nearbyBaseMarkers.size(); i++) {
NearbyBaseMarker nearbyBaseMarker = nearbyBaseMarkers.get(i);
for (int i = 0; i < baseMarkers.size(); i++) {
BaseMarker nearbyBaseMarker = baseMarkers.get(i);
NearbyController.markerLabelList.add(
new MarkerPlaceGroup(nearbyBaseMarker.getMarker(),
new MarkerPlaceGroup(
bookmarkLocationDao.findBookmarkLocation(nearbyBaseMarker.getPlace()),
nearbyBaseMarker.getPlace()));
//TODO: fix bookmark location
NearbyController.markerExistsMap.put(
(nearbyBaseMarkers.get(i).getPlace().hasWikidataLink()),
nearbyBaseMarkers.get(i).getMarker());
NearbyController.markerNeedPicMap.put(
((nearbyBaseMarkers.get(i).getPlace().pic == null) ? true : false),
nearbyBaseMarkers.get(i).getMarker());
}
}
@ -414,14 +373,4 @@ public class NearbyParentFragmentPresenter
initializeMapOperations();
}
}
public boolean areLocationsClose(LatLng cameraTarget, LatLng lastKnownLocation) {
double distance = LocationUtils.commonsLatLngToMapBoxLatLng(cameraTarget)
.distanceTo(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation));
if (distance > NearbyController.currentLocationSearchRadius * 3 / 4) {
return false;
} else {
return true;
}
}
}

View file

@ -22,7 +22,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import fr.free.nrw.commons.CameraPosition;
import fr.free.nrw.commons.LocationPicker.LocationPicker;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.MainActivity;
@ -558,10 +558,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
defaultLongitude = uploadItem.getGpsCoords().getDecLongitude();
defaultZoom = uploadItem.getGpsCoords().getZoomLevel();
startActivityForResult(new LocationPicker.IntentBuilder()
.defaultLocation(new CameraPosition.Builder()
.target(
new com.mapbox.mapboxsdk.geometry.LatLng(defaultLatitude, defaultLongitude))
.zoom(defaultZoom).build())
.defaultLocation(new CameraPosition(defaultLatitude,defaultLongitude,defaultZoom))
.activityKey("UploadActivity")
.build(getActivity()), REQUEST_CODE);
} else {
@ -575,10 +572,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
defaultZoom = Double.parseDouble(defaultKvStore.getString(LAST_ZOOM));
}
startActivityForResult(new LocationPicker.IntentBuilder()
.defaultLocation(new CameraPosition.Builder()
.target(
new com.mapbox.mapboxsdk.geometry.LatLng(defaultLatitude, defaultLongitude))
.zoom(defaultZoom).build())
.defaultLocation(new CameraPosition(defaultLatitude,defaultLongitude,defaultZoom))
.activityKey("NoLocationUploadActivity")
.build(getActivity()), REQUEST_CODE);
}
@ -601,9 +595,9 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
if (cameraPosition != null) {
final String latitude = String.valueOf(cameraPosition.target.getLatitude());
final String longitude = String.valueOf(cameraPosition.target.getLongitude());
final double zoom = cameraPosition.zoom;
final String latitude = String.valueOf(cameraPosition.getLatitude());
final String longitude = String.valueOf(cameraPosition.getLongitude());
final double zoom = cameraPosition.getZoom();
editLocation(latitude, longitude, zoom);
/*

View file

@ -4,13 +4,7 @@ import fr.free.nrw.commons.location.LatLng;
import timber.log.Timber;
public class LocationUtils {
public static LatLng mapBoxLatLngToCommonsLatLng(com.mapbox.mapboxsdk.geometry.LatLng mapBoxLatLng) {
return new LatLng(mapBoxLatLng.getLatitude(), mapBoxLatLng.getLongitude(), 0);
}
public static com.mapbox.mapboxsdk.geometry.LatLng commonsLatLngToMapBoxLatLng(LatLng commonsLatLng) {
return new com.mapbox.mapboxsdk.geometry.LatLng(commonsLatLng.getLatitude(), commonsLatLng.getLongitude());
}
public static final double RADIUS_OF_EARTH_KM = 6371.0; // Earth's radius in kilometers
public static LatLng deriveUpdatedLocationFromSearchQuery(String customQuery) {
LatLng latLng = null;
@ -43,4 +37,22 @@ public class LocationUtils {
return latLng;
}
public static double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
double lat1Rad = Math.toRadians(lat1);
double lon1Rad = Math.toRadians(lon1);
double lat2Rad = Math.toRadians(lat2);
double lon2Rad = Math.toRadians(lon2);
// Haversine formula
double dlon = lon2Rad - lon1Rad;
double dlat = lat2Rad - lat1Rad;
double a = Math.pow(Math.sin(dlat / 2), 2) + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.pow(Math.sin(dlon / 2), 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double distance = RADIUS_OF_EARTH_KM * c;
return distance;
}
}

View file

@ -1,14 +1,8 @@
package fr.free.nrw.commons.utils;
import android.content.Context;
import android.content.res.Configuration;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.location.LocationUpdateListener;
import fr.free.nrw.commons.nearby.Place;
import timber.log.Timber;
public class MapUtils {
@ -20,40 +14,6 @@ public class MapUtils {
public static final LatLng defaultLatLng = new fr.free.nrw.commons.location.LatLng(51.50550,-0.07520,1f);
public static void centerMapToPlace(Place placeToCenter, MapboxMap mapBox, Place lastPlaceToCenter, Context context) {
Timber.d("Map is centered to place");
final double cameraShift;
if(null != placeToCenter){
lastPlaceToCenter = placeToCenter;
}
if (null != lastPlaceToCenter) {
final Configuration configuration = context.getResources().getConfiguration();
if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
cameraShift = CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT;
} else {
cameraShift = CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE;
}
final CameraPosition position = new CameraPosition.Builder()
.target(LocationUtils.commonsLatLngToMapBoxLatLng(
new fr.free.nrw.commons.location.LatLng(lastPlaceToCenter.location.getLatitude() - cameraShift,
lastPlaceToCenter.getLocation().getLongitude(),
0))) // Sets the new camera position
.zoom(ZOOM_LEVEL) // Same zoom level
.build();
mapBox.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
}
}
public static void centerMapToDefaultLatLng(MapboxMap mapBox) {
final CameraPosition position = new CameraPosition.Builder()
.target(LocationUtils.commonsLatLngToMapBoxLatLng(defaultLatLng))
.zoom(MapUtils.ZOOM_OUT)
.build();
if(mapBox != null){
mapBox.moveCamera(CameraUpdateFactory.newCameraPosition(position));
}
}
public static void registerUnregisterLocationListener(final boolean removeLocationListener, LocationServiceManager locationManager, LocationUpdateListener locationUpdateListener) {
try {
if (removeLocationListener) {

View file

@ -36,28 +36,4 @@ public class UiUtils {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
/**
* Creates a series of points that create a circle on the map.
* Takes the center latitude, center longitude of the circle,
* the radius in meter and the number of nodes of the circle.
*
* @return List List of LatLng points of the circle.
*/
public static List<com.mapbox.mapboxsdk.geometry.LatLng> createCircleArray(
double centerLat, double centerLong, float radius, int nodes) {
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = new ArrayList<>();
float radiusKilometer = radius / 1000;
double radiusLong = radiusKilometer
/ (111.320 * Math.cos(centerLat * Math.PI / 180));
double radiusLat = radiusKilometer / 110.574;
for (int i = 0; i < nodes; i++) {
double theta = ((double) i / (double) nodes) * (2 * Math.PI);
double nodeLongitude = centerLong + radiusLong * Math.cos(theta);
double nodeLatitude = centerLat + radiusLat * Math.sin(theta);
circle.add(new com.mapbox.mapboxsdk.geometry.LatLng(nodeLatitude, nodeLongitude));
}
return circle;
}
}

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Authors:
* Winston Sung
-->
<resources>
<string name="crash_dialog_title">同享壞咗</string>
<string name="crash_dialog_text">哎呀。出咗錯!</string>
<string name="crash_dialog_ok_toast">多謝你!</string>
</resources>

View file

@ -18,7 +18,7 @@ class NearbyControllerTest {
val location = LatLng(0.0, 0.0, 0f)
val options = loadAttractionsFromLocationToBaseMarkerOptions(
location, null, ApplicationProvider.getApplicationContext(), null)
location, null)
assertEquals(0, options.size.toLong())
}
@ -28,7 +28,7 @@ class NearbyControllerTest {
val location = LatLng(0.0, 0.0, 0f)
val options = loadAttractionsFromLocationToBaseMarkerOptions(
location, emptyList(), ApplicationProvider.getApplicationContext(), emptyList())
location, emptyList())
assertEquals(0, options.size.toLong())
}

View file

@ -9,21 +9,13 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.maps.UiSettings
import com.mapbox.mapboxsdk.style.layers.Layer
import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import fr.free.nrw.commons.CameraPosition
import fr.free.nrw.commons.LocationPicker.LocationPickerActivity
import fr.free.nrw.commons.Media
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.coordinates.CoordinateEditHelper
import fr.free.nrw.commons.kvstore.JsonKvStore
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.LAST_LOCATION
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.LAST_ZOOM

View file

@ -2,11 +2,11 @@ package fr.free.nrw.commons.locationpicker
import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import fr.free.nrw.commons.CameraPosition
import fr.free.nrw.commons.LocationPicker.LocationPickerViewModel
import org.junit.Before
import org.junit.Test

View file

@ -1,92 +0,0 @@
package fr.free.nrw.commons.nearby
import android.os.Parcel
import com.mapbox.mapboxsdk.annotations.Icon
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.powermock.reflect.Whitebox
class NearbyBaseMarkerUnitTests {
private lateinit var marker: NearbyBaseMarker
@Mock
private lateinit var place: Place
@Mock
private lateinit var parcel: Parcel
@Mock
private lateinit var icon: Icon
@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
marker = NearbyBaseMarker()
Whitebox.setInternalState(marker, "icon", icon)
}
@Test
@Throws(Exception::class)
fun checkNotNull() {
Assert.assertNotNull(marker)
}
@Test
@Throws(Exception::class)
fun testPlace() {
marker.place(place)
}
@Test
@Throws(Exception::class)
fun testGetThis() {
marker.getThis()
}
@Test
@Throws(Exception::class)
fun testGetMarker() {
marker.marker
}
@Test
@Throws(Exception::class)
fun testGetPlace() {
marker.place
}
@Test
@Throws(Exception::class)
fun testDescribeContents() {
marker.describeContents()
}
@Test
@Throws(Exception::class)
fun testWriteToParcel() {
marker.writeToParcel(parcel, 0)
}
@Test
@Throws(Exception::class)
fun testEquals() {
marker.equals(this)
}
@Test
@Throws(Exception::class)
fun testEqualsCaseNull() {
Assert.assertFalse(marker.equals(this))
}
@Test
@Throws(Exception::class)
fun testHashCode() {
marker.hashCode()
}
}

View file

@ -5,6 +5,7 @@ import androidx.test.core.app.ApplicationProvider
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.anyOrNull
import com.nhaarman.mockitokotlin2.eq
import fr.free.nrw.commons.BaseMarker
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.location.LatLng
import fr.free.nrw.commons.nearby.NearbyController.loadAttractionsFromLocationToBaseMarkerOptions
@ -239,10 +240,8 @@ class NearbyControllerTest {
assertEquals(
loadAttractionsFromLocationToBaseMarkerOptions(
currentLatLng,
null,
context,
mutableListOf(place)
), listOf<NearbyBaseMarker>()
null
), listOf<BaseMarker>()
)
}
@ -265,9 +264,7 @@ class NearbyControllerTest {
assertEquals(
loadAttractionsFromLocationToBaseMarkerOptions(
currentLatLng,
listOf(place),
context,
mutableListOf(place)
listOf(place)
)[0].place, place
)
}
@ -291,9 +288,7 @@ class NearbyControllerTest {
assertEquals(
loadAttractionsFromLocationToBaseMarkerOptions(
currentLatLng,
listOf(place),
context,
mutableListOf(place)
listOf(place)
)[0].place, place
)
}
@ -317,9 +312,7 @@ class NearbyControllerTest {
assertEquals(
loadAttractionsFromLocationToBaseMarkerOptions(
currentLatLng,
listOf(place),
context,
mutableListOf(place)
listOf(place)
)[0].place, place
)
}
@ -343,16 +336,14 @@ class NearbyControllerTest {
assertEquals(
loadAttractionsFromLocationToBaseMarkerOptions(
currentLatLng,
listOf(place),
context,
mutableListOf(place)
listOf(place)
)[0].place, place
)
}
@Test
fun testUpdateMarkerLabelListBookmarkCaseTrue() {
markerPlaceGroup = MarkerPlaceGroup(null, true, place)
markerPlaceGroup = MarkerPlaceGroup(true, place)
`when`(place.wikiDataEntityId).thenReturn("someString")
val list = mutableListOf(markerPlaceGroup)
Whitebox.setInternalState(
@ -363,12 +354,11 @@ class NearbyControllerTest {
updateMarkerLabelListBookmark(place, false)
assertEquals(list[0].isBookmarked, false)
assertEquals(list[0].place, place)
assertEquals(list[0].marker, null)
}
@Test
fun testUpdateMarkerLabelListBookmarkCaseFalse() {
markerPlaceGroup = MarkerPlaceGroup(null, false, place)
markerPlaceGroup = MarkerPlaceGroup(false, place)
`when`(place.wikiDataEntityId).thenReturn("someString")
val list = mutableListOf(markerPlaceGroup)
Whitebox.setInternalState(
@ -379,7 +369,6 @@ class NearbyControllerTest {
updateMarkerLabelListBookmark(place, true)
assertEquals(list[0].isBookmarked, true)
assertEquals(list[0].place, place)
assertEquals(list[0].marker, null)
}
fun <T> any(type: Class<T>): T = Mockito.any(type)

View file

@ -1,6 +1,5 @@
package fr.free.nrw.commons.nearby
import com.mapbox.mapboxsdk.annotations.Marker
import com.nhaarman.mockitokotlin2.*
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
import fr.free.nrw.commons.location.LatLng
@ -17,8 +16,6 @@ import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.any
import org.mockito.Mockito.anyBoolean
import org.mockito.Mockito.anyDouble
import org.mockito.Mockito.anyFloat
import org.mockito.Mockito.verifyNoInteractions
import org.mockito.MockitoAnnotations
import java.util.*
@ -43,14 +40,10 @@ class NearbyParentFragmentPresenterTest {
@Mock
internal lateinit var selectedLabels: List<Label>
@Mock
internal lateinit var marker: Marker
@Mock
internal lateinit var nearbyPlaces: NearbyPlaces
private lateinit var nearbyPresenter: NearbyParentFragmentPresenter
private lateinit var mapboxCameraTarget: com.mapbox.mapboxsdk.geometry.LatLng
/**
* initial setup
@ -193,7 +186,6 @@ class NearbyParentFragmentPresenterTest {
@Test
fun testUserTrackedWhenCurrentLocationMarkerVisible() {
expectMapAndListUpdate()
whenever(nearbyParentFragmentView.isCurrentLocationMarkerVisible()).thenReturn(true)
whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng(2.0, 1.0, 0.0F))
whenever(nearbyParentFragmentView.mapCenter).thenReturn(null);
nearbyPresenter.updateMapAndList(LocationChangeType.LOCATION_SLIGHTLY_CHANGED)
@ -209,17 +201,15 @@ class NearbyParentFragmentPresenterTest {
fun testUserNotTrackedWhenCurrentLocationMarkerInvisible() {
expectMapAndListUpdate()
verify(nearbyParentFragmentView).enableFABRecenter()
whenever(nearbyParentFragmentView.isCurrentLocationMarkerVisible()).thenReturn(false)
whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng(2.0, 1.0, 0.0F))
whenever(nearbyParentFragmentView.mapCenter).thenReturn(null);
nearbyPresenter.updateMapAndList(LocationChangeType.LOCATION_SLIGHTLY_CHANGED)
verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
verify(nearbyParentFragmentView).getLastMapFocus()
verify(nearbyParentFragmentView).getMapCenter()
verify(nearbyParentFragmentView).isCurrentLocationMarkerVisible()
verifyNoMoreInteractions(nearbyParentFragmentView)
}
// Set this test function to @Ignore because of change in functionalities due to Mapbox to osmdroid transition.
/**
* Test search this area button became visible after user moved the camera target to far
* away from current target. Distance between these two point is 111.19 km, so our camera target
@ -229,31 +219,12 @@ class NearbyParentFragmentPresenterTest {
@Test @Ignore
fun testSearchThisAreaButtonVisibleWhenMoveToFarPosition() {
NearbyController.latestSearchLocation = Mockito.spy(LatLng(2.0, 1.0, 0.0F))
mapboxCameraTarget = Mockito.spy(com.mapbox.mapboxsdk.geometry.LatLng(1.0, 1.0, 0.0))
// Distance between these two point is 111.19 km
NearbyController.latestSearchRadius = 111.19 * 1000 // To meter
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true)
nearbyPresenter.onCameraMove(mapboxCameraTarget)
verify(nearbyParentFragmentView).setSearchThisAreaButtonVisibility(true)
}
/**
* Test search this area button became visible after user moved the camera target to far
* away from current target. Distance between these two point is 111.19 km, so our camera target
* is at inside of previously searched region if we set latestSearchRadius above 111.19. Thus,
* setSearchThisAreaButtonVisibility(false) should be verified.
*/
@Test
fun testSearchThisAreaButtonInvisibleWhenMoveToClosePosition() {
NearbyController.latestSearchLocation = Mockito.spy(LatLng(2.0, 1.0, 0.0F))
mapboxCameraTarget = Mockito.spy(com.mapbox.mapboxsdk.geometry.LatLng(1.0, 1.0, 0.0))
// Distance between these two point is 111.19 km
NearbyController.latestSearchRadius = 112.0 * 1000 // To meter
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true)
nearbyPresenter.onCameraMove(mapboxCameraTarget)
verify(nearbyParentFragmentView).setSearchThisAreaButtonVisibility(false)
}
/**
* Multi selection should overwrite single selection of marker types. Ie. when user choose
*"parks", then they multi select to display all or none, we overwrite previous "park" filter.
@ -344,29 +315,11 @@ class NearbyParentFragmentPresenterTest {
verify(nearbyParentFragmentView).hideBottomDetailsSheet()
}
/**
* Test if the search is close to current location, when last location is null we expect it to
* return true
*/
@Test
fun testSearchCloseToCurrentLocationNullLastLocation() {
whenever(nearbyParentFragmentView.getLastFocusLocation()).thenReturn(null)
val isClose = nearbyPresenter?.searchCloseToCurrentLocation()
assertTrue(isClose!!)
}
/**
* Test if the search is close to current location, when far
*/
@Test
fun testSearchCloseToCurrentLocationWhenFar() {
whenever(nearbyParentFragmentView.getLastFocusLocation()).thenReturn(
com.mapbox.mapboxsdk.geometry.LatLng(
1.0,
1.0,
0.0
)
)
whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng(2.0, 1.0, 0.0F));
whenever(nearbyParentFragmentView.mapFocus).thenReturn(LatLng(2.0, 1.0, 0.0F))
//111.19 km real distance, return false if 148306.444306 > currentLocationSearchRadius
@ -380,13 +333,6 @@ class NearbyParentFragmentPresenterTest {
*/
@Test
fun testSearchCloseToCurrentLocationWhenClose() {
whenever(nearbyParentFragmentView.getLastFocusLocation()).thenReturn(
com.mapbox.mapboxsdk.geometry.LatLng(
1.0,
1.0,
0.0
)
)
whenever(nearbyParentFragmentView.getCameraTarget()).thenReturn(LatLng(2.0, 1.0, 0.0F))
//111.19 km real distance, return false if 148253.333 > currentLocationSearchRadius
NearbyController.currentLocationSearchRadius = 148307.0
@ -444,12 +390,6 @@ class NearbyParentFragmentPresenterTest {
verify(nearbyParentFragmentView).hideBottomSheet();
}
@Test
fun testMarkerSelected() {
nearbyPresenter.markerSelected(marker)
verify(nearbyParentFragmentView).displayBottomSheetWithInfo(marker)
}
@Test
fun testOnWikidataEditSuccessful() {
nearbyPresenter.onWikidataEditSuccessful()
@ -473,12 +413,10 @@ class NearbyParentFragmentPresenterTest {
nearbyPresenter.onLocationChangedSlightly(latestLocation)
expectMapAndListUpdate()
verify(nearbyParentFragmentView).enableFABRecenter()
whenever(nearbyParentFragmentView.isCurrentLocationMarkerVisible()).thenReturn(true)
whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng(2.0, 1.0, 0.0F))
whenever(nearbyParentFragmentView.mapCenter).thenReturn(null)
nearbyPresenter.updateMapAndList(LocationChangeType.LOCATION_SLIGHTLY_CHANGED)
verify(nearbyParentFragmentView).getLastMapFocus()
verify(nearbyParentFragmentView).isCurrentLocationMarkerVisible()
verify(nearbyParentFragmentView).recenterMap(nearbyParentFragmentView.lastMapFocus)
}
@ -528,31 +466,6 @@ class NearbyParentFragmentPresenterTest {
expectMapAndListUpdate()
}
@Test
fun testOnCameraMoveWhenSearchLocationNull() {
NearbyController.latestSearchLocation = null
nearbyPresenter.onCameraMove(Mockito.mock(com.mapbox.mapboxsdk.geometry.LatLng::class.java))
verify(nearbyParentFragmentView).setSearchThisAreaButtonVisibility(false)
}
@Test
fun testOnCameraMoveWhenNetworkConnectionNotEstablished() {
NearbyController.latestSearchLocation = latestLocation
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(false)
nearbyPresenter.onCameraMove(Mockito.mock(com.mapbox.mapboxsdk.geometry.LatLng::class.java))
verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
verifyNoMoreInteractions(nearbyParentFragmentView)
}
@Test
fun testOnCameraMoveWhenNetworkConnectionEstablished() {
NearbyController.latestSearchLocation = latestLocation
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(false)
nearbyPresenter.onCameraMove(Mockito.mock(com.mapbox.mapboxsdk.geometry.LatLng::class.java))
verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
verifyNoMoreInteractions(nearbyParentFragmentView)
}
@Test
fun testSetAdvancedQuery() {
nearbyPresenter.setAdvancedQuery("test")
@ -570,8 +483,8 @@ class NearbyParentFragmentPresenterTest {
nearbyPlacesInfo.placeList = null
whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList())
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo, marker, true)
Mockito.verify(nearbyParentFragmentView).updateMapMarkers(any(), eq(marker))
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo, true)
Mockito.verify(nearbyParentFragmentView).updateMapMarkers(any())
Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false)
Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList)

View file

@ -18,12 +18,9 @@ import androidx.fragment.app.FragmentTransaction
import androidx.test.core.app.ApplicationProvider
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import fr.free.nrw.commons.BaseMarker
import fr.free.nrw.commons.OkHttpConnectionFactory
import fr.free.nrw.commons.R
import fr.free.nrw.commons.TestCommonsApplication
@ -66,9 +63,6 @@ class NearbyParentFragmentUnitTest {
@Mock
private lateinit var applicationKvStore: JsonKvStore
@Mock
private lateinit var mapBox: MapboxMap
@Mock
private lateinit var presenter: NearbyParentFragmentPresenter
@ -105,9 +99,6 @@ class NearbyParentFragmentUnitTest {
@Mock
private lateinit var bottomSheetDetails: View
@Mock
private lateinit var marker: NearbyMarker
@Mock
private lateinit var linearLayout: LinearLayout
@ -225,17 +216,6 @@ class NearbyParentFragmentUnitTest {
verify(applicationKvStore, times(1))
.putBoolean("doNotAskForLocationPermission", true)
verify(presenter, times(1)).onMapReady()
val position = CameraPosition.Builder()
.target(
LatLng(
51.50550,
-0.07520, 0.0
)
)
.zoom(0.0)
.build()
verify(mapBox, times(1))
.moveCamera(CameraUpdateFactory.newCameraPosition(position))
}
@Test @Ignore
@ -252,17 +232,6 @@ class NearbyParentFragmentUnitTest {
verify(applicationKvStore, times(1))
.putBoolean("doNotAskForLocationPermission", true)
verify(presenter, times(1)).onMapReady()
val position = CameraPosition.Builder()
.target(
LatLng(
23.76,
56.876, 0.0
)
)
.zoom(14.0)
.build()
verify(mapBox, times(1))
.moveCamera(CameraUpdateFactory.newCameraPosition(position))
}
@Test @Ignore
@ -393,14 +362,12 @@ class NearbyParentFragmentUnitTest {
@Test @Ignore
@Throws(Exception::class)
fun testDisplayBottomSheetWithInfo() {
val nearbyBaseMarker = mock(NearbyBaseMarker::class.java)
val nearbyBaseMarker = mock(BaseMarker::class.java)
val place = mock(Place::class.java)
val label = mock(Label::class.java)
whenever(marker.nearbyBaseMarker).thenReturn(nearbyBaseMarker)
whenever(nearbyBaseMarker.place).thenReturn(place)
whenever(place.label).thenReturn(label)
whenever(place.longDescription).thenReturn("")
fragment.displayBottomSheetWithInfo(marker)
verify(bottomSheetBehavior).state = BottomSheetBehavior.STATE_COLLAPSED
}

View file

@ -18,9 +18,8 @@ import androidx.fragment.app.FragmentTransaction
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ApplicationProvider
import com.github.chrisbanes.photoview.PhotoView
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
import com.nhaarman.mockitokotlin2.mock
import fr.free.nrw.commons.CameraPosition
import fr.free.nrw.commons.LocationPicker.LocationPicker
import fr.free.nrw.commons.LocationPicker.LocationPickerActivity
import fr.free.nrw.commons.OkHttpConnectionFactory
@ -28,6 +27,7 @@ import fr.free.nrw.commons.R
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.createTestClient
import fr.free.nrw.commons.kvstore.JsonKvStore
import fr.free.nrw.commons.location.LatLng
import fr.free.nrw.commons.nearby.Place
import fr.free.nrw.commons.upload.ImageCoordinates
import fr.free.nrw.commons.upload.UploadActivity
@ -355,7 +355,8 @@ class UploadMediaDetailFragmentUnitTest {
val cameraPosition = Mockito.mock(CameraPosition::class.java)
val latLng = Mockito.mock(LatLng::class.java)
Whitebox.setInternalState(cameraPosition, "target", latLng)
Whitebox.setInternalState(cameraPosition, "latitude", latLng.latitude)
Whitebox.setInternalState(cameraPosition, "longitude", latLng.longitude)
Whitebox.setInternalState(fragment, "editableUploadItem", uploadItem)
`when`(LocationPicker.getCameraPosition(intent)).thenReturn(cameraPosition)
@ -376,7 +377,8 @@ class UploadMediaDetailFragmentUnitTest {
val latLng = Mockito.mock(LatLng::class.java)
Whitebox.setInternalState(fragment, "callback", callback)
Whitebox.setInternalState(cameraPosition, "target", latLng)
Whitebox.setInternalState(cameraPosition, "latitude", latLng.latitude)
Whitebox.setInternalState(cameraPosition, "longitude", latLng.longitude)
Whitebox.setInternalState(fragment, "editableUploadItem", uploadItem)
Whitebox.setInternalState(fragment,"isMissingLocationDialog",true)
Whitebox.setInternalState(fragment, "presenter", presenter)

View file

@ -9,26 +9,18 @@ import org.junit.jupiter.api.Assertions.assertEquals
*/
class LocationUtilsTest {
/**
* MapBox LatLng to commons LatLng test.
*/
@Test
fun testMapBoxLatLngToCommonsLatLng() {
val commonsLatLngTest = LocationUtils.mapBoxLatLngToCommonsLatLng(com.mapbox.mapboxsdk.geometry.LatLng(0.0, 0.0))
assertEquals(0.0, commonsLatLngTest.latitude)
assertEquals(0.0, commonsLatLngTest.longitude)
assertEquals(0f, commonsLatLngTest.accuracy)
}
fun testCalculateDistance() {
val lat1 = 37.7749
val lon1 = -122.4194
val lat2 = 34.0522
val lon2 = -118.2437
/**
* Commons LatLng to MapBox LatLng test.
*/
@Test
fun testCommonsLatLngToMapBoxLatLng() {
val geoLatLngTest = LocationUtils.commonsLatLngToMapBoxLatLng(LatLng(0.0, 0.0, 0f))
assertEquals(0.0, geoLatLngTest.latitude)
assertEquals(0.0, geoLatLngTest.longitude)
assertEquals(0.0, geoLatLngTest.altitude)
val expectedDistance = 559.02 // Expected distance in kilometers
val actualDistance = LocationUtils.calculateDistance(lat1, lon1, lat2, lon2)
assertEquals(expectedDistance, actualDistance, 0.2) // Tolerance = 0.2 km
}
}