use of org.wikipedia.pageimages.PageImage 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.pageimages.PageImage in project apps-android-wikipedia by wikimedia.
the class ParcelableTest method testPageImage.
@Test
public void testPageImage() throws Throwable {
WikiSite wiki = WikiSite.forLanguageCode("en");
PageTitle title = new PageTitle("Talk", "India", wiki);
PageImage pageImage = new PageImage(title, "Testing image");
TestParcelUtil.test(pageImage);
}
use of org.wikipedia.pageimages.PageImage in project apps-android-wikipedia by wikimedia.
the class PageFragmentLoadState method pageLoadLeadSectionComplete.
private void pageLoadLeadSectionComplete(PageLead pageLead, int startSequenceNum) {
if (!fragment.isAdded() || !sequenceNumber.inSync(startSequenceNum)) {
return;
}
if (pageLead.hasError()) {
ServiceError error = pageLead.getError();
if (error != null) {
commonSectionFetchOnCatch(new MwException((MwServiceError) error), startSequenceNum);
} else {
commonSectionFetchOnCatch(new IOException(getResources().getString(R.string.error_unknown)), startSequenceNum);
}
return;
}
Page page = pageLead.toPage(model.getTitle());
model.setPage(page);
model.setTitle(page.getTitle());
editHandler.setPage(model.getPage());
if (page.getTitle().getDescription() == null) {
app.getSessionFunnel().noDescription();
}
layoutLeadImage(() -> {
if (!fragment.isAdded()) {
return;
}
fragment.callback().onPageInvalidateOptionsMenu();
pageLoadRemainingSections(sequenceNumber.get());
});
// Update our history entry, in case the Title was changed (i.e. normalized)
final HistoryEntry curEntry = model.getCurEntry();
model.setCurEntry(new HistoryEntry(model.getTitle(), curEntry.getTimestamp(), curEntry.getSource()));
// Fetch larger thumbnail URL from the network, and save it to our DB.
new PageImagesClient().request(model.getTitle().getWikiSite(), Collections.singletonList(model.getTitle()), new PageImagesClient.Callback() {
@Override
public void success(@NonNull Call<MwQueryResponse> call, @NonNull Map<PageTitle, PageImage> results) {
if (results.containsKey(model.getTitle())) {
PageImage pageImage = results.get(model.getTitle());
app.getDatabaseClient(PageImage.class).upsert(pageImage, PageImageHistoryContract.Image.SELECTION);
updateThumbnail(pageImage.getImageName());
}
}
@Override
public void failure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable caught) {
L.w(caught);
}
});
}
Aggregations