/**
  * The constructor.
  *
  * @param ownerIdentity
  * @param activityType
  */
 public ActivitiesRealtimeListAccessV1Alpha2(
     RestIdentity ownerIdentity, ActivityType activityType, QueryParams queryParams) {
   this.ownerIdentity = ownerIdentity;
   this.activityType = activityType;
   if (queryParams != null) {
     this.queryParams.append(queryParams.get(QueryParams.NUMBER_OF_COMMENTS_PARAM));
     this.queryParams.append(queryParams.get(QueryParams.NUMBER_OF_LIKES_PARAM));
   }
 }
  /** {@inheritDoc} */
  @Override
  public List<RestActivity> loadNewerAsList(RestActivity baseElement, int limit)
      throws SocialClientLibException {
    String requestURL = null;
    HttpResponse response = null;
    queryParams.append(QueryParams.LIMIT_PARAM.setValue(limit));
    queryParams.append(QueryParams.SINCE_ID_PARAM.setValue(baseElement.getId()));
    switch (activityType) {
      case ACTIVITY_STREAM:
        {
          requestURL =
              BASE_URL
                  + "activity_stream/"
                  + this.ownerIdentity.getId()
                  + ".json?"
                  + queryParams.buildQuery();
          break;
        }

      case ACTIVITY_FEED:
        {
          requestURL = BASE_URL + "activity_stream/feed.json?" + queryParams.buildQuery();
          break;
        }

      case CONNECTIONS_ACTIVITIES:
        {
          requestURL = BASE_URL + "activity_stream/connections.json?" + queryParams.buildQuery();
          break;
        }

      case USER_SPACE_ACTIVITIES:
        {
          requestURL = BASE_URL + "activity_stream/spaces.json?" + queryParams.buildQuery();
          break;
        }
    }
    queryParams.remove(QueryParams.LIMIT_PARAM);
    queryParams.remove(QueryParams.SINCE_ID_PARAM);

    try {
      response = executeGet(requestURL, POLICY.BASIC_AUTH);
      handleError(response);
    } catch (SocialHttpClientException e) {
      throw new ServiceException(e.getMessage(), e);
    }
    return this.getListActivitiesFromResponse(response);
  }
  @Override
  public Integer doInBackground(Boolean... params) {
    isLikeAction = params[0];

    try {
      ActivityService<RestActivity> activityService =
          SocialServiceHelper.getInstance().activityService;

      String activityId = SocialDetailHelper.getInstance().getActivityId();
      QueryParams queryParams = new QueryParamsImpl();
      queryParams.append(
          QueryParams.NUMBER_OF_LIKES_PARAM.setValue(ExoConstants.NUMBER_OF_LIKES_PARAM));
      queryParams.append(
          QueryParams.NUMBER_OF_COMMENTS_PARAM.setValue(ExoConstants.NUMBER_OF_COMMENTS_PARAM));
      queryParams.append(QueryParams.POSTER_IDENTITY_PARAM.setValue(true));
      selectedRestActivity = activityService.get(activityId, queryParams);
      SocialDetailHelper.getInstance().setLiked(false);

      streamInfo = new SocialActivityInfo();
      RestProfile restProfile = selectedRestActivity.getPosterIdentity().getProfile();
      streamInfo.setActivityId(selectedRestActivity.getId());
      streamInfo.setImageUrl(restProfile.getAvatarUrl());
      streamInfo.setUserName(restProfile.getFullName());
      streamInfo.setTitle(selectedRestActivity.getTitle());
      streamInfo.setBody(selectedRestActivity.getBody());
      streamInfo.setPostedTime(selectedRestActivity.getPostedTime());

      if (SocialActivityUtil.getPlatformVersion() >= 4.0f) {
        streamInfo.setUpdatedTime(selectedRestActivity.getLastUpdated());
      }

      streamInfo.setLikeNumber(selectedRestActivity.getTotalNumberOfLikes());
      streamInfo.setCommentNumber(selectedRestActivity.getTotalNumberOfComments());
      activityType = selectedRestActivity.getType();
      streamInfo.setType(activityType);
      streamInfo.restActivityStream = selectedRestActivity.getActivityStream();
      streamInfo.templateParams = selectedRestActivity.getTemplateParams();

      List<RestIdentity> likeList = selectedRestActivity.getAvailableLikes();
      List<RestComment> commentList = selectedRestActivity.getAvailableComments();
      if (likeList != null) {
        for (RestIdentity like : likeList) {
          RestProfile likeProfile = like.getProfile();
          SocialLikeInfo socialLike = new SocialLikeInfo();
          socialLike.likedImageUrl = likeProfile.getAvatarUrl();
          String identity = like.getId();
          if (identity.equalsIgnoreCase(SocialServiceHelper.getInstance().userIdentity)) {
            socialLike.setLikeName(youText);
            likeLinkedList.addFirst(socialLike);
            SocialDetailHelper.getInstance().setLiked(true);
          } else {
            String likeName = like.getProfile().getFullName();
            socialLike.setLikeName(likeName);
            likeLinkedList.add(socialLike);
          }
        }
      }

      if (commentList != null) {
        for (RestComment comment : commentList) {
          SocialCommentInfo socialComment = new SocialCommentInfo();
          RestIdentity restId = comment.getPosterIdentity();

          RestProfile profile = restId.getProfile();
          socialComment.setCommentId(restId.getId());
          socialComment.setCommentName(profile.getFullName());
          socialComment.setImageUrl(profile.getAvatarUrl());
          socialComment.setCommentTitle(comment.getText());
          socialComment.setPostedTime(comment.getPostedTime());

          socialCommentList.add(socialComment);
        }
      }

      return 1;
    } catch (SocialClientLibException e) {
      if (Log.LOGD)
        Log.d(getClass().getSimpleName(), "doInBackground ", Log.getStackTraceString(e));
      return 0;
    } catch (RuntimeException e) {
      if (Log.LOGD)
        Log.d(getClass().getSimpleName(), "doInBackground ", Log.getStackTraceString(e));
      return -1;
    }
  }