mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +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.R;
|
||||||
import fr.free.nrw.commons.contributions.ContributionController;
|
import fr.free.nrw.commons.contributions.ContributionController;
|
||||||
import fr.free.nrw.commons.utils.UriDeserializer;
|
import fr.free.nrw.commons.utils.UriDeserializer;
|
||||||
|
import fr.free.nrw.commons.utils.ViewUtil;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
|
|
@ -105,7 +106,8 @@ public class NearbyMapFragment extends DaggerFragment {
|
||||||
private PolygonOptions currentLocationPolygonOptions;
|
private PolygonOptions currentLocationPolygonOptions;
|
||||||
|
|
||||||
private boolean isBottomListSheetExpanded;
|
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
|
@Inject
|
||||||
@Named("prefs")
|
@Named("prefs")
|
||||||
|
|
@ -253,13 +255,24 @@ public class NearbyMapFragment extends DaggerFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make camera to follow user on location change
|
// Make camera to follow user on location change
|
||||||
CameraPosition position = new CameraPosition.Builder()
|
CameraPosition position ;
|
||||||
.target(isBottomListSheetExpanded ?
|
if(ViewUtil.isPortrait(getActivity())){
|
||||||
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR,
|
position = new CameraPosition.Builder()
|
||||||
curMapBoxLatLng.getLongitude())
|
.target(isBottomListSheetExpanded ?
|
||||||
: curMapBoxLatLng ) // Sets the new camera position
|
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
|
||||||
.zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level
|
curMapBoxLatLng.getLongitude())
|
||||||
.build();
|
: 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
|
mapboxMap.animateCamera(CameraUpdateFactory
|
||||||
.newCameraPosition(position), 1000);
|
.newCameraPosition(position), 1000);
|
||||||
|
|
@ -273,12 +286,21 @@ public class NearbyMapFragment extends DaggerFragment {
|
||||||
if (mapboxMap != null && curLatLng != null) {
|
if (mapboxMap != null && curLatLng != null) {
|
||||||
if (isBottomListSheetExpanded) {
|
if (isBottomListSheetExpanded) {
|
||||||
// Make camera to follow user on location change
|
// Make camera to follow user on location change
|
||||||
position = new CameraPosition.Builder()
|
if(ViewUtil.isPortrait(getActivity())) {
|
||||||
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR,
|
position = new CameraPosition.Builder()
|
||||||
curLatLng.getLongitude())) // Sets the new camera target above
|
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
|
||||||
// current to make it visible when sheet is expanded
|
curLatLng.getLongitude())) // Sets the new camera target above
|
||||||
.zoom(11) // Same zoom level
|
// current to make it visible when sheet is expanded
|
||||||
.build();
|
.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 {
|
} else {
|
||||||
// Make camera to follow user on location change
|
// Make camera to follow user on location change
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package fr.free.nrw.commons.utils;
|
package fr.free.nrw.commons.utils;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.view.Display;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
@ -16,4 +18,13 @@ public class ViewUtil {
|
||||||
Toast.LENGTH_LONG).show();
|
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