コード例 #1
0
  public void doGetAction() {
    if (!StringUtils.isEmpty(actionId)
        && (currentAction == null || !currentAction.getId().equals(actionId))) {

      int id = Integer.parseInt(actionId);

      // TODO: this should be able to process generic actions.
      CommentUtils.getComment(
          getActivity(),
          new CommentGetListener() {
            @Override
            public void onError(SocializeException error) {
              countdown();
              showError(getContext(), error);
            }

            @Override
            public void onGet(Comment entity) {
              ActionDetailLayoutView.this.currentAction = entity;
              content.setAction(entity);
              if (entity.getUser() != null) {
                doGetUserProfile(entity.getUser().getId(), entity);
              } else if (!StringUtils.isEmpty(userId)) {
                doGetUserProfile(Long.parseLong(userId), entity);
              }
            }
          },
          id);
    } else if (!StringUtils.isEmpty(userId)) {
      doGetUserProfile(Long.parseLong(userId), null);
    }
  }
コード例 #2
0
  /**
   * Returns a simple one-line address based on city and country
   *
   * @param address
   * @return
   */
  public String getSimpleLocation(Address address) {
    StringBuilder builder = new StringBuilder();
    String locality = address.getLocality();
    String countryName = address.getCountryName();

    if (!StringUtils.isEmpty(locality)) {
      builder.append(locality);
    } else if (!StringUtils.isEmpty(countryName)) {
      builder.append(countryName);
    }

    return builder.toString();
  }
コード例 #3
0
 protected void doGetUserProfile(SocializeAction action) {
   if (action != null && action.getUser() != null) {
     doGetUserProfile(action.getUser().getId(), action);
   } else if (!StringUtils.isEmpty(userId)) {
     doGetUserProfile(Long.parseLong(userId), action);
   }
 }
コード例 #4
0
  /*
   * (non-Javadoc)
   * @see com.socialize.networks.AbstractSocialNetworkSharer#doShare(android.app.Activity, com.socialize.entity.Entity, com.socialize.entity.PropagationUrlSet, java.lang.String, com.socialize.networks.SocialNetworkListener, com.socialize.api.action.ActionType)
   */
  @Override
  protected void doShare(
      Activity context,
      Entity entity,
      PropagationInfo urlSet,
      String comment,
      SocialNetworkListener listener,
      ActionType type) {

    Tweet tweet = new Tweet();

    switch (type) {
      case SHARE:
        if (StringUtils.isEmpty(comment)) comment = "Shared " + entity.getDisplayName();
        break;
      case LIKE:
        comment = "\u2764 likes " + entity.getDisplayName();
        break;
      case VIEW:
        comment = "Viewed " + entity.getDisplayName();
        break;
    }

    StringBuilder status = new StringBuilder();

    if (StringUtils.isEmpty(comment)) {
      status.append(entity.getDisplayName());
    } else {
      status.append(comment);
    }

    status.append(", ");
    status.append(urlSet.getEntityUrl());

    tweet.setText(status.toString());

    UserSettings settings = UserUtils.getUserSettings(context);

    if (settings != null && settings.isLocationEnabled()) {
      tweet.setLocation(LocationUtils.getLastKnownLocation(context));
      tweet.setShareLocation(true);
    }

    TwitterUtils.tweet(context, tweet, listener);
  }
コード例 #5
0
  @SuppressWarnings("deprecation")
  public boolean validateSessionAuthDataLegacy(SocializeSession loaded, AuthProviderData data) {

    if (data.getAuthProviderType().equals(AuthProviderType.SOCIALIZE)) {
      return true;
    }

    if (data.getAuthProviderType() != null && !StringUtils.isEmpty(data.getAppId3rdParty())) {
      AuthProviderType loadedAuthProviderType = loaded.getAuthProviderType();
      String loadedAppId3rdParty = loaded.get3rdPartyAppId();

      if (loadedAuthProviderType != null
          && !StringUtils.isEmpty(loadedAppId3rdParty)
          && loadedAuthProviderType.equals(data.getAuthProviderType())
          && loadedAppId3rdParty.equals(data.getAppId3rdParty())) {
        return true;
      }
    }

    return false;
  }
コード例 #6
0
  public void setUserDetails(User user, SocializeAction action) {

    String profilePicData = user.getSmallImageUri();
    final ImageView userIcon = content.getProfilePicture();

    if (!StringUtils.isEmpty(profilePicData)) {
      userIcon.getBackground().setAlpha(64);

      imageLoader.loadImageByUrl(
          profilePicData,
          new ImageLoadListener() {
            @Override
            public void onImageLoadFail(ImageLoadRequest request, Exception error) {
              Log.e(SocializeLogger.LOG_TAG, error.getMessage(), error);
              userIcon.post(
                  new Runnable() {
                    public void run() {
                      userIcon.setImageDrawable(defaultProfilePicture);
                      userIcon.getBackground().setAlpha(255);
                    }
                  });
            }

            @Override
            public void onImageLoad(ImageLoadRequest request, final SafeBitmapDrawable drawable) {
              // Must be run on UI thread
              userIcon.post(
                  new Runnable() {
                    public void run() {
                      drawable.setAlpha(255);
                      userIcon.setImageDrawable(drawable);
                      userIcon.getBackground().setAlpha(255);
                    }
                  });
            }
          });
    } else {
      userIcon.setImageDrawable(defaultProfilePicture);
      userIcon.getBackground().setAlpha(255);
    }

    content.getDisplayName().setText(user.getDisplayName());
    content.loadUserActivity(user, action);
  }
コード例 #7
0
  @Override
  public void post(
      Activity parent,
      Entity entity,
      String message,
      PropagationInfo propInfo,
      SocialNetworkListener listener) {

    String caption = "Download the app now to join the conversation.";
    String linkName = appUtils.getAppName();
    String link = propInfo.getAppUrl();
    String appId = getSocialize().getConfig().getProperty(SocializeConfig.FACEBOOK_APP_ID);

    if (!StringUtils.isEmpty(appId)) {
      post(parent, appId, linkName, message, link, caption, listener);
    } else {
      String msg =
          "Cannot post message to Facebook.  No app id found.  Make sure you specify facebook.app.id in socialize.properties";
      onError(parent, msg, new SocializeException(msg), listener);
    }
  }
コード例 #8
0
  @Override
  public void postPhoto(
      Activity parent, Share share, String comment, Uri photoUri, SocialNetworkListener listener) {
    PropagationInfoResponse propagationInfoResponse = share.getPropagationInfoResponse();
    PropagationInfo propInfo = propagationInfoResponse.getPropagationInfo(ShareType.FACEBOOK);

    if (propInfo != null) {
      String link = propInfo.getAppUrl();
      String appId = getSocialize().getConfig().getProperty(SocializeConfig.FACEBOOK_APP_ID);

      if (!StringUtils.isEmpty(appId)) {
        postPhoto(parent, appId, link, comment, photoUri, listener);
      } else {
        String msg =
            "Cannot post message to Facebook.  No app id found.  Make sure you specify facebook.app.id in socialize.properties";
        onError(parent, msg, new SocializeException(msg), listener);
      }
    } else {
      String msg = "Cannot post message to Facebook.  No propagation info found";
      onError(parent, msg, new SocializeException(msg), listener);
    }
  }
コード例 #9
0
  private final String prepareEndpoint(String host, String endpoint, boolean secure) {
    endpoint = endpoint.trim();

    if (StringUtils.isEmpty(host)) {
      logger.warn("The session did not have a host configured, using the config");
      host = config.getProperty(SocializeConfig.API_HOST);
    }

    if (host != null) {

      if (!host.startsWith("http")) {
        if (secure) {
          host = "https://" + host;
        } else {
          host = "http://" + host;
        }
      }

      if (!host.endsWith("/")) {
        if (!endpoint.startsWith("/")) {
          host += "/";
        }
      } else if (endpoint.startsWith("/")) {
        endpoint = endpoint.substring(1, endpoint.length());
      }

      endpoint = host + endpoint;
    } else {
      logger.error("Could not locate host property in session or config!");
    }

    if (!endpoint.endsWith("/")) {
      endpoint += "/";
    }

    return endpoint;
  }
コード例 #10
0
  private ListResult<T> doListTypeRequest(
      HttpUriRequest request, ActionType type, boolean isJSONResponse) throws SocializeException {
    List<T> results = null;
    List<ActionError> errors = null;
    HttpEntity entity = null;

    ListResult<T> result = null;

    if (!clientFactory.isDestroyed()) {

      try {
        HttpClient client = clientFactory.getClient();

        if (logger != null && logger.isDebugEnabled()) {
          logger.debug("Request: " + request.getMethod() + " " + request.getRequestLine().getUri());
        }

        HttpResponse response = executeRequest(client, request);

        if (logger != null && logger.isDebugEnabled()) {
          logger.debug("Response: " + response.getStatusLine().getStatusCode());
        }

        entity = response.getEntity();

        if (httpUtils.isHttpError(response)) {

          if (sessionPersister != null && httpUtils.isAuthError(response)) {
            sessionPersister.delete(context);
          }

          String msg = ioUtils.readSafe(entity.getContent());
          throw new SocializeApiError(httpUtils, response.getStatusLine().getStatusCode(), msg);
        } else {

          result = new ListResult<T>();

          if (isJSONResponse) {
            // Read the json just for logging
            String json = ioUtils.readSafe(entity.getContent());

            if (logger != null && logger.isDebugEnabled()) {
              logger.debug("JSON Response: " + json);
            }

            if (!StringUtils.isEmpty(json)) {
              JSONObject object = jsonParser.parseObject(json);

              if (object.has(JSON_ATTR_ERRORS) && !object.isNull(JSON_ATTR_ERRORS)) {

                JSONArray errorList = object.getJSONArray(JSON_ATTR_ERRORS);

                int length = errorList.length();

                errors = new ArrayList<ActionError>(length);

                for (int i = 0; i < length; i++) {
                  JSONObject jsonObject = errorList.getJSONObject(i);
                  ActionError error = errorFactory.fromJSON(jsonObject);
                  errors.add(error);
                }

                result.setErrors(errors);
              }

              if (object.has(JSON_ATTR_ITEMS) && !object.isNull(JSON_ATTR_ITEMS)) {
                JSONArray list = object.getJSONArray(JSON_ATTR_ITEMS);

                int length = list.length();

                results = new ArrayList<T>(length);

                for (int i = 0; i < length; i++) {
                  results.add(fromJSON(list.getJSONObject(i), type));
                }

                result.setItems(results);
              }

              if (object.has(JSON_ATTR_COUNT) && !object.isNull(JSON_ATTR_COUNT)) {
                result.setTotalCount(object.getInt(JSON_ATTR_COUNT));
              }
            }
          }
        }
      } catch (Throwable e) {
        throw SocializeException.wrap(e);
      } finally {
        closeEntity(entity);
      }

      return result;
    } else {
      if (logger != null) {
        logger.warn("Attempt to access HttpClientFactory that was already destroyed");
      }

      return null;
    }
  }
コード例 #11
0
  @Override
  public SocializeSession authenticate(
      String endpoint, String key, String secret, AuthProviderData data, String uuid)
      throws SocializeException {
    try {
      SessionLock.lock();

      WritableSession session = loadSession(endpoint, key, secret);

      if (session != null) {

        if (validateSession(session, data)) {
          return session;
        } else {
          session = setProviderCredentialsForUser(data, session);
        }
      }

      if (session == null) {
        session = sessionFactory.create(key, secret, data);
      }

      endpoint = prepareEndpoint(session, endpoint, true);

      if (!clientFactory.isDestroyed()) {

        HttpClient client = clientFactory.getClient();

        HttpEntity entity = null;

        try {
          HttpUriRequest request = requestFactory.getAuthRequest(session, endpoint, uuid, data);

          if (logger != null && logger.isDebugEnabled()) {
            logger.debug("Calling authenticate endpoint for device [" + uuid + "]");
          }

          HttpResponse response = executeRequest(client, request);

          entity = response.getEntity();

          if (httpUtils.isHttpError(response)) {

            if (sessionPersister != null && httpUtils.isAuthError(response)) {
              sessionPersister.delete(context);
            }

            String msg = ioUtils.readSafe(entity.getContent());

            throw new SocializeApiError(httpUtils, response.getStatusLine().getStatusCode(), msg);
          } else {

            JSONObject json = jsonParser.parseObject(entity.getContent());

            User user = userFactory.fromJSON(json.getJSONObject("user"));

            String oauth_token = json.getString("oauth_token");
            String oauth_token_secret = json.getString("oauth_token_secret");

            if (StringUtils.isEmpty(oauth_token)) {
              throw new SocializeException("oauth_token was empty in response from server");
            }

            if (StringUtils.isEmpty(oauth_token_secret)) {
              throw new SocializeException("oauth_token_secret was empty in response from server");
            }

            session.setConsumerToken(oauth_token);
            session.setConsumerTokenSecret(oauth_token_secret);
            session.setUser(user);

            setProviderCredentialsForUser(data, session);

            // Ensure the user credentials match the user auth data returned from the server
            verifyProviderCredentialsForUser(session, user);

            saveSession(session);
          }
        } catch (Exception e) {
          throw SocializeException.wrap(e);
        } finally {
          closeEntity(entity);
        }
      } else {
        if (logger != null) {
          logger.warn("Attempt to access HttpClientFactory that was already destroyed");
        }
      }

      return session;
    } finally {
      SessionLock.unlock();
    }
  }