use of org.wikipedia.dataclient.page.PageRemaining 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.PageRemaining 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