Exemplo n.º 1
0
  /** Logs the given user in by writing it to SharedPreferences and setting mUser. */
  public void login(User user) {
    final SharedPreferences prefs = getSharedPreferences(PREFERENCE_FILE, Context.MODE_PRIVATE);
    Editor editor = prefs.edit();
    editor.putString(mSite.mName + AUTH_TOKEN_KEY, user.getAuthToken());
    editor.putString(mSite.mName + USERNAME_KEY, user.getUsername());
    editor.putInt(mSite.mName + USERID_KEY, user.getUserid());
    editor.commit();
    mUser = user;

    getBus().post(new LoginEvent.Login(mUser));

    setIsLoggingIn(false);

    /** Execute pending API call if one exists. */
    Intent pendingApiCall = APIService.getAndRemovePendingApiCall(this);
    if (pendingApiCall != null) {
      startService(pendingApiCall);
    }
  }