Search in sources :

Example 6 with PageLead

use of org.wikipedia.dataclient.page.PageLead in project apps-android-wikipedia by wikimedia.

the class PageImageUrlParserTest method testParseLeadEmpty.

@Test
public void testParseLeadEmpty() {
    PageLead lead = mock(PageLead.class);
    when(lead.getLeadSectionContent()).thenReturn("");
    assertThat(subject.parse(lead, 0), empty());
}
Also used : PageLead(org.wikipedia.dataclient.page.PageLead) Test(org.junit.Test)

Example 7 with PageLead

use of org.wikipedia.dataclient.page.PageLead in project apps-android-wikipedia by wikimedia.

the class PageImageUrlParserTest method testParseLeadLeadImage.

@Test
public void testParseLeadLeadImage() {
    PageLead lead = mock(PageLead.class);
    when(lead.getLeadImageUrl(anyInt())).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 8 with PageLead

use of org.wikipedia.dataclient.page.PageLead in project apps-android-wikipedia by wikimedia.

the class PageImageUrlParserTest method testParseLeadContentImages.

@Test
public void testParseLeadContentImages() {
    PageLead lead = mock(PageLead.class);
    when(lead.getLeadSectionContent()).thenReturn("<img src='url'>");
    assertThat(subject.parse(lead, 0), contains("url"));
}
Also used : PageLead(org.wikipedia.dataclient.page.PageLead) Test(org.junit.Test)

Example 9 with PageLead

use of org.wikipedia.dataclient.page.PageLead in project apps-android-wikipedia by wikimedia.

the class SavedPageSyncService method deletePageContents.

private void deletePageContents(@NonNull ReadingListPage page) {
    PageTitle pageTitle = ReadingListPage.toPageTitle(page);
    PageLead lead = null;
    Call<PageLead> leadCall = reqPageLead(CacheControl.FORCE_CACHE, OfflineCacheInterceptor.SAVE_HEADER_DELETE, pageTitle);
    try {
        lead = leadCall.execute().body();
    } catch (IOException ignore) {
    }
    if (lead != null) {
        List<String> imageUrls = pageImageUrlParser.parse(lead);
        if (!TextUtils.isEmpty(pageTitle.getThumbUrl())) {
            imageUrls.add(pageTitle.getThumbUrl());
        }
        for (String url : imageUrls) {
            try {
                Request request = makeImageRequest(pageTitle.getWikiSite(), url).addHeader(OfflineCacheInterceptor.SAVE_HEADER, OfflineCacheInterceptor.SAVE_HEADER_DELETE).build();
                OkHttpConnectionFactory.getClient().newCall(request).execute();
            } catch (IOException ignore) {
            }
        }
    }
    Call<PageRemaining> sectionsCall = reqPageSections(CacheControl.FORCE_CACHE, OfflineCacheInterceptor.SAVE_HEADER_DELETE, pageTitle);
    PageRemaining sections = null;
    try {
        sections = sectionsCall.execute().body();
    } catch (IOException ignore) {
    }
    if (sections != null) {
        for (String url : pageImageUrlParser.parse(sections)) {
            try {
                Request request = makeImageRequest(pageTitle.getWikiSite(), url).addHeader(OfflineCacheInterceptor.SAVE_HEADER, OfflineCacheInterceptor.SAVE_HEADER_DELETE).build();
                OkHttpConnectionFactory.getClient().newCall(request).execute();
            } catch (IOException ignore) {
            }
        }
    }
}
Also used : PageTitle(org.wikipedia.page.PageTitle) Request(okhttp3.Request) PageLead(org.wikipedia.dataclient.page.PageLead) IOException(java.io.IOException) PageRemaining(org.wikipedia.dataclient.page.PageRemaining)

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