Search in sources :

Example 1 with PageLead

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;
}
Also used : PageTitle(org.wikipedia.page.PageTitle) PageLead(org.wikipedia.dataclient.page.PageLead) PageRemaining(org.wikipedia.dataclient.page.PageRemaining) HashSet(java.util.HashSet)

Example 2 with PageLead

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"));
}
Also used : PageLead(org.wikipedia.dataclient.page.PageLead) Test(org.junit.Test)

Example 3 with PageLead

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);
        }
    });
}
Also used : WikipediaApp(org.wikipedia.WikipediaApp) PageTitle(org.wikipedia.page.PageTitle) PageLead(org.wikipedia.dataclient.page.PageLead)

Example 4 with PageLead

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();
}
Also used : TestLatch(org.wikipedia.testlib.TestLatch) PageLead(org.wikipedia.dataclient.page.PageLead) BasePageLeadTest(org.wikipedia.dataclient.page.BasePageLeadTest) Test(org.junit.Test)

Example 5 with PageLead

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();
}
Also used : TestLatch(org.wikipedia.testlib.TestLatch) MwMobileViewPageLead(org.wikipedia.dataclient.mwapi.page.MwMobileViewPageLead) PageLead(org.wikipedia.dataclient.page.PageLead) BasePageLeadTest(org.wikipedia.dataclient.page.BasePageLeadTest) Test(org.junit.Test)

Aggregations

PageLead (org.wikipedia.dataclient.page.PageLead)9 Test (org.junit.Test)6 PageTitle (org.wikipedia.page.PageTitle)3 BasePageLeadTest (org.wikipedia.dataclient.page.BasePageLeadTest)2 PageRemaining (org.wikipedia.dataclient.page.PageRemaining)2 TestLatch (org.wikipedia.testlib.TestLatch)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Request (okhttp3.Request)1 WikipediaApp (org.wikipedia.WikipediaApp)1 MwMobileViewPageLead (org.wikipedia.dataclient.mwapi.page.MwMobileViewPageLead)1