use of org.wikipedia.wikidata.DescriptionClient in project apps-android-wikipedia by wikimedia.
the class DisambigListAdapter method fetchDescriptions.
/**
* Start getting Wikidata descriptions (directly from the current Wikipedia wiki).
*/
private void fetchDescriptions() {
final List<PageTitle> titleList = new ArrayList<>();
for (DisambigResult r : items) {
titleList.add(r.getTitle());
}
if (titleList.isEmpty()) {
return;
}
new DescriptionClient().request(wiki, titleList, new DescriptionClient.Callback() {
@Override
public void success(@NonNull Call<MwQueryResponse> call, @NonNull List<MwQueryPage> results) {
for (MwQueryPage page : results) {
PageTitle pageTitle = new PageTitle(null, page.title(), wiki);
for (PageTitle title : titleList) {
if (title.getPrefixedText().equals(pageTitle.getPrefixedText()) || title.getDisplayText().equals(pageTitle.getDisplayText())) {
title.setDescription(page.description());
break;
}
}
}
notifyDataSetChanged();
}
@Override
public void failure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable caught) {
// descriptions are expendable
}
});
}
Aggregations