56
56
import fr .free .nrw .commons .Utils ;
57
57
import fr .free .nrw .commons .contributions .ContributionController ;
58
58
import fr .free .nrw .commons .utils .UriDeserializer ;
59
+ import fr .free .nrw .commons .utils .ViewUtil ;
59
60
import timber .log .Timber ;
60
61
61
62
import static android .app .Activity .RESULT_OK ;
@@ -106,7 +107,8 @@ public class NearbyMapFragment extends DaggerFragment {
106
107
private PolygonOptions currentLocationPolygonOptions ;
107
108
108
109
private boolean isBottomListSheetExpanded ;
109
- private final double CAMERA_TARGET_SHIFT_FACTOR = 0.06 ;
110
+ private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.06 ;
111
+ private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04 ;
110
112
111
113
@ Inject
112
114
@ Named ("prefs" )
@@ -254,13 +256,28 @@ private void updateMapToTrackPosition() {
254
256
}
255
257
256
258
// Make camera to follow user on location change
257
- CameraPosition position = new CameraPosition .Builder ()
258
- .target (isBottomListSheetExpanded ?
259
- new LatLng (curMapBoxLatLng .getLatitude ()- CAMERA_TARGET_SHIFT_FACTOR ,
260
- curMapBoxLatLng .getLongitude ())
261
- : curMapBoxLatLng ) // Sets the new camera position
262
- .zoom (mapboxMap .getCameraPosition ().zoom ) // Same zoom level
263
- .build ();
259
+ CameraPosition position ;
260
+ if (ViewUtil .isPortrait (getActivity ())){
261
+ position = new CameraPosition .Builder ()
262
+ .target (isBottomListSheetExpanded ?
263
+ new LatLng (curMapBoxLatLng .getLatitude ()- CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT ,
264
+ curMapBoxLatLng .getLongitude ())
265
+ : curMapBoxLatLng ) // Sets the new camera position
266
+ .zoom (isBottomListSheetExpanded ?
267
+ 11 // zoom level is fixed to 11 when bottom sheet is expanded
268
+ :mapboxMap .getCameraPosition ().zoom ) // Same zoom level
269
+ .build ();
270
+ }else {
271
+ position = new CameraPosition .Builder ()
272
+ .target (isBottomListSheetExpanded ?
273
+ new LatLng (curMapBoxLatLng .getLatitude ()- CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE ,
274
+ curMapBoxLatLng .getLongitude ())
275
+ : curMapBoxLatLng ) // Sets the new camera position
276
+ .zoom (isBottomListSheetExpanded ?
277
+ 11 // zoom level is fixed to 11 when bottom sheet is expanded
278
+ :mapboxMap .getCameraPosition ().zoom ) // Same zoom level
279
+ .build ();
280
+ }
264
281
265
282
mapboxMap .animateCamera (CameraUpdateFactory
266
283
.newCameraPosition (position ), 1000 );
@@ -274,12 +291,21 @@ private void updateMapCameraAccordingToBottomSheet(boolean isBottomListSheetExpa
274
291
if (mapboxMap != null && curLatLng != null ) {
275
292
if (isBottomListSheetExpanded ) {
276
293
// Make camera to follow user on location change
277
- position = new CameraPosition .Builder ()
278
- .target (new LatLng (curLatLng .getLatitude () - CAMERA_TARGET_SHIFT_FACTOR ,
279
- curLatLng .getLongitude ())) // Sets the new camera target above
280
- // current to make it visible when sheet is expanded
281
- .zoom (11 ) // Same zoom level
282
- .build ();
294
+ if (ViewUtil .isPortrait (getActivity ())) {
295
+ position = new CameraPosition .Builder ()
296
+ .target (new LatLng (curLatLng .getLatitude () - CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT ,
297
+ curLatLng .getLongitude ())) // Sets the new camera target above
298
+ // current to make it visible when sheet is expanded
299
+ .zoom (11 ) // Fixed zoom level
300
+ .build ();
301
+ } else {
302
+ position = new CameraPosition .Builder ()
303
+ .target (new LatLng (curLatLng .getLatitude () - CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE ,
304
+ curLatLng .getLongitude ())) // Sets the new camera target above
305
+ // current to make it visible when sheet is expanded
306
+ .zoom (11 ) // Fixed zoom level
307
+ .build ();
308
+ }
283
309
284
310
} else {
285
311
// Make camera to follow user on location change
@@ -345,10 +371,29 @@ private void setListeners() {
345
371
fabRecenter .setOnClickListener (view -> {
346
372
if (curLatLng != null ) {
347
373
mapView .getMapAsync (mapboxMap -> {
348
- CameraPosition position = new CameraPosition .Builder ()
349
- .target (new LatLng (curLatLng .getLatitude (), curLatLng .getLongitude ())) // Sets the new camera position
350
- .zoom (11 ) // Sets the zoom
351
- .build (); // Creates a CameraPosition from the builder
374
+ CameraPosition position ;
375
+
376
+ if (ViewUtil .isPortrait (getActivity ())){
377
+ position = new CameraPosition .Builder ()
378
+ .target (isBottomListSheetExpanded ?
379
+ new LatLng (curLatLng .getLatitude ()- CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT ,
380
+ curLatLng .getLongitude ())
381
+ : new LatLng (curLatLng .getLatitude (), curLatLng .getLongitude (), 0 )) // Sets the new camera position
382
+ .zoom (isBottomListSheetExpanded ?
383
+ 11 // zoom level is fixed to 11 when bottom sheet is expanded
384
+ :mapboxMap .getCameraPosition ().zoom ) // Same zoom level
385
+ .build ();
386
+ }else {
387
+ position = new CameraPosition .Builder ()
388
+ .target (isBottomListSheetExpanded ?
389
+ new LatLng (curLatLng .getLatitude ()- CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE ,
390
+ curLatLng .getLongitude ())
391
+ : new LatLng (curLatLng .getLatitude (), curLatLng .getLongitude (), 0 )) // Sets the new camera position
392
+ .zoom (isBottomListSheetExpanded ?
393
+ 11 // zoom level is fixed to 11 when bottom sheet is expanded
394
+ :mapboxMap .getCameraPosition ().zoom ) // Same zoom level
395
+ .build ();
396
+ }
352
397
353
398
mapboxMap .animateCamera (CameraUpdateFactory
354
399
.newCameraPosition (position ), 1000 );
@@ -535,7 +580,9 @@ public void prepareViewsForSheetPosition(int bottomSheetState) {
535
580
transparentView .setAlpha (0 );
536
581
closeFabs (isFabOpen );
537
582
hideFAB ();
538
- this .getView ().requestFocus ();
583
+ if (this .getView () != null ) {
584
+ this .getView ().requestFocus ();
585
+ }
539
586
break ;
540
587
}
541
588
}
@@ -776,6 +823,9 @@ public void onDestroyView() {
776
823
if (mapView != null ) {
777
824
mapView .onDestroy ();
778
825
}
826
+ selected = null ;
827
+ currentLocationMarker = null ;
828
+
779
829
super .onDestroyView ();
780
830
}
781
831
0 commit comments