From a45ab9cf161866e7bc11f964e7b7cd679dfab3fc Mon Sep 17 00:00:00 2001 From: bugfixer4646 <62693668+aahlad2000@users.noreply.github.com> Date: Mon, 25 Mar 2024 07:05:30 +0530 Subject: [PATCH] Refactor curlatLng to currentLatLng (#5646) Co-authored-by: Aahlad --- .../fr/free/nrw/commons/MapController.java | 4 +- .../contributions/ContributionsFragment.java | 10 ++-- .../commons/explore/map/ExploreMapCalls.java | 6 +- .../explore/map/ExploreMapContract.java | 4 +- .../explore/map/ExploreMapController.java | 16 ++--- .../explore/map/ExploreMapFragment.java | 20 +++---- .../explore/map/ExploreMapPresenter.java | 10 ++-- .../nrw/commons/nearby/NearbyController.java | 40 ++++++------- .../free/nrw/commons/nearby/NearbyPlaces.java | 6 +- .../NearbyParentFragmentContract.java | 8 +-- .../fragments/NearbyParentFragment.java | 60 +++++++++---------- .../NearbyParentFragmentPresenter.java | 12 ++-- .../commons/nearby/NearbyControllerTest.kt | 6 +- .../NearbyParentFragmentPresenterTest.kt | 2 +- 14 files changed, 102 insertions(+), 102 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/MapController.java b/app/src/main/java/fr/free/nrw/commons/MapController.java index 0cf66ad8f..72005fe83 100644 --- a/app/src/main/java/fr/free/nrw/commons/MapController.java +++ b/app/src/main/java/fr/free/nrw/commons/MapController.java @@ -12,7 +12,7 @@ public abstract class MapController { public class NearbyPlacesInfo { public List placeList; // List of nearby places public LatLng[] boundaryCoordinates; // Corners of nearby area - public LatLng curLatLng; // Current location when this places are populated + public LatLng currentLatLng; // Current location when this places are populated public LatLng searchLatLng; // Search location for finding this places public List mediaList; // Search location for finding this places } @@ -23,7 +23,7 @@ public abstract class MapController { public class ExplorePlacesInfo { public List explorePlaceList; // List of nearby places public LatLng[] boundaryCoordinates; // Corners of nearby area - public LatLng curLatLng; // Current location when this places are populated + public LatLng currentLatLng; // Current location when this places are populated public LatLng searchLatLng; // Search location for finding this places public List mediaList; // Search location for finding this places } diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java index 3ac5c8197..9186b62fc 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java @@ -121,7 +121,7 @@ public class ContributionsFragment @Inject SessionManager sessionManager; - private LatLng curLatLng; + private LatLng currentLatLng; private boolean isFragmentAttachedBefore = false; private View checkBoxView; @@ -542,9 +542,9 @@ public class ContributionsFragment private void updateClosestNearbyCardViewInfo() { - curLatLng = locationManager.getLastLocation(); + currentLatLng = locationManager.getLastLocation(); compositeDisposable.add(Observable.fromCallable(() -> nearbyController - .loadAttractionsFromLocation(curLatLng, curLatLng, true, + .loadAttractionsFromLocation(currentLatLng, currentLatLng, true, false)) // thanks to boolean, it will only return closest result .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -571,9 +571,9 @@ public class ContributionsFragment if (closestNearbyPlace == null) { binding.cardViewNearby.setVisibility(View.GONE); } else { - String distance = formatDistanceBetween(curLatLng, closestNearbyPlace.location); + String distance = formatDistanceBetween(currentLatLng, closestNearbyPlace.location); closestNearbyPlace.setDistance(distance); - direction = (float) computeBearing(curLatLng, closestNearbyPlace.location); + direction = (float) computeBearing(currentLatLng, closestNearbyPlace.location); binding.cardViewNearby.updateContent(closestNearbyPlace); } } else { diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapCalls.java b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapCalls.java index 0d8b1de57..ec426942c 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapCalls.java +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapCalls.java @@ -20,11 +20,11 @@ public class ExploreMapCalls { /** * Calls method to query Commons for uploads around a location * - * @param curLatLng coordinates of search location + * @param currentLatLng coordinates of search location * @return list of places obtained */ - List callCommonsQuery(final LatLng curLatLng) { - String coordinates = curLatLng.getLatitude() + "|" + curLatLng.getLongitude(); + List callCommonsQuery(final LatLng currentLatLng) { + String coordinates = currentLatLng.getLatitude() + "|" + currentLatLng.getLongitude(); return mediaClient.getMediaListFromGeoSearch(coordinates).blockingGet(); } diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapContract.java b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapContract.java index 791652475..935c1ed5b 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapContract.java +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapContract.java @@ -11,9 +11,9 @@ public class ExploreMapContract { interface View { boolean isNetworkConnectionEstablished(); - void populatePlaces(LatLng curlatLng); + void populatePlaces(LatLng currentLatLng); void checkPermissionsAndPerformAction(); - void recenterMap(LatLng curLatLng); + void recenterMap(LatLng currentLatLng); void showLocationOffDialog(); void openLocationSettings(); void hideBottomDetailsSheet(); diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.java b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.java index def735e86..99c755814 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.java +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.java @@ -45,17 +45,17 @@ public class ExploreMapController extends MapController { } /** - * Takes location as parameter and returns ExplorePlaces info that holds curLatLng, mediaList, + * Takes location as parameter and returns ExplorePlaces info that holds currentLatLng, mediaList, * explorePlaceList and boundaryCoordinates * - * @param curLatLng is current geolocation + * @param currentLatLng is current geolocation * @param searchLatLng is the location that we want to search around * @param checkingAroundCurrentLocation is a boolean flag. True if we want to check around * current location, false if another location - * @return explorePlacesInfo info that holds curLatLng, mediaList, explorePlaceList and + * @return explorePlacesInfo info that holds currentLatLng, mediaList, explorePlaceList and * boundaryCoordinates */ - public ExplorePlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng searchLatLng, + public ExplorePlacesInfo loadAttractionsFromLocation(LatLng currentLatLng, LatLng searchLatLng, boolean checkingAroundCurrentLocation) { if (searchLatLng == null) { @@ -65,7 +65,7 @@ public class ExploreMapController extends MapController { ExplorePlacesInfo explorePlacesInfo = new ExplorePlacesInfo(); try { - explorePlacesInfo.curLatLng = curLatLng; + explorePlacesInfo.currentLatLng = currentLatLng; latestSearchLocation = searchLatLng; List mediaList = exploreMapCalls.callCommonsQuery(searchLatLng); @@ -115,7 +115,7 @@ public class ExploreMapController extends MapController { // Our radius searched around us, will be used to understand when user search their own location, we will follow them if (checkingAroundCurrentLocation) { currentLocationSearchRadius = latestSearchRadius; - currentLocation = curLatLng; + currentLocation = currentLatLng; } } catch (Exception e) { e.printStackTrace(); @@ -129,7 +129,7 @@ public class ExploreMapController extends MapController { * @return baseMarkerOptions list that holds nearby places with their icons */ public static List loadAttractionsFromLocationToBaseMarkerOptions( - LatLng curLatLng, + LatLng currentLatLng, final List placeList, Context context, NearbyBaseMarkerThumbCallback callback, @@ -151,7 +151,7 @@ public class ExploreMapController extends MapController { if (vectorDrawable != null) { for (Place explorePlace : placeList) { final BaseMarker baseMarker = new BaseMarker(); - String distance = formatDistanceBetween(curLatLng, explorePlace.location); + String distance = formatDistanceBetween(currentLatLng, explorePlace.location); explorePlace.setDistance(distance); baseMarker.setTitle( diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java index 17baca795..b4c2c32d6 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java @@ -391,18 +391,18 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment } @Override - public void populatePlaces(LatLng curLatLng) { + public void populatePlaces(LatLng currentLatLng) { final Observable nearbyPlacesInfoObservable; - if (curLatLng == null) { + if (currentLatLng == null) { checkPermissionsAndPerformAction(); return; } - if (curLatLng.equals(getLastMapFocus())) { // Means we are checking around current location - nearbyPlacesInfoObservable = presenter.loadAttractionsFromLocation(curLatLng, + if (currentLatLng.equals(getLastMapFocus())) { // Means we are checking around current location + nearbyPlacesInfoObservable = presenter.loadAttractionsFromLocation(currentLatLng, getLastMapFocus(), true); } else { nearbyPlacesInfoObservable = presenter.loadAttractionsFromLocation(getLastMapFocus(), - curLatLng, false); + currentLatLng, false); } compositeDisposable.add(nearbyPlacesInfoObservable .subscribeOn(Schedulers.io()) @@ -413,7 +413,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment showResponseMessage(getString(R.string.no_pictures_in_this_area)); } updateMapMarkers(explorePlacesInfo); - lastMapFocus = new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude()); + lastMapFocus = new GeoPoint(currentLatLng.getLatitude(), currentLatLng.getLongitude()); }, throwable -> { Timber.d(throwable); @@ -479,8 +479,8 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment } @Override - public void recenterMap(LatLng curLatLng) { - if (isPermissionDenied || curLatLng == null) { + public void recenterMap(LatLng currentLatLng) { + if (isPermissionDenied || currentLatLng == null) { recenterToUserLocation = true; checkPermissionsAndPerformAction(); if (!isPermissionDenied && !(locationManager.isNetworkProviderEnabled() @@ -489,9 +489,9 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment } return; } - recenterMarkerToPosition(new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude())); + recenterMarkerToPosition(new GeoPoint(currentLatLng.getLatitude(), currentLatLng.getLongitude())); binding.mapView.getController() - .animateTo(new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude())); + .animateTo(new GeoPoint(currentLatLng.getLatitude(), currentLatLng.getLongitude())); if (lastMapFocus != null) { Location mylocation = new Location(""); Location dest_location = new Location(""); diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapPresenter.java b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapPresenter.java index 303adc409..c07aae24c 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapPresenter.java +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapPresenter.java @@ -25,7 +25,7 @@ public class ExploreMapPresenter BookmarkLocationsDao bookmarkLocationDao; private boolean isNearbyLocked; - private LatLng curLatLng; + private LatLng currentLatLng; private ExploreMapController exploreMapController; private static final ExploreMapContract.View DUMMY = (ExploreMapContract.View) Proxy @@ -119,7 +119,7 @@ public class ExploreMapPresenter @Override public void setActionListeners(JsonKvStore applicationKvStore) { exploreMapFragmentView.setFABRecenterAction(v -> { - exploreMapFragmentView.recenterMap(curLatLng); + exploreMapFragmentView.recenterMap(currentLatLng); }); } @@ -144,11 +144,11 @@ public class ExploreMapPresenter exploreMapFragmentView.addSearchThisAreaButtonAction(); } - public Observable loadAttractionsFromLocation(LatLng curLatLng, + public Observable loadAttractionsFromLocation(LatLng currentLatLng, LatLng searchLatLng, boolean checkingAroundCurrent) { return Observable .fromCallable(() -> exploreMapController - .loadAttractionsFromLocation(curLatLng, searchLatLng, checkingAroundCurrent)); + .loadAttractionsFromLocation(currentLatLng, searchLatLng, checkingAroundCurrent)); } /** @@ -169,7 +169,7 @@ public class ExploreMapPresenter void prepareNearbyBaseMarkers(MapController.ExplorePlacesInfo explorePlacesInfo) { exploreMapController - .loadAttractionsFromLocationToBaseMarkerOptions(explorePlacesInfo.curLatLng, + .loadAttractionsFromLocationToBaseMarkerOptions(explorePlacesInfo.currentLatLng, // Curlatlang will be used to calculate distances explorePlacesInfo.explorePlaceList, exploreMapFragmentView.getContext(), diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java index 37717e1a4..12bc641b8 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java @@ -39,14 +39,14 @@ public class NearbyController extends MapController { /** * Prepares Place list to make their distance information update later. * - * @param curLatLng current location for user + * @param currentLatLng current location for user * @param searchLatLng the location user wants to search around * @param returnClosestResult if this search is done to find closest result or all results * @param customQuery if this search is done via an advanced query * @return NearbyPlacesInfo a variable holds Place list without distance information and * boundary coordinates of current Place List */ - public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng curLatLng, + public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng currentLatLng, final LatLng searchLatLng, final boolean returnClosestResult, final boolean checkingAroundCurrentLocation, @Nullable final String customQuery) throws Exception { @@ -54,7 +54,7 @@ public class NearbyController extends MapController { Timber.d("Loading attractions near %s", searchLatLng); NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo(); if (searchLatLng == null) { - Timber.d("Loading attractions nearby, but curLatLng is null"); + Timber.d("Loading attractions nearby, but currentLatLng is null"); return null; } List places = nearbyPlaces @@ -68,11 +68,11 @@ public class NearbyController extends MapController { places.get(0).location, // west places.get(0).location};// east, init with a random location - if (curLatLng != null) { + if (currentLatLng != null) { Timber.d("Sorting places by distance..."); final Map distances = new HashMap<>(); for (Place place : places) { - distances.put(place, computeDistanceBetween(place.location, curLatLng)); + distances.put(place, computeDistanceBetween(place.location, currentLatLng)); // Find boundaries with basic find max approach if (place.location.getLatitude() < boundaryCoordinates[0].getLatitude()) { boundaryCoordinates[0] = place.location; @@ -95,7 +95,7 @@ public class NearbyController extends MapController { } ); } - nearbyPlacesInfo.curLatLng = curLatLng; + nearbyPlacesInfo.currentLatLng = currentLatLng; nearbyPlacesInfo.searchLatLng = searchLatLng; nearbyPlacesInfo.placeList = places; nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates; @@ -109,7 +109,7 @@ public class NearbyController extends MapController { // Our radius searched around us, will be used to understand when user search their own location, we will follow them if (checkingAroundCurrentLocation) { currentLocationSearchRadius = nearbyPlaces.radius * 1000; // to meter - currentLocation = curLatLng; + currentLocation = currentLatLng; } } @@ -121,7 +121,7 @@ public class NearbyController extends MapController { /** * Prepares Place list to make their distance information update later. * - * @param curLatLng The current latitude and longitude. + * @param currentLatLng The current latitude and longitude. * @param screenTopRight The top right corner of the screen (latitude, * longitude). * @param screenBottomLeft The bottom left corner of the screen (latitude, @@ -137,7 +137,7 @@ public class NearbyController extends MapController { * @return An object containing information about nearby places. * @throws Exception If an error occurs during the retrieval process. */ - public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng curLatLng, + public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng currentLatLng, final fr.free.nrw.commons.location.LatLng screenTopRight, final fr.free.nrw.commons.location.LatLng screenBottomLeft, final LatLng searchLatLng, final boolean returnClosestResult, final boolean checkingAroundCurrentLocation, @@ -148,7 +148,7 @@ public class NearbyController extends MapController { NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo(); if (searchLatLng == null) { - Timber.d("Loading attractions nearby, but curLatLng is null"); + Timber.d("Loading attractions nearby, but currentLatLng is null"); return null; } @@ -162,11 +162,11 @@ public class NearbyController extends MapController { places.get(0).location, // west places.get(0).location};// east, init with a random location - if (curLatLng != null) { + if (currentLatLng != null) { Timber.d("Sorting places by distance..."); final Map distances = new HashMap<>(); for (Place place : places) { - distances.put(place, computeDistanceBetween(place.location, curLatLng)); + distances.put(place, computeDistanceBetween(place.location, currentLatLng)); // Find boundaries with basic find max approach if (place.location.getLatitude() < boundaryCoordinates[0].getLatitude()) { boundaryCoordinates[0] = place.location; @@ -189,7 +189,7 @@ public class NearbyController extends MapController { } ); } - nearbyPlacesInfo.curLatLng = curLatLng; + nearbyPlacesInfo.currentLatLng = currentLatLng; nearbyPlacesInfo.searchLatLng = searchLatLng; nearbyPlacesInfo.placeList = places; nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates; @@ -203,7 +203,7 @@ public class NearbyController extends MapController { // Our radius searched around us, will be used to understand when user search their own location, we will follow them if (checkingAroundCurrentLocation) { currentLocationSearchRadius = nearbyPlaces.radius * 1000; // to meter - currentLocation = curLatLng; + currentLocation = currentLatLng; } } } @@ -213,29 +213,29 @@ public class NearbyController extends MapController { /** * Prepares Place list to make their distance information update later. * - * @param curLatLng current location for user + * @param currentLatLng current location for user * @param searchLatLng the location user wants to search around * @param returnClosestResult if this search is done to find closest result or all results * @return NearbyPlacesInfo a variable holds Place list without distance information and * boundary coordinates of current Place List */ - public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng curLatLng, + public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng currentLatLng, final LatLng searchLatLng, final boolean returnClosestResult, final boolean checkingAroundCurrentLocation) throws Exception { - return loadAttractionsFromLocation(curLatLng, searchLatLng, returnClosestResult, + return loadAttractionsFromLocation(currentLatLng, searchLatLng, returnClosestResult, checkingAroundCurrentLocation, null); } /** * Loads attractions from location for map view, we need to return BaseMarkerOption data type. * - * @param curLatLng users current location + * @param currentLatLng users current location * @param placeList list of nearby places in Place data type * @return BaseMarkerOptions list that holds nearby places */ public static List loadAttractionsFromLocationToBaseMarkerOptions( - LatLng curLatLng, + LatLng currentLatLng, List placeList) { List baseMarkersList = new ArrayList<>(); @@ -245,7 +245,7 @@ public class NearbyController extends MapController { placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS)); for (Place place : placeList) { BaseMarker baseMarker = new BaseMarker(); - String distance = formatDistanceBetween(curLatLng, place.location); + String distance = formatDistanceBetween(currentLatLng, place.location); place.setDistance(distance); baseMarker.setTitle(place.name); baseMarker.setPosition( diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java index 7fb69277a..07b7f53fd 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java @@ -38,13 +38,13 @@ public class NearbyPlaces { /** * Expands the radius as needed for the Wikidata query * - * @param curLatLng coordinates of search location + * @param currentLatLng coordinates of search location * @param lang user's language * @param returnClosestResult true if only the nearest point is desired * @param customQuery * @return list of places obtained */ - List radiusExpander(final LatLng curLatLng, final String lang, + List radiusExpander(final LatLng currentLatLng, final String lang, final boolean returnClosestResult, @Nullable final String customQuery) throws Exception { final int minResults; @@ -66,7 +66,7 @@ public class NearbyPlaces { // Increase the radius gradually to find a satisfactory number of nearby places while (radius <= maxRadius) { - places = getFromWikidataQuery(curLatLng, lang, radius, customQuery); + places = getFromWikidataQuery(currentLatLng, lang, radius, customQuery); Timber.d("%d results at radius: %f", places.size(), radius); if (places.size() >= minResults) { break; diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java b/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java index 1b973f326..8763926bc 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java @@ -18,9 +18,9 @@ public interface NearbyParentFragmentContract { void listOptionMenuItemClicked(); - void populatePlaces(LatLng curlatLng); + void populatePlaces(LatLng currentLatLng); - void populatePlaces(LatLng curlatLng, String customQuery); + void populatePlaces(LatLng currentLatLng, String customQuery); boolean isListBottomSheetExpanded(); @@ -34,7 +34,7 @@ public interface NearbyParentFragmentContract { void animateFABs(); - void recenterMap(LatLng curLatLng); + void recenterMap(LatLng currentLatLng); void showLocationOffDialog(); @@ -68,7 +68,7 @@ public interface NearbyParentFragmentContract { void enableFABRecenter(); - void addCurrentLocationMarker(LatLng curLatLng); + void addCurrentLocationMarker(LatLng currentLatLng); void clearAllMarkers(); diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index 7195e14cf..f84334db5 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -1119,7 +1119,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } @Override - public void populatePlaces(final fr.free.nrw.commons.location.LatLng curlatLng) { + public void populatePlaces(final fr.free.nrw.commons.location.LatLng currentLatLng) { IGeoPoint screenTopRight = mapView.getProjection().fromPixels(mapView.getWidth(), 0); IGeoPoint screenBottomLeft = mapView.getProjection().fromPixels(0, mapView.getHeight()); fr.free.nrw.commons.location.LatLng screenTopRightLatLng = new fr.free.nrw.commons.location.LatLng( @@ -1139,30 +1139,30 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment && screenBottomLeftLatLng.getLatitude() == 0.0 && screenBottomLeftLatLng.getLongitude() == 0.0) { final double delta = 0.02; - final double westCornerLat = curlatLng.getLatitude() - delta; - final double westCornerLong = curlatLng.getLongitude() - delta; - final double eastCornerLat = curlatLng.getLatitude() + delta; - final double eastCornerLong = curlatLng.getLongitude() + delta; + final double westCornerLat = currentLatLng.getLatitude() - delta; + final double westCornerLong = currentLatLng.getLongitude() - delta; + final double eastCornerLat = currentLatLng.getLatitude() + delta; + final double eastCornerLong = currentLatLng.getLongitude() + delta; screenTopRightLatLng = new fr.free.nrw.commons.location.LatLng(westCornerLat, westCornerLong, 0); screenBottomLeftLatLng = new fr.free.nrw.commons.location.LatLng(eastCornerLat, eastCornerLong, 0); - if (curlatLng.equals( + if (currentLatLng.equals( getLastMapFocus())) { // Means we are checking around current location populatePlacesForCurrentLocation(getLastMapFocus(), screenTopRightLatLng, - screenBottomLeftLatLng, curlatLng, null); + screenBottomLeftLatLng, currentLatLng, null); } else { populatePlacesForAnotherLocation(getLastMapFocus(), screenTopRightLatLng, - screenBottomLeftLatLng, curlatLng, null); + screenBottomLeftLatLng, currentLatLng, null); } } else { - if (curlatLng.equals( + if (currentLatLng.equals( getLastMapFocus())) { // Means we are checking around current location populatePlacesForCurrentLocation(getLastMapFocus(), screenTopRightLatLng, - screenBottomLeftLatLng, curlatLng, null); + screenBottomLeftLatLng, currentLatLng, null); } else { populatePlacesForAnotherLocation(getLastMapFocus(), screenTopRightLatLng, - screenBottomLeftLatLng, curlatLng, null); + screenBottomLeftLatLng, currentLatLng, null); } } @@ -1172,10 +1172,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } @Override - public void populatePlaces(final fr.free.nrw.commons.location.LatLng curlatLng, + public void populatePlaces(final fr.free.nrw.commons.location.LatLng currentLatLng, @Nullable final String customQuery) { if (customQuery == null || customQuery.isEmpty()) { - populatePlaces(curlatLng); + populatePlaces(currentLatLng); return; } IGeoPoint screenTopRight = mapView.getProjection().fromPixels(mapView.getWidth(), 0); @@ -1185,13 +1185,13 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment fr.free.nrw.commons.location.LatLng screenBottomLeftLatLng = new fr.free.nrw.commons.location.LatLng( screenTopRight.getLatitude(), screenTopRight.getLongitude(), 0); - if (curlatLng.equals(lastFocusLocation) || lastFocusLocation == null + if (currentLatLng.equals(lastFocusLocation) || lastFocusLocation == null || recenterToUserLocation) { // Means we are checking around current location populatePlacesForCurrentLocation(lastKnownLocation, screenTopRightLatLng, - screenBottomLeftLatLng, curlatLng, customQuery); + screenBottomLeftLatLng, currentLatLng, customQuery); } else { populatePlacesForAnotherLocation(lastKnownLocation, screenTopRightLatLng, - screenBottomLeftLatLng, curlatLng, customQuery); + screenBottomLeftLatLng, currentLatLng, customQuery); } if (recenterToUserLocation) { recenterToUserLocation = false; @@ -1199,14 +1199,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } private void populatePlacesForCurrentLocation( - final fr.free.nrw.commons.location.LatLng curlatLng, + final fr.free.nrw.commons.location.LatLng currentLatLng, final fr.free.nrw.commons.location.LatLng screenTopRight, final fr.free.nrw.commons.location.LatLng screenBottomLeft, final fr.free.nrw.commons.location.LatLng searchLatLng, @Nullable final String customQuery) { final Observable nearbyPlacesInfoObservable = Observable .fromCallable(() -> nearbyController - .loadAttractionsFromLocation(curlatLng, screenTopRight, screenBottomLeft, + .loadAttractionsFromLocation(currentLatLng, screenTopRight, screenBottomLeft, searchLatLng, false, true, Utils.isMonumentsEnabled(new Date()), customQuery)); @@ -1234,14 +1234,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } private void populatePlacesForAnotherLocation( - final fr.free.nrw.commons.location.LatLng curlatLng, + final fr.free.nrw.commons.location.LatLng currentLatLng, final fr.free.nrw.commons.location.LatLng screenTopRight, final fr.free.nrw.commons.location.LatLng screenBottomLeft, final fr.free.nrw.commons.location.LatLng searchLatLng, @Nullable final String customQuery) { final Observable nearbyPlacesInfoObservable = Observable .fromCallable(() -> nearbyController - .loadAttractionsFromLocation(curlatLng, screenTopRight, screenBottomLeft, + .loadAttractionsFromLocation(currentLatLng, screenTopRight, screenBottomLeft, searchLatLng, false, true, Utils.isMonumentsEnabled(new Date()), customQuery)); @@ -1502,15 +1502,15 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment * Should be called only on creation of Map, there is other method to update markers * location with users move. * - * @param curLatLng current location + * @param currentLatLng current location */ @Override - public void addCurrentLocationMarker(final fr.free.nrw.commons.location.LatLng curLatLng) { - if (null != curLatLng && !isPermissionDenied && locationManager.isGPSProviderEnabled()) { + public void addCurrentLocationMarker(final fr.free.nrw.commons.location.LatLng currentLatLng) { + if (null != currentLatLng && !isPermissionDenied && locationManager.isGPSProviderEnabled()) { ExecutorUtils.get().submit(() -> { Timber.d("Adds current location marker"); recenterMarkerToPosition( - new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude())); + new GeoPoint(currentLatLng.getLatitude(), currentLatLng.getLongitude())); }); } else { Timber.d("not adding current location marker..current location is null"); @@ -1612,10 +1612,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment * * @param isBookmarked true if place is bookmarked * @param place - * @param curLatLng current location + * @param currentLatLng current location */ public void updateMarker(final boolean isBookmarked, final Place place, - @Nullable final fr.free.nrw.commons.location.LatLng curLatLng) { + @Nullable final fr.free.nrw.commons.location.LatLng currentLatLng) { addMarkerToMap(place, isBookmarked); } @@ -1765,8 +1765,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } @Override - public void recenterMap(fr.free.nrw.commons.location.LatLng curLatLng) { - if (isPermissionDenied || curLatLng == null) { + public void recenterMap(fr.free.nrw.commons.location.LatLng currentLatLng) { + if (isPermissionDenied || currentLatLng == null) { recenterToUserLocation = true; checkPermissionsAndPerformAction(); if (!isPermissionDenied && !(locationManager.isNetworkProviderEnabled() @@ -1775,9 +1775,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } return; } - addCurrentLocationMarker(curLatLng); + addCurrentLocationMarker(currentLatLng); mapView.getController() - .animateTo(new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude())); + .animateTo(new GeoPoint(currentLatLng.getLatitude(), currentLatLng.getLongitude())); if (lastMapFocus != null) { Location mylocation = new Location(""); Location dest_location = new Location(""); 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 d0b4f400a..06608d6b9 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 @@ -38,7 +38,7 @@ public class NearbyParentFragmentPresenter LocationUpdateListener { private boolean isNearbyLocked; - private LatLng curLatLng; + private LatLng currentLatLng; private boolean placesLoadedOnce; @@ -111,7 +111,7 @@ public class NearbyParentFragmentPresenter }); nearbyParentFragmentView.setFABRecenterAction(v -> { - nearbyParentFragmentView.recenterMap(curLatLng); + nearbyParentFragmentView.recenterMap(currentLatLng); }); } @@ -172,11 +172,11 @@ public class NearbyParentFragmentPresenter LatLng lastLocation = nearbyParentFragmentView.getLastMapFocus(); if (nearbyParentFragmentView.getMapCenter() != null) { - curLatLng = nearbyParentFragmentView.getMapCenter(); + currentLatLng = nearbyParentFragmentView.getMapCenter(); } else { - curLatLng = lastLocation; + currentLatLng = lastLocation; } - if (curLatLng == null) { + if (currentLatLng == null) { Timber.d("Skipping update of nearby places as location is unavailable"); return; } @@ -220,7 +220,7 @@ public class NearbyParentFragmentPresenter if (null != nearbyParentFragmentView) { nearbyParentFragmentView.clearAllMarkers(); List baseMarkers = NearbyController - .loadAttractionsFromLocationToBaseMarkerOptions(nearbyPlacesInfo.curLatLng, + .loadAttractionsFromLocationToBaseMarkerOptions(nearbyPlacesInfo.currentLatLng, // Curlatlang will be used to calculate distances nearbyPlacesInfo.placeList); nearbyParentFragmentView.updateMapMarkers(baseMarkers); diff --git a/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyControllerTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyControllerTest.kt index 253c094b0..3ece391a5 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyControllerTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyControllerTest.kt @@ -168,7 +168,7 @@ class NearbyControllerTest { false, customQuery ) - assertEquals(result.curLatLng, currentLatLng) + assertEquals(result.currentLatLng, currentLatLng) assertEquals(result.searchLatLng, searchLatLong) } @@ -209,7 +209,7 @@ class NearbyControllerTest { true, customQuery ) - assertEquals(result.curLatLng, currentLatLng) + assertEquals(result.currentLatLng, currentLatLng) assertEquals(result.searchLatLng, searchLatLong) } @@ -250,7 +250,7 @@ class NearbyControllerTest { true, customQuery ) - assertEquals(result.curLatLng, currentLatLng) + assertEquals(result.currentLatLng, currentLatLng) assertEquals(result.searchLatLng, searchLatLong) } diff --git a/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt index c3e719e95..e4bc42d88 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt @@ -478,7 +478,7 @@ class NearbyParentFragmentPresenterTest { whenever(latestLocation.accuracy).thenReturn(0.0F) var nearbyPlacesInfo = NearbyController(nearbyPlaces).NearbyPlacesInfo() nearbyPlacesInfo.boundaryCoordinates = arrayOf() - nearbyPlacesInfo.curLatLng = latestLocation + nearbyPlacesInfo.currentLatLng = latestLocation nearbyPlacesInfo.searchLatLng = latestLocation nearbyPlacesInfo.placeList = null