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());
}
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"));
}
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"));
}
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) {
}
}
}
}
Aggregations