Search in sources :

Example 1 with WikiSite

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();
    }
}
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 WikiSite

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));
}
Also used : WikiSite(org.wikipedia.dataclient.WikiSite) Test(org.junit.Test)

Example 3 with WikiSite

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;
}
Also used : BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) FeedConfigureFunnel(org.wikipedia.analytics.FeedConfigureFunnel) WikiSite(org.wikipedia.dataclient.WikiSite)

Example 4 with WikiSite

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));
}
Also used : PageProperties(org.wikipedia.page.PageProperties) PageTitle(org.wikipedia.page.PageTitle) Page(org.wikipedia.page.Page) WikiSite(org.wikipedia.dataclient.WikiSite) Test(org.junit.Test) MockRetrofitTest(org.wikipedia.test.MockRetrofitTest)

Example 5 with WikiSite

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));
}
Also used : PageProperties(org.wikipedia.page.PageProperties) PageTitle(org.wikipedia.page.PageTitle) Page(org.wikipedia.page.Page) WikiSite(org.wikipedia.dataclient.WikiSite) Test(org.junit.Test) MockRetrofitTest(org.wikipedia.test.MockRetrofitTest)

Aggregations

WikiSite (org.wikipedia.dataclient.WikiSite)46 Test (org.junit.Test)23 PageTitle (org.wikipedia.page.PageTitle)13 ArrayList (java.util.ArrayList)7 HistoryEntry (org.wikipedia.history.HistoryEntry)6 List (java.util.List)5 SuppressLint (android.annotation.SuppressLint)4 NonNull (android.support.annotation.NonNull)4 View (android.view.View)4 Date (java.util.Date)4 Uri (android.net.Uri)3 HashMap (java.util.HashMap)3 PageProperties (org.wikipedia.page.PageProperties)3 Context (android.content.Context)2 Bundle (android.os.Bundle)2 RecyclerView (android.support.v7.widget.RecyclerView)2 BindView (butterknife.BindView)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 JSONException (org.json.JSONException)2