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 feebd20c6..194ed5d24 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 @@ -120,6 +120,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment private double prevZoom; private double prevLatitude; private double prevLongitude; + private boolean recentlyCameFromNearbyMap; private ExploreMapPresenter presenter; @@ -371,6 +372,16 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment prevLatitude = getArguments().getDouble("prev_latitude"); prevLongitude = getArguments().getDouble("prev_longitude"); } + + setRecentlyCameFromNearbyMap(isCameFromNearbyMap()); + } + + /** + * @return The LatLng from the previous Fragment's map center or (0,0,0) coordinates + * if that information is not available/applicable. + */ + public LatLng getPreviousLatLng() { + return new LatLng(prevLatitude, prevLongitude, (float)prevZoom); } /** @@ -383,6 +394,23 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment return prevZoom != 0.0 || prevLatitude != 0.0 || prevLongitude != 0.0; } + /** + * Gets the value that indicates if the user navigated from "Show in Explore" in Nearby and + * that the LatLng from Nearby has yet to be searched for map markers. + */ + public boolean recentlyCameFromNearbyMap() { + return recentlyCameFromNearbyMap; + } + + /** + * Sets the value that indicates if the user navigated from "Show in Explore" in Nearby and + * that the LatLng from Nearby has yet to be searched for map markers. + * @param newValue The value to set. + */ + public void setRecentlyCameFromNearbyMap(boolean newValue) { + recentlyCameFromNearbyMap = newValue; + } + public void loadNearbyMapFromExplore() { ((MainActivity) getContext()).loadNearbyMapFromExplore( binding.mapView.getZoomLevelDouble(), 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 94b9cf5ad..45a11a422 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 @@ -74,9 +74,22 @@ public class ExploreMapPresenter */ if (locationChangeType.equals(LOCATION_SIGNIFICANTLY_CHANGED)) { Timber.d("LOCATION_SIGNIFICANTLY_CHANGED"); + LatLng populateLatLng = exploreMapFragmentView.getMapCenter(); + + //If "Show in Explore" was selected in Nearby, use the previous LatLng + if (exploreMapFragmentView instanceof ExploreMapFragment) { + ExploreMapFragment exploreMapFragment = (ExploreMapFragment)exploreMapFragmentView; + if (exploreMapFragment.recentlyCameFromNearbyMap()) { + //Ensure this LatLng will not be used again if user searches their GPS location + exploreMapFragment.setRecentlyCameFromNearbyMap(false); + + populateLatLng = exploreMapFragment.getPreviousLatLng(); + } + } + lockUnlockNearby(true); exploreMapFragmentView.setProgressBarVisibility(true); - exploreMapFragmentView.populatePlaces(exploreMapFragmentView.getMapCenter()); + exploreMapFragmentView.populatePlaces(populateLatLng); } else if (locationChangeType.equals(SEARCH_CUSTOM_AREA)) { Timber.d("SEARCH_CUSTOM_AREA"); lockUnlockNearby(true);