53
53
54
54
import dagger .android .support .DaggerFragment ;
55
55
import fr .free .nrw .commons .R ;
56
+ import fr .free .nrw .commons .Utils ;
56
57
import fr .free .nrw .commons .contributions .ContributionController ;
57
58
import fr .free .nrw .commons .utils .UriDeserializer ;
59
+ import fr .free .nrw .commons .utils .ViewUtil ;
58
60
import timber .log .Timber ;
59
61
60
62
import static android .app .Activity .RESULT_OK ;
@@ -105,7 +107,8 @@ public class NearbyMapFragment extends DaggerFragment {
105
107
private PolygonOptions currentLocationPolygonOptions ;
106
108
107
109
private boolean isBottomListSheetExpanded ;
108
- 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 ;
109
112
110
113
@ Inject
111
114
@ Named ("prefs" )
@@ -253,13 +256,28 @@ private void updateMapToTrackPosition() {
253
256
}
254
257
255
258
// 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 ();
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
+ }
263
281
264
282
mapboxMap .animateCamera (CameraUpdateFactory
265
283
.newCameraPosition (position ), 1000 );
@@ -273,12 +291,21 @@ private void updateMapCameraAccordingToBottomSheet(boolean isBottomListSheetExpa
273
291
if (mapboxMap != null && curLatLng != null ) {
274
292
if (isBottomListSheetExpanded ) {
275
293
// 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 ();
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
+ }
282
309
283
310
} else {
284
311
// Make camera to follow user on location change
@@ -344,10 +371,29 @@ private void setListeners() {
344
371
fabRecenter .setOnClickListener (view -> {
345
372
if (curLatLng != null ) {
346
373
mapView .getMapAsync (mapboxMap -> {
347
- CameraPosition position = new CameraPosition .Builder ()
348
- .target (new LatLng (curLatLng .getLatitude (), curLatLng .getLongitude ())) // Sets the new camera position
349
- .zoom (11 ) // Sets the zoom
350
- .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
+ }
351
397
352
398
mapboxMap .animateCamera (CameraUpdateFactory
353
399
.newCameraPosition (position ), 1000 );
@@ -534,7 +580,9 @@ public void prepareViewsForSheetPosition(int bottomSheetState) {
534
580
transparentView .setAlpha (0 );
535
581
closeFabs (isFabOpen );
536
582
hideFAB ();
537
- this .getView ().requestFocus ();
583
+ if (this .getView () != null ) {
584
+ this .getView ().requestFocus ();
585
+ }
538
586
break ;
539
587
}
540
588
}
@@ -700,8 +748,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
700
748
}
701
749
702
750
private void openWebView (Uri link ) {
703
- Intent browserIntent = new Intent (Intent .ACTION_VIEW , link );
704
- startActivity (browserIntent );
751
+ Utils .handleWebUrl (getContext (), link );
705
752
}
706
753
707
754
private void animateFAB (boolean isFabOpen ) {
@@ -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