#3752 Media details do not show depiction - make request return all languages available and choose preferred or first (#3761)

This commit is contained in:
Seán Mac Gillicuddy 2020-05-21 13:51:20 +01:00 committed by GitHub
parent 3f31c3eded
commit 618ace707b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View file

@ -208,11 +208,15 @@ public class MediaClient {
* @return label
*/
public Single<String> getLabelForDepiction(String entityId, String language) {
return mediaDetailInterface.getEntity(entityId, language)
return mediaDetailInterface.getEntity(entityId)
.map(entities -> {
if (isSuccess(entities)) {
for (Entity entity : entities.entities().values()) {
for (Label label : entity.labels().values()) {
final Map<String, Label> languageToLabelMap = entity.labels();
if (languageToLabelMap.containsKey(language)) {
return languageToLabelMap.get(language).value();
}
for (Label label : languageToLabelMap.values()) {
return label.value();
}
}

View file

@ -20,12 +20,11 @@ public interface MediaDetailInterface {
/**
* Gets labels for Depictions using Entity Id from MediaWikiAPI
* @param entityId EntityId (Ex: Q81566) of the depict entity
*
* @param entityId EntityId (Ex: Q81566) of the depict entity
* @param language user's locale
*/
@GET("/w/api.php?format=json&action=wbgetentities&props=labels&languagefallback=1")
Observable<Entities> getEntity(@Query("ids") String entityId, @Query("languages") String language);
Observable<Entities> getEntity(@Query("ids") String entityId);
/**
* Fetches caption using wikibaseIdentifier