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