use of org.wikipedia.page.PageTitle 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) {
}
}
}
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class SearchResultsFragment method onItemClick.
@OnItemClick(R.id.search_results_list)
void onItemClick(ListView view, int position) {
Callback callback = callback();
if (callback != null) {
PageTitle item = ((SearchResult) getAdapter().getItem(position)).getPageTitle();
callback.navigateToTitle(item, false, position);
}
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class DeveloperSettingsPreferenceLoader method createTestReadingList.
private void createTestReadingList(String listName, int numOfLists, int numOfArticles) {
int index = 0;
List<ReadingList> lists = ReadingListDbHelper.instance().getAllListsWithoutContents();
for (int i = lists.size() - 1; i >= 0; i--) {
ReadingList lastReadingList = lists.get(i);
if (lastReadingList.title().contains(listName)) {
String trimmedListTitle = lastReadingList.title().substring(listName.length()).trim();
index = (trimmedListTitle.isEmpty()) ? index : (Integer.valueOf(trimmedListTitle) > index ? Integer.valueOf(trimmedListTitle) : index);
break;
}
}
for (int i = 0; i < numOfLists; i++) {
index += 1;
ReadingList list = ReadingListDbHelper.instance().createList(listName + " " + index, "");
List<ReadingListPage> pages = new ArrayList<>();
for (int j = 0; j < numOfArticles; j++) {
PageTitle pageTitle = new PageTitle("" + (j + 1), WikipediaApp.getInstance().getWikiSite());
pages.add(new ReadingListPage(pageTitle));
}
ReadingListDbHelper.instance().addPagesToList(list, pages, true);
}
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class PageImageDatabaseTable method fromCursor.
@Override
public PageImage fromCursor(Cursor cursor) {
WikiSite wiki = new WikiSite(Col.SITE.val(cursor), Col.LANG.val(cursor));
PageTitle title = new PageTitle(Col.NAMESPACE.val(cursor), Col.TITLE.val(cursor), wiki);
String imageName = Col.IMAGE_NAME.val(cursor);
return new PageImage(title, imageName);
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class PageImagesClient method request.
@VisibleForTesting
Call<MwQueryResponse> request(@NonNull final WikiSite wiki, @NonNull Service service, @NonNull final List<PageTitle> titles, @NonNull final Callback cb) {
Call<MwQueryResponse> call = service.request(TextUtils.join("|", titles));
call.enqueue(new retrofit2.Callback<MwQueryResponse>() {
@Override
public void onResponse(@NonNull Call<MwQueryResponse> call, @NonNull Response<MwQueryResponse> response) {
Map<PageTitle, PageImage> pageImagesMap = new ArrayMap<>();
// error cases
if (response.body().success()) {
// nominal case
Map<String, PageTitle> titlesMap = new ArrayMap<>();
for (PageTitle title : titles) {
titlesMap.put(title.getPrefixedText(), title);
}
Map<String, String> thumbnailSourcesMap = new ArrayMap<>();
// noinspection ConstantConditions
for (MwQueryPage page : response.body().query().pages()) {
thumbnailSourcesMap.put(new PageTitle(null, page.title(), wiki).getPrefixedText(), page.thumbUrl());
if (!TextUtils.isEmpty(page.convertedFrom())) {
thumbnailSourcesMap.put(new PageTitle(null, page.convertedFrom(), wiki).getPrefixedText(), page.thumbUrl());
}
if (!TextUtils.isEmpty(page.redirectFrom())) {
thumbnailSourcesMap.put(new PageTitle(null, page.redirectFrom(), wiki).getPrefixedText(), page.thumbUrl());
}
}
for (String key : titlesMap.keySet()) {
if (thumbnailSourcesMap.containsKey(key)) {
PageTitle title = titlesMap.get(key);
pageImagesMap.put(title, new PageImage(title, thumbnailSourcesMap.get(key)));
}
}
cb.success(call, pageImagesMap);
} else if (response.body().hasError()) {
// noinspection ConstantConditions
cb.failure(call, new MwException(response.body().getError()));
} else {
cb.failure(call, new IOException("An unknown error occurred."));
}
}
@Override
public void onFailure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable t) {
cb.failure(call, t);
}
});
return call;
}
Aggregations