11
11
import fr .free .nrw .commons .location .LocationServiceManager ;
12
12
import fr .free .nrw .commons .location .LocationUpdateListener ;
13
13
import fr .free .nrw .commons .nearby .NearbyController ;
14
+ import fr .free .nrw .commons .nearby .Place ;
14
15
import fr .free .nrw .commons .nearby .mvp .contract .NearbyMapContract ;
15
16
import fr .free .nrw .commons .nearby .mvp .contract .NearbyParentFragmentContract ;
16
17
import fr .free .nrw .commons .utils .LocationUtils ;
@@ -43,6 +44,11 @@ public class NearbyParentFragmentPresenter
43
44
boolean nearbyOperationsInitialized ;
44
45
boolean mapInitialized ; // TODO reset this on fragment destroyed
45
46
47
+ Place placeToCenter ;
48
+ boolean isPortraitMode ;
49
+ boolean willMapBeCentered ;
50
+ boolean placesLoadedOnce ;
51
+
46
52
47
53
private LocationServiceManager locationServiceManager ;
48
54
@@ -282,7 +288,7 @@ public void updateMapAndList(LocationServiceManager.LocationChangeType locationC
282
288
/**
283
289
* Populates places for custom location, should be used for finding nearby places around a
284
290
* 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.
286
292
*/
287
293
public void updateMapMarkers (NearbyController .NearbyPlacesInfo nearbyPlacesInfo , Marker selectedMarker ) {
288
294
nearbyMapFragmentView .updateMapMarkers (nearbyPlacesInfo .curLatLng , nearbyPlacesInfo .placeList , selectedMarker , this );
@@ -291,20 +297,28 @@ public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo,
291
297
lockUnlockNearby (false ); // So that new location updates wont come
292
298
nearbyParentFragmentView .setProgressBarVisibility (false );
293
299
nearbyListFragmentView .updateListFragment (nearbyPlacesInfo .placeList );
300
+ handleCenteringTaskIfAny ();
294
301
}
295
302
296
303
/**
297
304
* Populates places for custom location, should be used for finding nearby places around a
298
305
* 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.
300
307
*/
301
308
public void updateMapMarkersForCustomLocation (NearbyController .NearbyPlacesInfo nearbyPlacesInfo , Marker selectedMarker ) {
302
309
nearbyMapFragmentView .updateMapMarkers (nearbyPlacesInfo .curLatLng , nearbyPlacesInfo .placeList , selectedMarker , this );
303
310
nearbyMapFragmentView .addCurrentLocationMarker (nearbyPlacesInfo .curLatLng );
304
311
lockUnlockNearby (false ); // So that new location updates wont come
305
312
nearbyParentFragmentView .setProgressBarVisibility (false );
306
313
nearbyListFragmentView .updateListFragment (nearbyPlacesInfo .placeList );
314
+ handleCenteringTaskIfAny ();
315
+ }
307
316
317
+ private void handleCenteringTaskIfAny () {
318
+ if (!placesLoadedOnce ) {
319
+ placesLoadedOnce = true ;
320
+ nearbyMapFragmentView .centerMapToPlace (placeToCenter , isPortraitMode );
321
+ }
308
322
}
309
323
310
324
@ Override
@@ -395,4 +409,18 @@ public boolean searchCloseToCurrentLocation() {
395
409
return true ;
396
410
}
397
411
}
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
+ }
398
426
}
0 commit comments