Search in sources :

Example 56 with PageTitle

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) {
            }
        }
    }
}
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)

Example 57 with PageTitle

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

Example 58 with PageTitle

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);
    }
}
Also used : ArrayList(java.util.ArrayList) PageTitle(org.wikipedia.page.PageTitle) ReadingList(org.wikipedia.readinglist.database.ReadingList) ReadingListPage(org.wikipedia.readinglist.database.ReadingListPage)

Example 59 with PageTitle

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

Example 60 with PageTitle

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;
}
Also used : MwQueryPage(org.wikipedia.dataclient.mwapi.MwQueryPage) PageTitle(org.wikipedia.page.PageTitle) MwQueryResponse(org.wikipedia.dataclient.mwapi.MwQueryResponse) MwException(org.wikipedia.dataclient.mwapi.MwException) IOException(java.io.IOException) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) VisibleForTesting(android.support.annotation.VisibleForTesting)

Aggregations

PageTitle (org.wikipedia.page.PageTitle)60 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)15 WikiSite (org.wikipedia.dataclient.WikiSite)11 HistoryEntry (org.wikipedia.history.HistoryEntry)11 NonNull (android.support.annotation.NonNull)6 OnClick (butterknife.OnClick)5 ReadingListPage (org.wikipedia.readinglist.database.ReadingListPage)5 IOException (java.io.IOException)4 Date (java.util.Date)4 WikipediaApp (org.wikipedia.WikipediaApp)3 PageBackStackItem (org.wikipedia.page.PageBackStackItem)3 Tab (org.wikipedia.page.tabs.Tab)3 ProgressDialog (android.app.ProgressDialog)2 Intent (android.content.Intent)2 AssetManager (android.content.res.AssetManager)2 Configuration (android.content.res.Configuration)2 Resources (android.content.res.Resources)2 Bundle (android.os.Bundle)2 DisplayMetrics (android.util.DisplayMetrics)2