use of org.wikipedia.dataclient.page.PageLead in project apps-android-wikipedia by wikimedia.
the class SavedPageSyncService method savePageFor.
private long savePageFor(@NonNull ReadingListPage page) throws IOException, InterruptedException {
PageTitle pageTitle = ReadingListPage.toPageTitle(page);
long totalSize = 0;
Call<PageLead> leadCall = reqPageLead(CacheControl.FORCE_NETWORK, OfflineCacheInterceptor.SAVE_HEADER_SAVE, pageTitle);
Call<PageRemaining> sectionsCall = reqPageSections(CacheControl.FORCE_NETWORK, OfflineCacheInterceptor.SAVE_HEADER_SAVE, pageTitle);
retrofit2.Response<PageLead> leadRsp = leadCall.execute();
totalSize += responseSize(leadRsp);
retrofit2.Response<PageRemaining> sectionsRsp = sectionsCall.execute();
totalSize += responseSize(sectionsRsp);
Set<String> imageUrls = new HashSet<>(pageImageUrlParser.parse(leadRsp.body()));
imageUrls.addAll(pageImageUrlParser.parse(sectionsRsp.body()));
if (!TextUtils.isEmpty(leadRsp.body().getThumbUrl())) {
page.thumbUrl(UriUtil.resolveProtocolRelativeUrl(pageTitle.getWikiSite(), leadRsp.body().getThumbUrl()));
persistPageThumbnail(pageTitle, page.thumbUrl());
imageUrls.add(page.thumbUrl());
}
page.description(leadRsp.body().getDescription());
if (Prefs.isImageDownloadEnabled()) {
totalSize += reqSaveImages(pageTitle.getWikiSite(), imageUrls);
}
String title = pageTitle.getPrefixedText();
L.i("Saved page " + title + " (" + totalSize + ")");
return totalSize;
}
use of org.wikipedia.dataclient.page.PageLead in project apps-android-wikipedia by wikimedia.
the class PageImageUrlParserTest method testParseLeadPronunciation.
@Test
public void testParseLeadPronunciation() {
PageLead lead = mock(PageLead.class);
when(lead.getTitlePronunciationUrl()).thenReturn("url");
when(lead.getLeadSectionContent()).thenReturn("");
assertThat(subject.parse(lead, 0), contains("url"));
}
use of org.wikipedia.dataclient.page.PageLead in project apps-android-wikipedia by wikimedia.
the class WidgetProviderFeaturedPage method getMainPageLead.
private void getMainPageLead(final Callback cb) {
WikipediaApp app = WikipediaApp.getInstance();
final PageTitle title = new PageTitle(MainPageNameData.valueFor(app.getAppOrSystemLanguageCode()), app.getWikiSite());
getApiService(title).lead(null, null, title.getPrefixedText(), DimenUtil.calculateLeadImageWidth()).enqueue(new retrofit2.Callback<PageLead>() {
@Override
public void onResponse(Call<PageLead> call, Response<PageLead> rsp) {
PageLead lead = rsp.body();
if (lead.hasError()) {
lead.logError("Error while updating widget");
return;
}
L.d("Downloaded page " + title.getDisplayText());
String titleText = findFeaturedArticleTitle(lead.getLeadSectionContent());
cb.onFeaturedArticleReceived(titleText);
}
@Override
public void onFailure(Call<PageLead> call, Throwable t) {
L.e(t);
}
});
}
use of org.wikipedia.dataclient.page.PageLead in project apps-android-wikipedia by wikimedia.
the class MwMobileViewPageLeadTest method testThumbUrls.
@Test
@SuppressWarnings("checkstyle:magicnumber")
public void testThumbUrls() throws Throwable {
enqueueFromFile("page_lead_mw.json");
final TestLatch latch = new TestLatch();
subject.lead(CacheControl.FORCE_NETWORK, null, "foo", 640).enqueue(new Callback<PageLead>() {
@Override
public void onResponse(@NonNull Call<PageLead> call, @NonNull Response<PageLead> response) {
assertThat(response.body().getLeadImageUrl(640).contains("640px"), is(true));
assertThat(response.body().getThumbUrl().contains(preferredThumbSizeString()), is(true));
assertThat(response.body().getDescription(), is("Mexican boxer"));
latch.countDown();
}
@Override
public void onFailure(@NonNull Call<PageLead> call, @NonNull Throwable t) {
fail();
latch.countDown();
}
});
latch.await();
}
use of org.wikipedia.dataclient.page.PageLead in project apps-android-wikipedia by wikimedia.
the class RbPageLeadTest method testThumbUrls.
@Test
@SuppressWarnings("checkstyle:magicnumber")
public void testThumbUrls() throws Throwable {
enqueueFromFile("page_lead_rb.json");
final TestLatch latch = new TestLatch();
subject.lead(CacheControl.FORCE_NETWORK, null, "foo", 640).enqueue(new Callback<PageLead>() {
@Override
public void onResponse(@NonNull Call<PageLead> call, @NonNull Response<PageLead> response) {
assertThat(response.body().getLeadImageUrl(640).contains("640px"), is(true));
assertThat(response.body().getThumbUrl().contains(preferredThumbSizeString()), is(true));
assertThat(response.body().getDescription(), is("Mexican boxer"));
latch.countDown();
}
@Override
public void onFailure(@NonNull Call<PageLead> call, @NonNull Throwable t) {
fail();
latch.countDown();
}
});
latch.await();
}
Aggregations