Skip to content

Commit e791477

Browse files
committed
fixed issue commons-app#3111
1 parent 1607bd9 commit e791477

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

app/src/main/java/fr/free/nrw/commons/MediaDataExtractor.java

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ private ArrayList<Map<String, String>> formatDepictions(JsonObject mediaResponse
9090
JsonObject depictedItem = (JsonObject) depictionArray.get(i);
9191
Map <String, String> depictedObject = new HashMap<>();
9292
depictedObject.put("label", depictedItem.get("label").toString().substring(3, depictedItem.get("label").toString().length()-3));
93-
depictedObject.put("url", depictedItem.get("url").toString().substring(3, depictedItem.get("url").toString().length() - 3));
9493
depictedObject.put("id", depictedItem.get("id").toString().substring(1, depictedItem.get("id").toString().length() - 1));
9594
depictedItemList.add(depictedObject);
9695
}

app/src/main/java/fr/free/nrw/commons/media/MediaClient.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private JsonObject fetchCaptionandDepictionsFromMediaDetailResponse(MediaDetailR
249249
Map<String, LinkedTreeMap> datavalue = (Map<String, LinkedTreeMap>) mainsnak.get("datavalue");
250250
LinkedTreeMap value = datavalue.get("value");
251251
String id = value.get("id").toString();
252-
JsonObject jsonObject = getLabelForDepiction(id)
252+
JsonObject jsonObject = getLabelForDepiction(id, Locale.getDefault().getLanguage())
253253
.subscribeOn(Schedulers.newThread())
254254
.blockingGet();
255255
jsonArray.add(jsonObject);
@@ -284,21 +284,22 @@ private JsonObject fetchCaptionandDepictionsFromMediaDetailResponse(MediaDetailR
284284
* @return Json Object having label and wikidata url for the Depiction Entity
285285
*/
286286

287-
public Single<JsonObject> getLabelForDepiction(String entityId) {
288-
return mediaDetailInterface.fetchLabelForWikidata(entityId)
287+
public Single<JsonObject> getLabelForDepiction(String entityId, String language) {
288+
return mediaDetailInterface.getDepictions(entityId, language)
289289
.map(jsonResponse -> {
290290
try {
291291
if (jsonResponse.get("success").toString().equals("1")) {
292-
JsonArray search = (JsonArray) jsonResponse.get("search");
293-
JsonObject searchElement = (JsonObject) search.get(0);
294-
String label = searchElement.get("label").toString();
295-
String url = searchElement.get("concepturi").toString();
292+
JsonObject entities = (JsonObject) jsonResponse.getAsJsonObject().get("entities");
293+
JsonObject responseObject = (JsonObject) entities.getAsJsonObject().get(entityId);
294+
JsonObject labels = responseObject.getAsJsonObject("labels");
295+
JsonObject languageObject = labels.getAsJsonObject(language);
296+
String label = String.valueOf(languageObject.get("value"));
297+
298+
296299
JsonElement labelJson = new JsonPrimitive(label);
297-
JsonElement urlJson = new JsonPrimitive(url);
298300
JsonElement idJson = new JsonPrimitive(entityId);
299301
JsonObject jsonObject = new JsonObject();
300302
jsonObject.add("label", labelJson);
301-
jsonObject.add("url", urlJson);
302303
jsonObject.add("id", idJson);
303304
return jsonObject;
304305
}

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,8 @@ private void rebuildDepictionList() {
347347
depictionContainer.removeAllViews();
348348
for (int i = 0; i<depictions.size(); i++) {
349349
String depictionName = depictions.get(i).get("label");
350-
String depictionUrl = depictions.get(i).get("url");
351350
String entityId = depictions.get(i).get("id");
352-
View depictLabel = buildDepictLabel(depictionName, depictionUrl, entityId, depictionContainer);
351+
View depictLabel = buildDepictLabel(depictionName, entityId, depictionContainer);
353352
depictionContainer.addView(depictLabel);
354353
}
355354
}
@@ -518,7 +517,7 @@ private void rebuildCatList() {
518517
* Add view to depictions obtained also tapping on depictions should open the url
519518
*/
520519

521-
private View buildDepictLabel(String depictionName, String depictionUrl, String entityId, LinearLayout depictionContainer) {
520+
private View buildDepictLabel(String depictionName, String entityId, LinearLayout depictionContainer) {
522521
final View item = LayoutInflater.from(getContext()).inflate(R.layout.detail_depicts_item, depictionContainer, false);
523522
final CompatTextView textView = item.findViewById(R.id.media_detail_depicted_item_text);
524523

app/src/main/java/fr/free/nrw/commons/media/MediaDetailInterface.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public interface MediaDetailInterface {
2020
@GET("w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1&sites=commonswiki")
2121
Observable<MediaDetailResponse> fetchStructuredDataByFilename(@Query("languages") String language, @Query("titles") String filename);
2222

23-
@GET("w/api.php?action=wbsearchentities&format=json&language=en")
24-
Observable<JsonObject> fetchLabelForWikidata(@Query("search") String entityId);
23+
@GET("/w/api.php?format=json&action=wbgetentities&props=labels&languagefallback=1")
24+
Observable<JsonObject> getDepictions(@Query("ids") String entityId, @Query("languages") String language);
2525
}

0 commit comments

Comments
 (0)