1111import fr .free .nrw .commons .location .LocationServiceManager ;
1212import fr .free .nrw .commons .location .LocationUpdateListener ;
1313import fr .free .nrw .commons .nearby .NearbyController ;
14+ import fr .free .nrw .commons .nearby .Place ;
1415import fr .free .nrw .commons .nearby .mvp .contract .NearbyMapContract ;
1516import fr .free .nrw .commons .nearby .mvp .contract .NearbyParentFragmentContract ;
1617import fr .free .nrw .commons .utils .LocationUtils ;
@@ -43,6 +44,11 @@ public class NearbyParentFragmentPresenter
4344 boolean nearbyOperationsInitialized ;
4445 boolean mapInitialized ; // TODO reset this on fragment destroyed
4546
47+ Place placeToCenter ;
48+ boolean isPortraitMode ;
49+ boolean willMapBeCentered ;
50+ boolean placesLoadedOnce ;
51+
4652
4753 private LocationServiceManager locationServiceManager ;
4854
@@ -282,7 +288,7 @@ public void updateMapAndList(LocationServiceManager.LocationChangeType locationC
282288 /**
283289 * Populates places for custom location, should be used for finding nearby places around a
284290 * location where you are not at.
285- * @param nearbyPlacesInfo This variable has place list information and distances.
291+ * @param nearbyPlacesInfo This variable has placeToCenter list information and distances.
286292 */
287293 public void updateMapMarkers (NearbyController .NearbyPlacesInfo nearbyPlacesInfo , Marker selectedMarker ) {
288294 nearbyMapFragmentView .updateMapMarkers (nearbyPlacesInfo .curLatLng , nearbyPlacesInfo .placeList , selectedMarker , this );
@@ -291,20 +297,28 @@ public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo,
291297 lockUnlockNearby (false ); // So that new location updates wont come
292298 nearbyParentFragmentView .setProgressBarVisibility (false );
293299 nearbyListFragmentView .updateListFragment (nearbyPlacesInfo .placeList );
300+ handleCenteringTaskIfAny ();
294301 }
295302
296303 /**
297304 * Populates places for custom location, should be used for finding nearby places around a
298305 * location where you are not at.
299- * @param nearbyPlacesInfo This variable has place list information and distances.
306+ * @param nearbyPlacesInfo This variable has placeToCenter list information and distances.
300307 */
301308 public void updateMapMarkersForCustomLocation (NearbyController .NearbyPlacesInfo nearbyPlacesInfo , Marker selectedMarker ) {
302309 nearbyMapFragmentView .updateMapMarkers (nearbyPlacesInfo .curLatLng , nearbyPlacesInfo .placeList , selectedMarker , this );
303310 nearbyMapFragmentView .addCurrentLocationMarker (nearbyPlacesInfo .curLatLng );
304311 lockUnlockNearby (false ); // So that new location updates wont come
305312 nearbyParentFragmentView .setProgressBarVisibility (false );
306313 nearbyListFragmentView .updateListFragment (nearbyPlacesInfo .placeList );
314+ handleCenteringTaskIfAny ();
315+ }
307316
317+ private void handleCenteringTaskIfAny () {
318+ if (!placesLoadedOnce ) {
319+ placesLoadedOnce = true ;
320+ nearbyMapFragmentView .centerMapToPlace (placeToCenter , isPortraitMode );
321+ }
308322 }
309323
310324 @ Override
@@ -395,4 +409,18 @@ public boolean searchCloseToCurrentLocation() {
395409 return true ;
396410 }
397411 }
412+
413+ /**
414+ * Centers the map in nearby fragment to a given placeToCenter
415+ * @param place is new center of the map
416+ */
417+ public void centerMapToPlace (Place place , boolean isPortraitMode ) {
418+ if (placesLoadedOnce ) {
419+ nearbyMapFragmentView .centerMapToPlace (place , isPortraitMode );
420+ } else {
421+ willMapBeCentered = true ;
422+ this .isPortraitMode = isPortraitMode ;
423+ this .placeToCenter = place ;
424+ }
425+ }
398426}
0 commit comments