use of org.wikipedia.dataclient.mwapi.MwQueryResponse 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
}
});
}
use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.
the class DisambigListAdapter method requestPageImages.
private void requestPageImages() {
List<PageTitle> titleList = new ArrayList<>();
for (DisambigResult r : items) {
if (pageImagesCache.get(r.getTitle().getPrefixedText()) == null) {
// not in our cache yet
titleList.add(r.getTitle());
}
}
if (titleList.isEmpty()) {
return;
}
new PageImagesClient().request(wiki, titleList, new PageImagesClient.Callback() {
@Override
public void success(@NonNull Call<MwQueryResponse> call, @NonNull Map<PageTitle, PageImage> results) {
for (Map.Entry<PageTitle, PageImage> entry : results.entrySet()) {
if (entry.getValue() == null || entry.getValue().getImageName() == null) {
continue;
}
pageImagesCache.put(entry.getKey().getPrefixedText(), entry.getValue().getImageName());
}
notifyDataSetInvalidated();
}
@Override
public void failure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable caught) {
// Don't actually do anything.
// Thumbnails are expendable
}
});
}
use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.
the class BottomContentView method requestReadMoreItems.
private void requestReadMoreItems(final HistoryEntry entry) {
if (entry == null || TextUtils.isEmpty(entry.getTitle().getPrefixedText())) {
hideReadMore();
return;
}
final long timeMillis = System.currentTimeMillis();
new FullTextSearchClient().requestMoreLike(entry.getTitle().getWikiSite(), entry.getTitle().getPrefixedText(), null, null, Constants.MAX_SUGGESTION_RESULTS * 2, new FullTextSearchClient.Callback() {
@Override
public void success(@NonNull Call<MwQueryResponse> call, @NonNull SearchResults results) {
funnel.setLatency(System.currentTimeMillis() - timeMillis);
readMoreItems = SearchResults.filter(results, entry.getTitle().getPrefixedText(), true);
if (!readMoreItems.getResults().isEmpty()) {
readMoreAdapter.setResults(results.getResults());
showReadMore();
} else {
// If there's no results, just hide the section
hideReadMore();
}
}
@Override
public void failure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable caught) {
// Read More titles are expendable.
L.w("Error while fetching Read More titles.", caught);
}
});
}
use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.
the class ShareHandler method shareSnippet.
private void shareSnippet(@NonNull CharSequence input) {
final String selectedText = StringUtil.sanitizeText(input.toString());
final PageTitle title = fragment.getTitle();
final String leadImageNameText = fragment.getPage().getPageProperties().getLeadImageName() != null ? fragment.getPage().getPageProperties().getLeadImageName() : "";
new ImageLicenseFetchClient().request(title.getWikiSite(), new PageTitle(Namespace.FILE.toLegacyString(), leadImageNameText, title.getWikiSite()), new ImageLicenseFetchClient.Callback() {
@Override
public void success(@NonNull Call<MwQueryResponse> call, @NonNull ImageLicense result) {
final Bitmap snippetBitmap = SnippetImage.getSnippetImage(fragment.getContext(), fragment.getLeadImageBitmap(), title.getDisplayText(), fragment.getPage().isMainPage() ? "" : StringUtils.capitalize(title.getDescription()), selectedText, result);
fragment.showBottomSheet(new PreviewDialog(fragment.getContext(), snippetBitmap, title, selectedText, funnel));
}
@Override
public void failure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable caught) {
// If we failed to get license info for the lead image, just share the text
PreviewDialog.shareAsText(fragment.getContext(), title, selectedText, funnel);
L.e("Error fetching image license info for " + title.getDisplayText(), caught);
}
});
}
use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.
the class ReadingListPageInfoClient method request.
@VisibleForTesting
public Call<MwQueryResponse> request(@NonNull Service service, @NonNull List<PageTitle> titles, @NonNull final Callback cb) {
Call<MwQueryResponse> call = service.request(TextUtils.join("|", titles));
call.enqueue(new retrofit2.Callback<MwQueryResponse>() {
@Override
public void onResponse(@NonNull Call<MwQueryResponse> call, @NonNull Response<MwQueryResponse> response) {
if (response.isSuccessful()) {
if (response.body().success()) {
// noinspection ConstantConditions
cb.success(call, response.body().query().pages());
} else if (response.body().hasError()) {
// noinspection ConstantConditions
cb.failure(call, new MwException(response.body().getError()));
} else {
cb.failure(call, new IOException("An unknown error occurred."));
}
} else {
cb.failure(call, RetrofitException.httpError(response));
}
}
@Override
public void onFailure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable t) {
cb.failure(call, t);
}
});
return call;
}
Aggregations