Search in sources :

Example 16 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class WikipediaZeroHandler method identifyZeroCarrier.

private void identifyZeroCarrier(@NonNull final String xCarrierFromHeader, @NonNull final String xCarrierMetaFromHeader) {
    Handler wikipediaZeroHandler = new Handler((Message msg) -> {
        new ZeroConfigClient().request(new WikiSite(app.getWikiSite().mobileAuthority()), app.getUserAgent(), new ZeroConfigClient.Callback() {

            @Override
            public void success(@NonNull Call<ZeroConfig> call, @NonNull ZeroConfig config) {
                L.i("New Wikipedia Zero config: " + config);
                if (!config.isEligible()) {
                    acquiringCarrierMessage = false;
                    return;
                }
                // ex. "123-45"
                xCarrier = xCarrierFromHeader;
                zeroCarrierString = xCarrierFromHeader;
                // ex. "wap"; default ""
                zeroCarrierMetaString = xCarrierMetaFromHeader;
                zeroConfig = config;
                zeroEnabled = true;
                app.getBus().post(new WikipediaZeroEnterEvent());
                if (zeroConfig.hashCode() != Prefs.zeroConfigHashCode()) {
                    notifyEnterZeroNetwork(app, zeroConfig);
                }
                Prefs.zeroConfigHashCode(zeroConfig.hashCode());
                acquiringCarrierMessage = false;
            }

            @Override
            public void failure(@NonNull Call<ZeroConfig> call, @NonNull Throwable caught) {
                L.w("Wikipedia Zero eligibility check failed", caught);
                acquiringCarrierMessage = false;
            }
        });
        acquiringCarrierMessage = true;
        return true;
    });
    wikipediaZeroHandler.removeMessages(MESSAGE_ZERO_CS);
    Message zeroMessage = Message.obtain();
    zeroMessage.what = MESSAGE_ZERO_CS;
    zeroMessage.obj = "zero_eligible_check";
    wikipediaZeroHandler.sendMessage(zeroMessage);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) WikipediaZeroEnterEvent(org.wikipedia.events.WikipediaZeroEnterEvent) WikiSite(org.wikipedia.dataclient.WikiSite)

Example 17 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class WikiSiteTypeAdapterTest method testReadLegacyUriLang.

@Test
public void testReadLegacyUriLang() {
    String json = "{\"domain\": \"test.wikipedia.org\"}";
    WikiSite expected = WikiSite.forLanguageCode("test");
    assertThat(unmarshal(WikiSite.class, json), is(expected));
}
Also used : WikiSite(org.wikipedia.dataclient.WikiSite) Test(org.junit.Test)

Example 18 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class WikiSiteTypeAdapterTest method testReadLegacyLang.

@Test
public void testReadLegacyLang() {
    String json = "{\"domain\": \"https://test.wikipedia.org\"}";
    WikiSite expected = WikiSite.forLanguageCode("test");
    assertThat(unmarshal(WikiSite.class, json), is(expected));
}
Also used : WikiSite(org.wikipedia.dataclient.WikiSite) Test(org.junit.Test)

Example 19 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class WikiSiteTypeAdapterTest method testReadLegacyUri.

@Test
public void testReadLegacyUri() {
    String json = "{\"domain\": \"test.wikipedia.org\", \"languageCode\": \"test\"}";
    WikiSite expected = WikiSite.forLanguageCode("test");
    assertThat(unmarshal(WikiSite.class, json), is(expected));
}
Also used : WikiSite(org.wikipedia.dataclient.WikiSite) Test(org.junit.Test)

Example 20 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class PageTitleTest method testIsMainPageProps.

@Test
public void testIsMainPageProps() throws Throwable {
    String text = "text";
    WikiSite wiki = WikiSite.forLanguageCode("test");
    final String thumbUrl = null;
    final String desc = null;
    PageProperties props = mock(PageProperties.class);
    when(props.isMainPage()).thenReturn(true);
    PageTitle subject = new PageTitle(text, wiki, thumbUrl, desc, props);
    assertThat(subject.isMainPage(), is(true));
}
Also used : WikiSite(org.wikipedia.dataclient.WikiSite) Test(org.junit.Test)

Aggregations

WikiSite (org.wikipedia.dataclient.WikiSite)35 Test (org.junit.Test)22 PageTitle (org.wikipedia.page.PageTitle)11 HistoryEntry (org.wikipedia.history.HistoryEntry)5 Date (java.util.Date)4 Uri (android.net.Uri)3 Bundle (android.os.Bundle)2 View (android.view.View)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Page (org.wikipedia.page.Page)2 PageBackStackItem (org.wikipedia.page.PageBackStackItem)2 PageProperties (org.wikipedia.page.PageProperties)2 Tab (org.wikipedia.page.tabs.Tab)2 MockWebServerTest (org.wikipedia.test.MockWebServerTest)2 ProgressDialog (android.app.ProgressDialog)1 AssetManager (android.content.res.AssetManager)1 Configuration (android.content.res.Configuration)1 Resources (android.content.res.Resources)1