5555import fr .free .nrw .commons .R ;
5656import fr .free .nrw .commons .contributions .ContributionController ;
5757import fr .free .nrw .commons .utils .UriDeserializer ;
58+ import fr .free .nrw .commons .utils .ViewUtil ;
5859import timber .log .Timber ;
5960
6061import static android .app .Activity .RESULT_OK ;
@@ -105,7 +106,8 @@ public class NearbyMapFragment extends DaggerFragment {
105106 private PolygonOptions currentLocationPolygonOptions ;
106107
107108 private boolean isBottomListSheetExpanded ;
108- private final double CAMERA_TARGET_SHIFT_FACTOR = 0.06 ;
109+ private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.06 ;
110+ private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04 ;
109111
110112 @ Inject
111113 @ Named ("prefs" )
@@ -253,13 +255,24 @@ private void updateMapToTrackPosition() {
253255 }
254256
255257 // Make camera to follow user on location change
256- CameraPosition position = new CameraPosition .Builder ()
257- .target (isBottomListSheetExpanded ?
258- new LatLng (curMapBoxLatLng .getLatitude ()- CAMERA_TARGET_SHIFT_FACTOR ,
259- curMapBoxLatLng .getLongitude ())
260- : curMapBoxLatLng ) // Sets the new camera position
261- .zoom (mapboxMap .getCameraPosition ().zoom ) // Same zoom level
262- .build ();
258+ CameraPosition position ;
259+ if (ViewUtil .isPortrait (getActivity ())){
260+ position = new CameraPosition .Builder ()
261+ .target (isBottomListSheetExpanded ?
262+ new LatLng (curMapBoxLatLng .getLatitude ()- CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT ,
263+ curMapBoxLatLng .getLongitude ())
264+ : curMapBoxLatLng ) // Sets the new camera position
265+ .zoom (mapboxMap .getCameraPosition ().zoom ) // Same zoom level
266+ .build ();
267+ }else {
268+ position = new CameraPosition .Builder ()
269+ .target (isBottomListSheetExpanded ?
270+ new LatLng (curMapBoxLatLng .getLatitude ()- CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE ,
271+ curMapBoxLatLng .getLongitude ())
272+ : curMapBoxLatLng ) // Sets the new camera position
273+ .zoom (mapboxMap .getCameraPosition ().zoom ) // Same zoom level
274+ .build ();
275+ }
263276
264277 mapboxMap .animateCamera (CameraUpdateFactory
265278 .newCameraPosition (position ), 1000 );
@@ -273,12 +286,21 @@ private void updateMapCameraAccordingToBottomSheet(boolean isBottomListSheetExpa
273286 if (mapboxMap != null && curLatLng != null ) {
274287 if (isBottomListSheetExpanded ) {
275288 // Make camera to follow user on location change
276- position = new CameraPosition .Builder ()
277- .target (new LatLng (curLatLng .getLatitude () - CAMERA_TARGET_SHIFT_FACTOR ,
278- curLatLng .getLongitude ())) // Sets the new camera target above
279- // current to make it visible when sheet is expanded
280- .zoom (11 ) // Same zoom level
281- .build ();
289+ if (ViewUtil .isPortrait (getActivity ())) {
290+ position = new CameraPosition .Builder ()
291+ .target (new LatLng (curLatLng .getLatitude () - CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT ,
292+ curLatLng .getLongitude ())) // Sets the new camera target above
293+ // current to make it visible when sheet is expanded
294+ .zoom (11 ) // Same zoom level
295+ .build ();
296+ } else {
297+ position = new CameraPosition .Builder ()
298+ .target (new LatLng (curLatLng .getLatitude () - CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE ,
299+ curLatLng .getLongitude ())) // Sets the new camera target above
300+ // current to make it visible when sheet is expanded
301+ .zoom (11 ) // Same zoom level
302+ .build ();
303+ }
282304
283305 } else {
284306 // Make camera to follow user on location change
0 commit comments