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));
}
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));
}
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));
}
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);
}
});
}
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;
}
Aggregations