Ejemplo n.º 1
0
  public GrowthPush initialize(
      Context context, int applicationId, String secret, Environment environment, boolean debug) {

    if (this.context != null) return this;

    this.context = context;
    this.applicationId = applicationId;
    this.secret = secret;
    this.environment = environment;

    this.logger.setDebug(debug);
    Preference.getInstance().setContext(context);

    client = Preference.getInstance().fetchClient();
    if (client != null && client.getApplicationId() != applicationId) this.clearClient();

    return this;
  }
Ejemplo n.º 2
0
  private void updateClient(final String registrationId) {

    try {

      logger.info(
          String.format(
              "Updating client... (applicationId: %d, token: %s, environment: %s)",
              applicationId, registrationId, environment));
      GrowthPush.this.client.setToken(registrationId);
      GrowthPush.this.client.setEnvironment(environment);
      GrowthPush.this.client = GrowthPush.this.client.update();
      logger.info(
          String.format("Update client success (clientId: %d)", GrowthPush.this.client.getId()));

      Preference.getInstance().saveClient(GrowthPush.this.client);
      latch.countDown();

    } catch (GrowthPushException e) {
      logger.error(String.format("Updating client fail. %s", e.getMessage()));
    }
  }
Ejemplo n.º 3
0
  private void createClient(final String registrationId) {

    try {

      logger.info(
          String.format(
              "Registering client... (applicationId: %d, environment: %s)",
              applicationId, environment));
      GrowthPush.this.client = new Client(registrationId, environment).save(GrowthPush.this);
      logger.info(
          String.format(
              "Registering client success (clientId: %d)", GrowthPush.this.client.getId()));

      logger.info(
          String.format(
              "See https://growthpush.com/applications/%d/clients to check the client registration.",
              applicationId));
      Preference.getInstance().saveClient(GrowthPush.this.client);
      latch.countDown();

    } catch (GrowthPushException e) {
      logger.error(String.format("Registering client fail. %s", e.getMessage()));
    }
  }
Ejemplo n.º 4
0
  private void clearClient() {

    this.client = null;
    Preference.getInstance().deleteClient();
    Preference.getInstance().deleteTags();
  }