Skip to content

Instantly share code, notes, and snippets.

@secondsun
Last active December 20, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secondsun/b01c3446095fb29a85e3 to your computer and use it in GitHub Desktop.
Save secondsun/b01c3446095fb29a85e3 to your computer and use it in GitHub Desktop.
Comparing APIs before and after Registration_refactor PR
class PushApplication extends Application {
private PushRegistrar registrar;
private PushConfig config;
private final Registrations registrations = new Registrations();
private static final String VARIANT_ID = "";
private static final String SECRET = "";
private static final String GCM_SENDER_ID = "";
private static final String UNIFIED_PUSH_URL = "";
private static final String MY_ALIAS = "";
public void onCreate() {
super.onCreate();
try {
config = new PushConfig(new URL(UNIFIED_PUSH_URL), GCM_SENDER_ID);
config.setVariantID(VARIANT_ID);
config.setSecret(SECRET);
config.setAlias(MY_ALIAS);
registrar = registrations.push("registrar", config);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
public void register() {
registrar.register(getApplicationContext(), new MyCallback<Void>());
}
public void unregister() {
registrar.unregister(getApplicationContext(), new MyCallback<Void>());
}
}
class PushApplication extends Application {
private Registrar registrar;
private PushConfig config;
private static final String VARIANT_ID = "";
private static final String SECRET = "";
private static final String GCM_SENDER_ID = "";
private static final String UNIFIED_PUSH_URL = "";
private static final String MY_ALIAS = "";
@Override
public void onCreate() {
super.onCreate();
try {
final Registrar r = new Registrar(new URL(UNIFIED_PUSH_URL));
PushConfig config = new PushConfig(GCM_SENDER_ID);
config.setVariantID(VARIANT_ID);
config.setSecret(SECRET);
config.setAlias(MY_ALIAS);
r.register(getApplicationContext(), config, new Callback<Void>() {
private static final long serialVersionUID = 1L;
@Override
public void onSuccess(Void ignore) {
registrar = r;
}
@Override
public void onFailure(Exception exception) {
Log.e(TAG, exception.getMessage(), exception);
}
});
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment