mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Fix bottom sheet and current location marker visibilities
This commit is contained in:
parent
b057d8ca7b
commit
ae0bfae275
2 changed files with 47 additions and 14 deletions
|
|
@ -55,6 +55,7 @@ import dagger.android.support.DaggerFragment;
|
|||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.contributions.ContributionController;
|
||||
import fr.free.nrw.commons.utils.UriDeserializer;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
|
@ -105,7 +106,8 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
private PolygonOptions currentLocationPolygonOptions;
|
||||
|
||||
private boolean isBottomListSheetExpanded;
|
||||
private final double CAMERA_TARGET_SHIFT_FACTOR = 0.06;
|
||||
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.06;
|
||||
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04;
|
||||
|
||||
@Inject
|
||||
@Named("prefs")
|
||||
|
|
@ -253,13 +255,24 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
}
|
||||
|
||||
// Make camera to follow user on location change
|
||||
CameraPosition position = new CameraPosition.Builder()
|
||||
.target(isBottomListSheetExpanded ?
|
||||
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR,
|
||||
curMapBoxLatLng.getLongitude())
|
||||
: curMapBoxLatLng ) // Sets the new camera position
|
||||
.zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level
|
||||
.build();
|
||||
CameraPosition position ;
|
||||
if(ViewUtil.isPortrait(getActivity())){
|
||||
position = new CameraPosition.Builder()
|
||||
.target(isBottomListSheetExpanded ?
|
||||
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
|
||||
curMapBoxLatLng.getLongitude())
|
||||
: curMapBoxLatLng ) // Sets the new camera position
|
||||
.zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level
|
||||
.build();
|
||||
}else {
|
||||
position = new CameraPosition.Builder()
|
||||
.target(isBottomListSheetExpanded ?
|
||||
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
|
||||
curMapBoxLatLng.getLongitude())
|
||||
: curMapBoxLatLng ) // Sets the new camera position
|
||||
.zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level
|
||||
.build();
|
||||
}
|
||||
|
||||
mapboxMap.animateCamera(CameraUpdateFactory
|
||||
.newCameraPosition(position), 1000);
|
||||
|
|
@ -273,12 +286,21 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
if (mapboxMap != null && curLatLng != null) {
|
||||
if (isBottomListSheetExpanded) {
|
||||
// Make camera to follow user on location change
|
||||
position = new CameraPosition.Builder()
|
||||
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR,
|
||||
curLatLng.getLongitude())) // Sets the new camera target above
|
||||
// current to make it visible when sheet is expanded
|
||||
.zoom(11) // Same zoom level
|
||||
.build();
|
||||
if(ViewUtil.isPortrait(getActivity())) {
|
||||
position = new CameraPosition.Builder()
|
||||
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
|
||||
curLatLng.getLongitude())) // Sets the new camera target above
|
||||
// current to make it visible when sheet is expanded
|
||||
.zoom(11) // Same zoom level
|
||||
.build();
|
||||
} else {
|
||||
position = new CameraPosition.Builder()
|
||||
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
|
||||
curLatLng.getLongitude())) // Sets the new camera target above
|
||||
// current to make it visible when sheet is expanded
|
||||
.zoom(11) // Same zoom level
|
||||
.build();
|
||||
}
|
||||
|
||||
} else {
|
||||
// Make camera to follow user on location change
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
|
@ -16,4 +18,13 @@ public class ViewUtil {
|
|||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public static boolean isPortrait(Context context) {
|
||||
Display orientation = ((Activity)context).getWindowManager().getDefaultDisplay();
|
||||
if(orientation.getWidth() < orientation.getHeight()){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue