use of org.wikipedia.dataclient.WikiSite 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();
}
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class PageTitleTest method testJsonSerialization.
@Test
public void testJsonSerialization() throws Throwable {
WikiSite enwiki = WikiSite.forLanguageCode("en");
PageTitle title = new PageTitle(null, "Test title", enwiki);
assertThat(title, is(new PageTitle(title.toJSON())));
title = new PageTitle("Talk", "Test title", enwiki);
assertThat(new PageTitle(title.toJSON()), is(title));
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class ConfigureFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_feed_configure, container, false);
unbinder = ButterKnife.bind(this, view);
setupRecyclerView();
funnel = new FeedConfigureFunnel(WikipediaApp.getInstance(), WikipediaApp.getInstance().getWikiSite(), requireActivity().getIntent().getIntExtra(ConfigureActivity.INVOKE_SOURCE_EXTRA, -1));
new FeedAvailabilityClient().request(new FeedAvailabilityClient.Callback() {
@Override
public void success(@NonNull Call<FeedAvailabilityClient.FeedAvailability> call, @NonNull FeedAvailabilityClient.FeedAvailability result) {
if (!isAdded()) {
return;
}
// apply the new availability rules to our content types
FeedContentType.NEWS.getLangCodesSupported().clear();
if (isLimitedToDomains(result.news())) {
addDomainNamesAsLangCodes(FeedContentType.NEWS.getLangCodesSupported(), result.news());
}
FeedContentType.ON_THIS_DAY.getLangCodesSupported().clear();
if (isLimitedToDomains(result.onThisDay())) {
addDomainNamesAsLangCodes(FeedContentType.ON_THIS_DAY.getLangCodesSupported(), result.onThisDay());
}
FeedContentType.TRENDING_ARTICLES.getLangCodesSupported().clear();
if (isLimitedToDomains(result.mostRead())) {
addDomainNamesAsLangCodes(FeedContentType.TRENDING_ARTICLES.getLangCodesSupported(), result.mostRead());
}
FeedContentType.FEATURED_ARTICLE.getLangCodesSupported().clear();
if (isLimitedToDomains(result.featuredArticle())) {
addDomainNamesAsLangCodes(FeedContentType.FEATURED_ARTICLE.getLangCodesSupported(), result.featuredArticle());
}
FeedContentType.FEATURED_IMAGE.getLangCodesSupported().clear();
if (isLimitedToDomains(result.featuredPicture())) {
addDomainNamesAsLangCodes(FeedContentType.FEATURED_IMAGE.getLangCodesSupported(), result.featuredPicture());
}
FeedContentType.saveState();
prepareContentTypeList();
}
@Override
public void failure(@NonNull Call<FeedAvailabilityClient.FeedAvailability> call, @NonNull Throwable caught) {
if (!isAdded()) {
return;
}
prepareContentTypeList();
}
private boolean isLimitedToDomains(@NonNull List<String> domainNames) {
return !domainNames.isEmpty() && !domainNames.get(0).contains("*");
}
private void addDomainNamesAsLangCodes(@NonNull List<String> outList, @NonNull List<String> domainNames) {
for (String domainName : domainNames) {
outList.add(new WikiSite(domainName).languageCode());
}
}
});
return view;
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class DescriptionEditClientTest method testIsEditAllowedSuccess.
@Test
public void testIsEditAllowedSuccess() {
WikiSite wiki = WikiSite.forLanguageCode("ru");
PageProperties props = mock(PageProperties.class);
when(props.getWikiBaseItem()).thenReturn("Q123");
when(props.canEdit()).thenReturn(true);
when(props.getDescriptionSource()).thenReturn("central");
Page page = new Page(new PageTitle("Test", wiki, null, null, props), Collections.<Section>emptyList(), props);
assertThat(DescriptionEditUtil.isEditAllowed(page), is(true));
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class DescriptionEditClientTest method testIsEditAllowedNoWikiBaseItem.
@Test
public void testIsEditAllowedNoWikiBaseItem() {
WikiSite wiki = WikiSite.forLanguageCode("ru");
PageProperties props = mock(PageProperties.class);
when(props.getWikiBaseItem()).thenReturn(null);
Page page = new Page(new PageTitle("Test", wiki, null, null, props), Collections.<Section>emptyList(), props);
assertThat(DescriptionEditUtil.isEditAllowed(page), is(false));
}
Aggregations