Skip to content

Commit 33cc08b

Browse files
cypheropmisaochan
authored andcommitted
Center map on location clicked in nearby list and notification card(#2060) (#2366)
* center map on location clicked in nearby (#2060) * improved animation * Center map on location clicked in nearby list * removed unnecessary methods * center map on location clicked in nearby notification card * some minor changes * travis build error * resolved errors * Tidy up PR
1 parent b48c72f commit 33cc08b

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,17 @@ public void onPause() {
705705
}
706706
}
707707

708+
709+
/**
710+
* Centers the map in nearby fragment to a given place
711+
* @param place is new center of the map
712+
*/
713+
public void centerMapToPlace(Place place) {
714+
if (nearbyMapFragment != null) {
715+
nearbyMapFragment.centerMapToPlace(place);
716+
}
717+
}
718+
708719
public boolean isBottomSheetExpanded() { return bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED;
709720
}
710721
}

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

+21-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
225225
Timber.d("curLatLng found, setting up map view...");
226226
setupMapView(savedInstanceState);
227227
}
228-
229228
setHasOptionsMenu(false);
230229

231230
return mapView;
@@ -254,6 +253,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
254253
});
255254
}
256255

256+
257257
/**
258258
* Updates map slightly means it doesn't updates all nearby markers around. It just updates
259259
* location tracker marker of user.
@@ -719,7 +719,6 @@ private void addNearbyMarkersToMapBoxMap(@Nullable List<NearbyBaseMarker> custom
719719
passInfoToSheet(place);
720720
bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
721721
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
722-
723722
}
724723
return false;
725724
});
@@ -1040,6 +1039,25 @@ public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
10401039
}
10411040
}
10421041

1042+
/**
1043+
* Centers the map in nearby fragment to a given place
1044+
* @param place is new center of the map
1045+
*/
1046+
public void centerMapToPlace(Place place) {
1047+
mapView.getMapAsync(mapboxMap1 -> {
1048+
CameraPosition position = new CameraPosition.Builder()
1049+
.target(isBottomListSheetExpanded ?
1050+
new LatLng(place.location.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
1051+
place.getLocation().getLongitude())
1052+
: new LatLng(place.getLocation().getLatitude(), place.getLocation().getLongitude(), 0)) // Sets the new camera position
1053+
.zoom(isBottomListSheetExpanded ?
1054+
ZOOM_LEVEL
1055+
:mapboxMap.getCameraPosition().zoom) // Same zoom level
1056+
.build();
1057+
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
1058+
});
1059+
}
1060+
10431061

10441062
public void updateMarker(boolean isBookmarked, Place place) {
10451063

@@ -1077,5 +1095,6 @@ public void updateMarker(boolean isBookmarked, Place place) {
10771095

10781096
}
10791097

1098+
10801099
}
10811100

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import fr.free.nrw.commons.utils.ViewUtil;
1818
import timber.log.Timber;
1919

20+
import static fr.free.nrw.commons.contributions.MainActivity.NEARBY_TAB_POSITION;
21+
2022
/**
2123
* Custom card view for nearby notification card view on main screen, above contributions list
2224
*/
@@ -66,7 +68,6 @@ private void init() {
6668

6769
progressBar = rootView.findViewById(R.id.progressBar);
6870

69-
setActionListeners();
7071
}
7172

7273
@Override
@@ -81,8 +82,16 @@ protected void onAttachedToWindow() {
8182
}
8283

8384

84-
private void setActionListeners() {
85-
this.setOnClickListener(view -> ((MainActivity)getContext()).viewPager.setCurrentItem(1));
85+
private void setActionListeners(Place place) {
86+
this.setOnClickListener(view -> {
87+
MainActivity m = (MainActivity) getContext();
88+
89+
// Change to nearby tab
90+
m.viewPager.setCurrentItem(NEARBY_TAB_POSITION);
91+
92+
// Center the map to the place
93+
((NearbyFragment) m.contributionsActivityPagerAdapter.getItem(NEARBY_TAB_POSITION)).centerMapToPlace(place);
94+
});
8695
}
8796

8897
@Override public boolean onSwipe(View view) {
@@ -120,6 +129,7 @@ public void updateContent(Place place) {
120129
contentLayout.setVisibility(VISIBLE);
121130
// Make progress bar invisible once data is ready
122131
progressBar.setVisibility(GONE);
132+
setActionListeners(place);
123133
// And content views visible since they are ready
124134
notificationTitle.setVisibility(VISIBLE);
125135
notificationDistance.setVisibility(VISIBLE);

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ protected void hookListeners(View view) {
116116
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(lastPosition, buttonLayout.getHeight());
117117
}
118118
}
119-
119+
if (onBookmarkClick == null) {
120+
((NearbyFragment) fragment.getParentFragment()).centerMapToPlace(place);
121+
}
120122
};
121123
view.setOnClickListener(listener);
124+
122125
view.requestFocus();
123126
view.setOnFocusChangeListener((view1, hasFocus) -> {
124127
if (!hasFocus && buttonLayout.isShown()) {

0 commit comments

Comments
 (0)