Search in sources :

Example 1 with PageClient

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

the class WiktionaryDialog method loadDefinitions.

private void loadDefinitions() {
    if (selectedText.trim().isEmpty()) {
        displayNoDefinitionsFound();
        return;
    }
    // TODO: centralize the Wiktionary domain better. Maybe a SharedPreference that defaults to
    // https://wiktionary.org.
    PageClient pageClient = PageClientFactory.create(new WikiSite(pageTitle.getWikiSite().subdomain() + WIKTIONARY_DOMAIN), Namespace.MAIN);
    if (pageClient instanceof RbPageClient) {
        ((RbPageClient) pageClient).define(addUnderscores(selectedText), definitionOnLoadCallback);
    } else {
        L.i("Wiktionary definitions require mobile content service loading!");
        displayNoDefinitionsFound();
    }
}
Also used : RbPageClient(org.wikipedia.dataclient.restbase.page.RbPageClient) RbPageClient(org.wikipedia.dataclient.restbase.page.RbPageClient) PageClient(org.wikipedia.dataclient.page.PageClient) WikiSite(org.wikipedia.dataclient.WikiSite)

Example 2 with PageClient

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

the class SavedPageSyncService method reqPageLead.

@NonNull
private Observable<retrofit2.Response<PageLead>> reqPageLead(@Nullable CacheControl cacheControl, @Nullable String saveOfflineHeader, @NonNull PageTitle pageTitle) {
    PageClient client = newPageClient(pageTitle);
    String title = pageTitle.getPrefixedText();
    int thumbnailWidth = DimenUtil.calculateLeadImageWidth();
    return client.lead(pageTitle.getWikiSite(), cacheControl, saveOfflineHeader, null, title, thumbnailWidth);
}
Also used : PageClient(org.wikipedia.dataclient.page.PageClient) SuppressLint(android.annotation.SuppressLint) NonNull(android.support.annotation.NonNull)

Example 3 with PageClient

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

the class SavedPageSyncService method reqPageSections.

@NonNull
private Observable<retrofit2.Response<PageRemaining>> reqPageSections(@Nullable CacheControl cacheControl, @Nullable String saveOfflineHeader, @NonNull PageTitle pageTitle) {
    PageClient client = newPageClient(pageTitle);
    String title = pageTitle.getPrefixedText();
    return client.sections(pageTitle.getWikiSite(), cacheControl, saveOfflineHeader, title);
}
Also used : PageClient(org.wikipedia.dataclient.page.PageClient) NonNull(android.support.annotation.NonNull)

Example 4 with PageClient

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

the class PageCacher method loadIntoCache.

@SuppressLint("CheckResult")
static void loadIntoCache(@NonNull PageTitle title) {
    L.d("Loading page into cache: " + title.getPrefixedText());
    PageClient client = PageClientFactory.create(title.getWikiSite(), title.namespace());
    Observable.zip(leadReq(client, title), remainingReq(client, title), (leadRsp, sectionsRsp) -> leadRsp).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(leadRsp -> {
        for (int i = WikipediaApp.getInstance().getTabCount() - 1; i >= 0; i--) {
            PageTitle pageTitle = WikipediaApp.getInstance().getTabList().get(i).getBackStackPositionTitle();
            if (pageTitle.equals(title)) {
                pageTitle.setThumbUrl(leadRsp.body().getThumbUrl());
                break;
            }
        }
    }, L::e);
}
Also used : PageRemaining(org.wikipedia.dataclient.page.PageRemaining) PageClient(org.wikipedia.dataclient.page.PageClient) NonNull(android.support.annotation.NonNull) Response(retrofit2.Response) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) DimenUtil.calculateLeadImageWidth(org.wikipedia.util.DimenUtil.calculateLeadImageWidth) SuppressLint(android.annotation.SuppressLint) WikipediaApp(org.wikipedia.WikipediaApp) PageClientFactory(org.wikipedia.dataclient.page.PageClientFactory) L(org.wikipedia.util.log.L) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) PageLead(org.wikipedia.dataclient.page.PageLead) L(org.wikipedia.util.log.L) PageClient(org.wikipedia.dataclient.page.PageClient) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

PageClient (org.wikipedia.dataclient.page.PageClient)4 NonNull (android.support.annotation.NonNull)3 SuppressLint (android.annotation.SuppressLint)2 Observable (io.reactivex.Observable)1 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)1 Schedulers (io.reactivex.schedulers.Schedulers)1 WikipediaApp (org.wikipedia.WikipediaApp)1 WikiSite (org.wikipedia.dataclient.WikiSite)1 PageClientFactory (org.wikipedia.dataclient.page.PageClientFactory)1 PageLead (org.wikipedia.dataclient.page.PageLead)1 PageRemaining (org.wikipedia.dataclient.page.PageRemaining)1 RbPageClient (org.wikipedia.dataclient.restbase.page.RbPageClient)1 DimenUtil.calculateLeadImageWidth (org.wikipedia.util.DimenUtil.calculateLeadImageWidth)1 L (org.wikipedia.util.log.L)1 Response (retrofit2.Response)1