Skip to content

Commit 6e090c8

Browse files
ExploreMapFragment.java: fix marker labels in Explore map fragment to display the username (#6260)
Before this change, the labels that would appear on the marker when tapped did not include the author or username. Instead, it displayed "Unknown". After this change, the labels now display the author name. If the author name is not available, the username will be displayed. If both are unavailable, the default value of "Unknown" will be displayed. To improve the readability of the text, any HTML text is removed from the username/author.
1 parent 4496664 commit 6e090c8

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java

+31-2
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,17 @@ private void addMarkerToMap(BaseMarker nearbyBaseMarker) {
708708
GeoPoint point = new GeoPoint(
709709
nearbyBaseMarker.getPlace().location.getLatitude(),
710710
nearbyBaseMarker.getPlace().location.getLongitude());
711-
OverlayItem item = new OverlayItem(nearbyBaseMarker.getPlace().name, null,
712-
point);
711+
712+
Media markerMedia = this.getMediaFromImageURL(nearbyBaseMarker.getPlace().pic);
713+
String authorUser = null;
714+
if (markerMedia != null) {
715+
authorUser = markerMedia.getAuthorOrUser();
716+
// HTML text is sometimes part of the author string and needs to be removed
717+
authorUser = Html.fromHtml(authorUser, Html.FROM_HTML_MODE_LEGACY).toString();
718+
}
719+
720+
OverlayItem item = new OverlayItem(nearbyBaseMarker.getPlace().name,
721+
authorUser, point);
713722
item.setMarker(d);
714723
items.add(item);
715724
ItemizedOverlayWithFocus overlay = new ItemizedOverlayWithFocus(items,
@@ -740,6 +749,26 @@ public boolean onItemLongPress(int index, OverlayItem item) {
740749
}
741750
}
742751

752+
/**
753+
* Retrieves the specific Media object from the mediaList field.
754+
* @param url The specific Media's image URL.
755+
* @return The Media object that matches the URL or null if it could not be found.
756+
*/
757+
private Media getMediaFromImageURL(String url) {
758+
if (mediaList == null || url == null) {
759+
return null;
760+
}
761+
762+
for (int i = 0; i < mediaList.size(); i++) {
763+
if (mediaList.get(i) != null && mediaList.get(i).getImageUrl() != null
764+
&& mediaList.get(i).getImageUrl().equals(url)) {
765+
return mediaList.get(i);
766+
}
767+
}
768+
769+
return null;
770+
}
771+
743772
/**
744773
* Removes a marker from the map based on the specified NearbyBaseMarker.
745774
*

0 commit comments

Comments
 (0)