Search in sources :

Example 31 with PageTitle

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

the class TabUnmarshallerTest method testUnmarshalSingle.

@Test
public void testUnmarshalSingle() {
    PageTitle page = new PageTitle("text", WikiSite.forLanguageCode("test"));
    HistoryEntry history = new HistoryEntry(page, new Date(0), HistoryEntry.SOURCE_SEARCH);
    Tab tab = new Tab();
    tab.getBackStack().add(new PageBackStackItem(page, history));
    List<Tab> tabs = singletonList(tab);
    assertThat(TabUnmarshaller.unmarshal(GsonMarshaller.marshal(tabs)), is(tabs));
}
Also used : Tab(org.wikipedia.page.tabs.Tab) PageTitle(org.wikipedia.page.PageTitle) HistoryEntry(org.wikipedia.history.HistoryEntry) PageBackStackItem(org.wikipedia.page.PageBackStackItem) Date(java.util.Date) Test(org.junit.Test)

Example 32 with PageTitle

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

the class TabUnmarshallerTest method testUnmarshalNoHistoryEntryAuthority.

// T152980
@Test(expected = RuntimeException.class)
public void testUnmarshalNoHistoryEntryAuthority() {
    PageTitle page = new PageTitle("text", WikiSite.forLanguageCode("test"));
    PageTitle prevPage = new PageTitle("text", new WikiSite("", ""));
    HistoryEntry history = new HistoryEntry(prevPage, new Date(0), HistoryEntry.SOURCE_SEARCH);
    Tab tab = new Tab();
    tab.getBackStack().add(new PageBackStackItem(page, history));
    List<Tab> tabs = singletonList(tab);
    TabUnmarshaller.unmarshal(GsonMarshaller.marshal(tabs));
}
Also used : Tab(org.wikipedia.page.tabs.Tab) PageTitle(org.wikipedia.page.PageTitle) HistoryEntry(org.wikipedia.history.HistoryEntry) WikiSite(org.wikipedia.dataclient.WikiSite) PageBackStackItem(org.wikipedia.page.PageBackStackItem) Date(java.util.Date) Test(org.junit.Test)

Example 33 with PageTitle

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

the class TabUnmarshallerTest method testUnmarshalNoPageTitleAuthority.

// T152980
@Test(expected = RuntimeException.class)
public void testUnmarshalNoPageTitleAuthority() {
    PageTitle page = new PageTitle("text", new WikiSite("", ""));
    HistoryEntry history = new HistoryEntry(page, new Date(0), HistoryEntry.SOURCE_SEARCH);
    Tab tab = new Tab();
    tab.getBackStack().add(new PageBackStackItem(page, history));
    List<Tab> tabs = singletonList(tab);
    TabUnmarshaller.unmarshal(GsonMarshaller.marshal(tabs));
}
Also used : Tab(org.wikipedia.page.tabs.Tab) PageTitle(org.wikipedia.page.PageTitle) HistoryEntry(org.wikipedia.history.HistoryEntry) WikiSite(org.wikipedia.dataclient.WikiSite) PageBackStackItem(org.wikipedia.page.PageBackStackItem) Date(java.util.Date) Test(org.junit.Test)

Example 34 with PageTitle

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

the class WidgetProviderFeaturedPage method getMainPageLead.

private void getMainPageLead(final Callback cb) {
    WikipediaApp app = WikipediaApp.getInstance();
    final PageTitle title = new PageTitle(MainPageNameData.valueFor(app.getAppOrSystemLanguageCode()), app.getWikiSite());
    getApiService(title).lead(null, null, title.getPrefixedText(), DimenUtil.calculateLeadImageWidth()).enqueue(new retrofit2.Callback<PageLead>() {

        @Override
        public void onResponse(Call<PageLead> call, Response<PageLead> rsp) {
            PageLead lead = rsp.body();
            if (lead.hasError()) {
                lead.logError("Error while updating widget");
                return;
            }
            L.d("Downloaded page " + title.getDisplayText());
            String titleText = findFeaturedArticleTitle(lead.getLeadSectionContent());
            cb.onFeaturedArticleReceived(titleText);
        }

        @Override
        public void onFailure(Call<PageLead> call, Throwable t) {
            L.e(t);
        }
    });
}
Also used : WikipediaApp(org.wikipedia.WikipediaApp) PageTitle(org.wikipedia.page.PageTitle) PageLead(org.wikipedia.dataclient.page.PageLead)

Example 35 with PageTitle

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

the class WidgetProviderFeaturedPage method findFeaturedArticleTitle.

private String findFeaturedArticleTitle(String pageLeadContent) {
    // Extract the actual link to the featured page in a hacky way (until we
    // have the correct API for it):
    // Parse the HTML, and look for the first link, which should be the
    // article of the day.
    Spanned text = StringUtil.fromHtml(pageLeadContent);
    URLSpan[] spans = text.getSpans(0, text.length(), URLSpan.class);
    String titleText = "";
    for (URLSpan span : spans) {
        if (!span.getURL().startsWith("/wiki/") || (text.getSpanEnd(span) - text.getSpanStart(span) <= 1)) {
            continue;
        }
        PageTitle title = WikipediaApp.getInstance().getWikiSite().titleForInternalLink(decodeURL(span.getURL()));
        if (!title.isFilePage() && !title.isSpecial()) {
            titleText = title.getDisplayText();
            break;
        }
    }
    return titleText;
}
Also used : PageTitle(org.wikipedia.page.PageTitle) URLSpan(android.text.style.URLSpan) Spanned(android.text.Spanned)

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