Search in sources :

Example 1 with UtcDate

use of org.wikipedia.feed.model.UtcDate in project apps-android-wikipedia by wikimedia.

the class AggregatedFeedContentClient method requestAggregated.

void requestAggregated(@NonNull WikiSite wiki, int age, @NonNull retrofit2.Callback<AggregatedFeedContent> cb) {
    cancel();
    UtcDate date = DateUtil.getUtcRequestDateFor(age);
    String endpoint = String.format(Locale.ROOT, Prefs.getRestbaseUriFormat(), wiki.scheme(), wiki.authority());
    Retrofit retrofit = RetrofitFactory.newInstance(endpoint, wiki);
    AggregatedFeedContentClient.Service service = retrofit.create(Service.class);
    call = service.get(date.year(), date.month(), date.date());
    call.enqueue(cb);
}
Also used : Retrofit(retrofit2.Retrofit) UtcDate(org.wikipedia.feed.model.UtcDate)

Example 2 with UtcDate

use of org.wikipedia.feed.model.UtcDate in project apps-android-wikipedia by wikimedia.

the class WidgetProviderFeaturedPage method getFeaturedArticleInformation.

@SuppressLint("CheckResult")
private void getFeaturedArticleInformation(final Callback cb) {
    WikipediaApp app = WikipediaApp.getInstance();
    final PageTitle mainPageTitle = new PageTitle(MainPageNameData.valueFor(app.getAppOrSystemLanguageCode()), app.getWikiSite());
    UtcDate date = DateUtil.getUtcRequestDateFor(0);
    ServiceFactory.getRest(WikipediaApp.getInstance().getWikiSite()).getAggregatedFeed(date.year(), date.month(), date.date()).flatMap(response -> {
        if (response.tfa() != null) {
            return Observable.just(response.tfa());
        } else {
            // TODO: this logic can be removed if the feed API can return the featured article for all languages.
            return getApiService(mainPageTitle).lead(mainPageTitle.getWikiSite(), null, null, null, mainPageTitle.getPrefixedText(), DimenUtil.calculateLeadImageWidth());
        }
    }).subscribeOn(Schedulers.io()).subscribe(response -> {
        CharSequence widgetText = mainPageTitle.getText();
        PageTitle pageTitle = mainPageTitle;
        if (response instanceof retrofit2.Response) {
            PageLead lead = (PageLead) ((retrofit2.Response) response).body();
            L.d("Downloaded page " + mainPageTitle.getDisplayText());
            widgetText = findFeaturedArticleTitle(lead.getLeadSectionContent());
        } else if (response instanceof RbPageSummary) {
            widgetText = StringUtil.fromHtml(((RbPageSummary) response).getDisplayTitle());
            pageTitle = ((RbPageSummary) response).getPageTitle(app.getWikiSite());
        }
        cb.onFeaturedArticleReceived(pageTitle, widgetText);
    }, L::e);
}
Also used : RbPageSummary(org.wikipedia.dataclient.restbase.page.RbPageSummary) UtcDate(org.wikipedia.feed.model.UtcDate) WikipediaApp(org.wikipedia.WikipediaApp) PageTitle(org.wikipedia.page.PageTitle) PageLead(org.wikipedia.dataclient.page.PageLead) UriUtil.decodeURL(org.wikipedia.util.UriUtil.decodeURL) L(org.wikipedia.util.log.L) SuppressLint(android.annotation.SuppressLint)

Aggregations

UtcDate (org.wikipedia.feed.model.UtcDate)2 SuppressLint (android.annotation.SuppressLint)1 WikipediaApp (org.wikipedia.WikipediaApp)1 PageLead (org.wikipedia.dataclient.page.PageLead)1 RbPageSummary (org.wikipedia.dataclient.restbase.page.RbPageSummary)1 PageTitle (org.wikipedia.page.PageTitle)1 UriUtil.decodeURL (org.wikipedia.util.UriUtil.decodeURL)1 L (org.wikipedia.util.log.L)1 Retrofit (retrofit2.Retrofit)1