Skip to content

Commit 9f8becc

Browse files
committed
Make list item clicked and map focus to same place
1 parent 6d41622 commit 9f8becc

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import fr.free.nrw.commons.contributions.ContributionController;
3434
import fr.free.nrw.commons.di.ApplicationlessInjection;
3535
import fr.free.nrw.commons.kvstore.JsonKvStore;
36+
import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment;
3637
import timber.log.Timber;
3738

3839
import static fr.free.nrw.commons.theme.NavigationBaseActivity.startActivityWithFlags;
@@ -117,7 +118,7 @@ protected void hookListeners(View view) {
117118
}
118119
}
119120
if (onBookmarkClick == null) {
120-
//((NearbyFragment) fragment.getParentFragment()).centerMapToPlace(place);
121+
((NearbyParentFragment) fragment.getParentFragment()).centerMapToPlace(place);
121122
}
122123
};
123124
view.setOnClickListener(listener);

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

+24
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
7575
private MapFragment.OnMapViewReadyCallback mapViewReadyCallback;
7676
private MapboxMap mapboxMap;
7777
private MapView map;
78+
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.005;
79+
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004;
80+
private static final double ZOOM_LEVEL = 14f;
7881

7982
/**
8083
* Creates a default MapFragment instance
@@ -435,5 +438,26 @@ public void updateMarker(boolean isBookmarked, Place place, LatLng curLatLng) {
435438
}
436439
}
437440

441+
/**
442+
* Centers the map in nearby fragment to a given place
443+
* @param place is new center of the map
444+
*/
445+
public void centerMapToPlace(Place place, boolean isPortraitMode) {
446+
Log.d("denemeSon","isPortyrait:"+isPortraitMode);
447+
double cameraShift;
448+
if (isPortraitMode) {
449+
cameraShift = CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT;
450+
} else {
451+
cameraShift = CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE;
452+
}
453+
CameraPosition position = new CameraPosition.Builder()
454+
.target(LocationUtils.commonsLatLngToMapBoxLatLng(
455+
new LatLng(place.location.getLatitude()-cameraShift,
456+
place.getLocation().getLongitude(),
457+
0))) // Sets the new camera position
458+
.zoom(ZOOM_LEVEL) // Same zoom level
459+
.build();
460+
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
461+
}
438462
}
439463

app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.Context;
77
import android.content.Intent;
88
import android.content.IntentFilter;
9+
import android.content.res.Configuration;
910
import android.os.Bundle;
1011
import android.util.Log;
1112
import android.view.Gravity;
@@ -398,6 +399,16 @@ public void onStyleLoaded(@NonNull Style style) {
398399
return mapFragment;
399400
}
400401

402+
public void centerMapToPlace(Place place) {
403+
Log.d("denemeson","place:"+place);
404+
if (nearbyMapFragment != null) {
405+
nearbyMapFragment.centerMapToPlace(
406+
place,
407+
getActivity().getResources().getConfiguration().orientation ==
408+
Configuration.ORIENTATION_PORTRAIT);
409+
}
410+
}
411+
401412
NearbyListFragment setListFragment() {
402413
///if (savedInstanceState == null) {
403414
NearbyListFragment nearbyListFragment;

0 commit comments

Comments
 (0)