Search in sources :

Example 1 with DescriptionClient

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
        }
    });
}
Also used : DescriptionClient(org.wikipedia.wikidata.DescriptionClient) MwQueryPage(org.wikipedia.dataclient.mwapi.MwQueryPage) ArrayList(java.util.ArrayList) MwQueryResponse(org.wikipedia.dataclient.mwapi.MwQueryResponse)

Aggregations

ArrayList (java.util.ArrayList)1 MwQueryPage (org.wikipedia.dataclient.mwapi.MwQueryPage)1 MwQueryResponse (org.wikipedia.dataclient.mwapi.MwQueryResponse)1 DescriptionClient (org.wikipedia.wikidata.DescriptionClient)1