ExploreMapFragment.java: fix marker labels in Explore map fragment to display the username

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.
This commit is contained in:
Jason Whitmore 2025-03-29 19:16:24 -07:00
parent 669f3043ae
commit d7cea1add5

View file

@ -708,8 +708,17 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
GeoPoint point = new GeoPoint( GeoPoint point = new GeoPoint(
nearbyBaseMarker.getPlace().location.getLatitude(), nearbyBaseMarker.getPlace().location.getLatitude(),
nearbyBaseMarker.getPlace().location.getLongitude()); nearbyBaseMarker.getPlace().location.getLongitude());
OverlayItem item = new OverlayItem(nearbyBaseMarker.getPlace().name, null,
point); Media markerMedia = this.getMediaFromImageURL(nearbyBaseMarker.getPlace().pic);
String authorUser = null;
if (markerMedia != null) {
authorUser = markerMedia.getAuthorOrUser();
// HTML text is sometimes part of the author string and needs to be removed
authorUser = Html.fromHtml(authorUser, Html.FROM_HTML_MODE_LEGACY).toString();
}
OverlayItem item = new OverlayItem(nearbyBaseMarker.getPlace().name,
authorUser, point);
item.setMarker(d); item.setMarker(d);
items.add(item); items.add(item);
ItemizedOverlayWithFocus overlay = new ItemizedOverlayWithFocus(items, ItemizedOverlayWithFocus overlay = new ItemizedOverlayWithFocus(items,
@ -740,6 +749,26 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
} }
} }
/**
* Retrieves the specific Media object from the mediaList field.
* @param url The specific Media's image URL.
* @return The Media object that matches the URL or null if it could not be found.
*/
private Media getMediaFromImageURL(String url) {
if (mediaList == null || url == null) {
return null;
}
for (int i = 0; i < mediaList.size(); i++) {
if (mediaList.get(i) != null && mediaList.get(i).getImageUrl() != null
&& mediaList.get(i).getImageUrl().equals(url)) {
return mediaList.get(i);
}
}
return null;
}
/** /**
* Removes a marker from the map based on the specified NearbyBaseMarker. * Removes a marker from the map based on the specified NearbyBaseMarker.
* *