示例#1
0
  public OperationResult<Card> getDefaultCard(User user) {
    OperationResult<Card> result = new OperationResult<>();

    try {
      result.type = OperationResult.ResultType.SUCCESS;
      result.error = null;

      result.result = this.mSharedPreferencesRepository.get(STORE_KEY_DEFAULT_CARD, Card.class);
      if (result.result == null && user != null && user.cards != null && user.cards.size() > 0) {
        result.result = user.cards.get(0);
        this.setDefaultCard(result.result);
      }
    } catch (Exception ex) {
      result.error = new OperationError();
      result.error.code = OperationError.ERROR_CODE_UNKNOWN;
      result.error.message = ex.toString();
      result.type = OperationResult.ResultType.ERROR;
    }

    return result;
  }
示例#2
0
  public OperationResult<User> getLoggedUser() {
    OperationResult<User> result = new OperationResult<User>();

    try {
      result.result = this.mSharedPreferencesRepository.get(STORE_KEY_LOGGED, User.class);
      if (result.result == null) {
        result.type = OperationResult.ResultType.ERROR;
        result.error = new OperationError();
        result.error.code = OperationError.ERROR_NOT_AUTHORIZED;
        result.error.message = "Not logged";
      } else {
        result.type = OperationResult.ResultType.SUCCESS;
      }
    } catch (Exception ex) {
      result.error = new OperationError();
      result.error.code = OperationError.ERROR_CODE_UNKNOWN;
      result.error.message = ex.toString();
      result.type = OperationResult.ResultType.ERROR;
    }

    return result;
  }
示例#3
0
  public OperationResult<Card> setDefaultCard(Card card) {
    OperationResult<Card> result = new OperationResult<Card>();
    try {
      mSharedPreferencesRepository.insertOrUpdate(STORE_KEY_DEFAULT_CARD, card);
      result.type = OperationResult.ResultType.SUCCESS;
      result.result = card;
    } catch (Exception ex) {
      result.error = new OperationError();
      result.error.code = OperationError.ERROR_CODE_UNKNOWN;
      result.error.message = ex.toString();
      result.type = OperationResult.ResultType.ERROR;
    }

    return result;
  }
示例#4
0
  public OperationResult<Void> logout() {
    OperationResult<Void> result = new OperationResult<Void>();

    try {
      this.mSharedPreferencesRepository.delete(STORE_KEY_LOGGED);
      result.type = OperationResult.ResultType.SUCCESS;
    } catch (Exception ex) {
      result.error = new OperationError();
      result.error.code = OperationError.ERROR_CODE_UNKNOWN;
      result.error.message = ex.toString();
      result.type = OperationResult.ResultType.ERROR;
    }

    return result;
  }