Skip to content

Commit 794dbb8

Browse files
Fix modification on bottom sheet's data when coming from Nearby Banner and clicked on other pins (commons-app#5937)
* refactor getIconFor method and remove call to highlightNearestPlace() It ensures single responsibility on getIconFor method * refactor and fix icon issue when coming from nearby banner --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent 0c969c3 commit 794dbb8

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

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

+25-18
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ public void centerMapToPlace(@Nullable final Place place) {
965965
lastPlaceToCenter.location.getLatitude() - cameraShift,
966966
lastPlaceToCenter.getLocation().getLongitude(), 0));
967967
}
968+
highlightNearestPlace(place);
968969
}
969970

970971

@@ -2001,7 +2002,8 @@ public void updateMarker(final boolean isBookmarked, final Place place,
20012002
*
20022003
* @param nearestPlace nearest place, which has to be highlighted
20032004
*/
2004-
private void highlightNearestPlace(Place nearestPlace) {
2005+
private void highlightNearestPlace(final Place nearestPlace) {
2006+
binding.bottomSheetDetails.icon.setVisibility(View.VISIBLE);
20052007
passInfoToSheet(nearestPlace);
20062008
hideBottomSheet();
20072009
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
@@ -2015,32 +2017,37 @@ private void highlightNearestPlace(Place nearestPlace) {
20152017
* @return returns the drawable of marker according to the place information
20162018
*/
20172019
private @DrawableRes int getIconFor(Place place, Boolean isBookmarked) {
2018-
if (nearestPlace != null) {
2019-
if (place.name.equals(nearestPlace.name)) {
2020-
// Highlight nearest place only when user clicks on the home nearby banner
2021-
highlightNearestPlace(place);
2022-
return (isBookmarked ?
2023-
R.drawable.ic_custom_map_marker_purple_bookmarked :
2024-
R.drawable.ic_custom_map_marker_purple);
2025-
}
2020+
if (nearestPlace != null && place.name.equals(nearestPlace.name)) {
2021+
// Highlight nearest place only when user clicks on the home nearby banner
2022+
// highlightNearestPlace(place);
2023+
return (isBookmarked ?
2024+
R.drawable.ic_custom_map_marker_purple_bookmarked :
2025+
R.drawable.ic_custom_map_marker_purple
2026+
);
20262027
}
2028+
20272029
if (place.isMonument()) {
20282030
return R.drawable.ic_custom_map_marker_monuments;
2029-
} else if (!place.pic.trim().isEmpty()) {
2031+
}
2032+
if (!place.pic.trim().isEmpty()) {
20302033
return (isBookmarked ?
20312034
R.drawable.ic_custom_map_marker_green_bookmarked :
2032-
R.drawable.ic_custom_map_marker_green);
2033-
} else if (!place.exists) { // Means that the topic of the Wikidata item does not exist in the real world anymore, for instance it is a past event, or a place that was destroyed
2035+
R.drawable.ic_custom_map_marker_green
2036+
);
2037+
}
2038+
if (!place.exists) { // Means that the topic of the Wikidata item does not exist in the real world anymore, for instance it is a past event, or a place that was destroyed
20342039
return (R.drawable.ic_clear_black_24dp);
2035-
}else if (place.name == "") {
2040+
}
2041+
if (place.name.isEmpty()) {
20362042
return (isBookmarked ?
20372043
R.drawable.ic_custom_map_marker_grey_bookmarked :
2038-
R.drawable.ic_custom_map_marker_grey);
2039-
} else {
2040-
return (isBookmarked ?
2041-
R.drawable.ic_custom_map_marker_red_bookmarked :
2042-
R.drawable.ic_custom_map_marker_red);
2044+
R.drawable.ic_custom_map_marker_grey
2045+
);
20432046
}
2047+
return (isBookmarked ?
2048+
R.drawable.ic_custom_map_marker_red_bookmarked :
2049+
R.drawable.ic_custom_map_marker_red
2050+
);
20442051
}
20452052

20462053
/**

app/src/main/res/layout/bottom_sheet_details.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
android:layout_width="@dimen/dimen_40"
3333
android:layout_height="@dimen/dimen_40"
3434
android:layout_marginLeft="@dimen/standard_gap"
35-
android:visibility="gone"></ImageView>
35+
android:visibility="gone" />
3636

3737
<LinearLayout
3838
android:id="@+id/wikiDataLl"

0 commit comments

Comments
 (0)