Make list item clicked and map focus to same place

This commit is contained in:
neslihanturan 2019-09-15 21:15:25 +03:00
parent 6d41622b7d
commit 9f8becc581
3 changed files with 37 additions and 1 deletions

View file

@ -33,6 +33,7 @@ import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
import fr.free.nrw.commons.contributions.ContributionController; import fr.free.nrw.commons.contributions.ContributionController;
import fr.free.nrw.commons.di.ApplicationlessInjection; import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.kvstore.JsonKvStore; import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment;
import timber.log.Timber; import timber.log.Timber;
import static fr.free.nrw.commons.theme.NavigationBaseActivity.startActivityWithFlags; import static fr.free.nrw.commons.theme.NavigationBaseActivity.startActivityWithFlags;
@ -117,7 +118,7 @@ public class PlaceRenderer extends Renderer<Place> {
} }
} }
if (onBookmarkClick == null) { if (onBookmarkClick == null) {
//((NearbyFragment) fragment.getParentFragment()).centerMapToPlace(place); ((NearbyParentFragment) fragment.getParentFragment()).centerMapToPlace(place);
} }
}; };
view.setOnClickListener(listener); view.setOnClickListener(listener);

View file

@ -75,6 +75,9 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
private MapFragment.OnMapViewReadyCallback mapViewReadyCallback; private MapFragment.OnMapViewReadyCallback mapViewReadyCallback;
private MapboxMap mapboxMap; private MapboxMap mapboxMap;
private MapView map; private MapView map;
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.005;
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004;
private static final double ZOOM_LEVEL = 14f;
/** /**
* Creates a default MapFragment instance * Creates a default MapFragment instance
@ -435,5 +438,26 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
} }
} }
/**
* Centers the map in nearby fragment to a given place
* @param place is new center of the map
*/
public void centerMapToPlace(Place place, boolean isPortraitMode) {
Log.d("denemeSon","isPortyrait:"+isPortraitMode);
double cameraShift;
if (isPortraitMode) {
cameraShift = CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT;
} else {
cameraShift = CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE;
}
CameraPosition position = new CameraPosition.Builder()
.target(LocationUtils.commonsLatLngToMapBoxLatLng(
new LatLng(place.location.getLatitude()-cameraShift,
place.getLocation().getLongitude(),
0))) // Sets the new camera position
.zoom(ZOOM_LEVEL) // Same zoom level
.build();
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
}
} }

View file

@ -6,6 +6,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
@ -398,6 +399,16 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
return mapFragment; return mapFragment;
} }
public void centerMapToPlace(Place place) {
Log.d("denemeson","place:"+place);
if (nearbyMapFragment != null) {
nearbyMapFragment.centerMapToPlace(
place,
getActivity().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT);
}
}
NearbyListFragment setListFragment() { NearbyListFragment setListFragment() {
///if (savedInstanceState == null) { ///if (savedInstanceState == null) {
NearbyListFragment nearbyListFragment; NearbyListFragment nearbyListFragment;