Skip to content

Commit eb617ae

Browse files
Fixes Issue 6308: Explore map shows image at my location rather than at shown location (commons-app#6315)
* ExploreMapFragment.java: add helper methods and fields to enable proper Explore map behavior Before this commit, there was no way to tell if the user had arrived from the Nearby and before the Nearby map center location had been searched for markers. This commit adds a boolean flag to indicate this situation. Access, modification, and initialization methods were added for this boolean value. Additionally, a helper method to retrieve the Nearby map center LatLng was added as a convienience. * ExploreMapPresenter.java: fix map update code to search for Nearby LatLng when appropriate Before this commit, when the user selected "Show in explore" in Nearby when no pins were on the map, Explore would only search for markers at the user's current GPS location, rather than those at the Nearby map center. After this commit, code was added to check if the user recently came from the Nearby map. If so, the stored coordinates of the Nearby map is searched rather than the user's current GPS coordinates. Additionally, the boolean that indicates that the user recently came from the Nearby map is set to false. This ensures that the stored Nearby map center coordinates are not used when the user taps the icon to focus the map on their current location. --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent b3c1474 commit eb617ae

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
120120
private double prevZoom;
121121
private double prevLatitude;
122122
private double prevLongitude;
123+
private boolean recentlyCameFromNearbyMap;
123124

124125
private ExploreMapPresenter presenter;
125126

@@ -371,6 +372,16 @@ public void loadNearbyMapData() {
371372
prevLatitude = getArguments().getDouble("prev_latitude");
372373
prevLongitude = getArguments().getDouble("prev_longitude");
373374
}
375+
376+
setRecentlyCameFromNearbyMap(isCameFromNearbyMap());
377+
}
378+
379+
/**
380+
* @return The LatLng from the previous Fragment's map center or (0,0,0) coordinates
381+
* if that information is not available/applicable.
382+
*/
383+
public LatLng getPreviousLatLng() {
384+
return new LatLng(prevLatitude, prevLongitude, (float)prevZoom);
374385
}
375386

376387
/**
@@ -383,6 +394,23 @@ public boolean isCameFromNearbyMap() {
383394
return prevZoom != 0.0 || prevLatitude != 0.0 || prevLongitude != 0.0;
384395
}
385396

397+
/**
398+
* Gets the value that indicates if the user navigated from "Show in Explore" in Nearby and
399+
* that the LatLng from Nearby has yet to be searched for map markers.
400+
*/
401+
public boolean recentlyCameFromNearbyMap() {
402+
return recentlyCameFromNearbyMap;
403+
}
404+
405+
/**
406+
* Sets the value that indicates if the user navigated from "Show in Explore" in Nearby and
407+
* that the LatLng from Nearby has yet to be searched for map markers.
408+
* @param newValue The value to set.
409+
*/
410+
public void setRecentlyCameFromNearbyMap(boolean newValue) {
411+
recentlyCameFromNearbyMap = newValue;
412+
}
413+
386414
public void loadNearbyMapFromExplore() {
387415
((MainActivity) getContext()).loadNearbyMapFromExplore(
388416
binding.mapView.getZoomLevelDouble(),

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapPresenter.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,22 @@ public void updateMap(LocationChangeType locationChangeType) {
7474
*/
7575
if (locationChangeType.equals(LOCATION_SIGNIFICANTLY_CHANGED)) {
7676
Timber.d("LOCATION_SIGNIFICANTLY_CHANGED");
77+
LatLng populateLatLng = exploreMapFragmentView.getMapCenter();
78+
79+
//If "Show in Explore" was selected in Nearby, use the previous LatLng
80+
if (exploreMapFragmentView instanceof ExploreMapFragment) {
81+
ExploreMapFragment exploreMapFragment = (ExploreMapFragment)exploreMapFragmentView;
82+
if (exploreMapFragment.recentlyCameFromNearbyMap()) {
83+
//Ensure this LatLng will not be used again if user searches their GPS location
84+
exploreMapFragment.setRecentlyCameFromNearbyMap(false);
85+
86+
populateLatLng = exploreMapFragment.getPreviousLatLng();
87+
}
88+
}
89+
7790
lockUnlockNearby(true);
7891
exploreMapFragmentView.setProgressBarVisibility(true);
79-
exploreMapFragmentView.populatePlaces(exploreMapFragmentView.getMapCenter());
92+
exploreMapFragmentView.populatePlaces(populateLatLng);
8093
} else if (locationChangeType.equals(SEARCH_CUSTOM_AREA)) {
8194
Timber.d("SEARCH_CUSTOM_AREA");
8295
lockUnlockNearby(true);

0 commit comments

Comments
 (0)