Skip to content

Commit ae0bfae

Browse files
committed
Fix bottom sheet and current location marker visibilities
1 parent b057d8c commit ae0bfae

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import fr.free.nrw.commons.R;
5656
import fr.free.nrw.commons.contributions.ContributionController;
5757
import fr.free.nrw.commons.utils.UriDeserializer;
58+
import fr.free.nrw.commons.utils.ViewUtil;
5859
import timber.log.Timber;
5960

6061
import 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

app/src/main/java/fr/free/nrw/commons/utils/ViewUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package fr.free.nrw.commons.utils;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.support.design.widget.Snackbar;
6+
import android.view.Display;
57
import android.view.View;
68
import android.widget.Toast;
79

@@ -16,4 +18,13 @@ public static void showLongToast(Context context, String text) {
1618
Toast.LENGTH_LONG).show();
1719
}
1820

21+
public static boolean isPortrait(Context context) {
22+
Display orientation = ((Activity)context).getWindowManager().getDefaultDisplay();
23+
if(orientation.getWidth() < orientation.getHeight()){
24+
return true;
25+
} else {
26+
return false;
27+
}
28+
}
29+
1930
}

0 commit comments

Comments
 (0)