/** {@inheritDoc} */
  @Override
  public void login(
      final Activity parentActivity, final AuthCallbacks.LoginListener loginListener) {
    if (!isInitialized) {
      SoomlaUtils.LogError(
          TAG, "Consumer key and secret were not defined, please provide them in initialization");
      return;
    }

    SoomlaUtils.LogDebug(TAG, "login");
    WeakRefParentActivity = new WeakReference<Activity>(parentActivity);

    RefProvider = getProvider();
    RefLoginListener = loginListener;

    preformingAction = ACTION_LOGIN;

    mainRequestToken = null;
    twitter.setOAuthAccessToken(null);

    // Try logging in using store credentials
    String oauthToken = KeyValueStorage.getValue(getTwitterStorageKey(TWITTER_OAUTH_TOKEN));
    String oauthTokenSecret = KeyValueStorage.getValue(getTwitterStorageKey(TWITTER_OAUTH_SECRET));
    if (!TextUtils.isEmpty(oauthToken) && !TextUtils.isEmpty(oauthTokenSecret)) {
      twitter.setOAuthAccessToken(new AccessToken(oauthToken, oauthTokenSecret));
      twitterScreenName = KeyValueStorage.getValue(getTwitterStorageKey(TWITTER_SCREEN_NAME));

      loginListener.success(RefProvider);

      clearListener(ACTION_LOGIN);
    } else {
      // If no stored credentials start login process by requesting
      // a request token
      twitter.getOAuthRequestTokenAsync(oauthCallbackURL);
    }
  }
Beispiel #2
0
  public static JSONObject getLevelUpModel() {
    JSONObject modelJSON = null;

    String model = KeyValueStorage.getValue(DB_KEY_PREFIX + "model");
    SoomlaUtils.LogDebug(TAG, "model: " + model);
    if (model == null) {
      return null;
    }

    try {
      modelJSON = new JSONObject(model);
    } catch (JSONException e) {
      SoomlaUtils.LogError(TAG, "Unable to parse LevelUp model into JSON");
    }

    return modelJSON;
  }