Search in sources :

Example 1 with WikipediaZeroEnterEvent

use of org.wikipedia.events.WikipediaZeroEnterEvent 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)

Aggregations

Handler (android.os.Handler)1 Message (android.os.Message)1 WikiSite (org.wikipedia.dataclient.WikiSite)1 WikipediaZeroEnterEvent (org.wikipedia.events.WikipediaZeroEnterEvent)1