コード例 #1
1
 private static void fetchLikesAndUpdateUsers(Post post, Set<User> users, Page page) {
   PagedList<Reference> likes = facebook.likeOperations().getLikes(post.getId());
   int totalLikes = likes.size();
   for (Reference userLike : likes) {
     User user =
         users
             .stream()
             .filter(f -> f.getId().equals(userLike.getId()))
             .findFirst()
             .orElse(new User(userLike.getId(), userLike.getName(), page));
     user.addLike(post, page.getId());
     users.add(user);
   }
   while (likes.getNextPage() != null) {
     likes = facebook.likeOperations().getLikes(post.getId(), likes.getNextPage());
     totalLikes += likes.size();
     for (Reference userLike : likes) {
       User user =
           users
               .stream()
               .filter(f -> f.getId().equals(userLike.getId()))
               .findFirst()
               .orElse(new User(userLike.getId(), userLike.getName(), page));
       user.addLike(post, page.getId());
       users.add(user);
     }
   }
   post.getExtraData().putIfAbsent("likesCount", totalLikes);
 }
コード例 #2
0
  public View getView(int position, View convertView, ViewGroup parent) {
    Post entry = getItem(position);

    View view = convertView;

    if (view == null) {
      view = _layoutInflater.inflate(R.layout.facebook_feed_list_item, parent, false);
    }

    TextView t = (TextView) view.findViewById(R.id.from_name);
    t.setText(entry.getFrom().getName());

    t = (TextView) view.findViewById(R.id.updated_time);
    t.setText(entry.getUpdatedTime().toString());

    t = (TextView) view.findViewById(R.id.message);
    t.setText(entry.getMessage());

    return view;
  }
コード例 #3
0
  private static void fetchCommentAndUpdateUsers(
      Post post, Set<Comment> commentsToSave, Set<User> users, Page page) {
    PagedList<Comment> comments = facebook.commentOperations().getComments(post.getId());
    int totalComments = comments.size();

    for (Comment comment : comments) {

      User user =
          users
              .stream()
              .filter(f -> f.getId().equals(comment.getFrom().getId()))
              .findFirst()
              .orElse(new User(comment.getFrom().getId(), comment.getFrom().getName(), page));
      user.addComment(comment, post, page.getId());
      users.add(user);

      commentsToSave.add(comment);
      if (comment.getCommentCount() != null && comment.getCommentCount() > 0) {
        PagedList<Comment> commentsComments =
            facebook.commentOperations().getComments(comment.getId());
        for (Comment commentsComment : commentsComments) {

          user =
              users
                  .stream()
                  .filter(f -> f.getId().equals(commentsComment.getFrom().getId()))
                  .findFirst()
                  .orElse(new User(comment.getFrom().getId(), comment.getFrom().getName(), page));
          user.addComment(commentsComment, post, page.getId());
          users.add(user);
          commentsToSave.add(comment);
        }
        while (commentsComments.getNextPage() != null) {
          commentsComments =
              facebook.commentOperations().getComments(post.getId(), comments.getNextPage());
          for (Comment commentsComment : commentsComments) {
            user =
                users
                    .stream()
                    .filter(f -> f.getId().equals(commentsComment.getFrom().getId()))
                    .findFirst()
                    .orElse(new User(comment.getFrom().getId(), comment.getFrom().getName(), page));
            user.addComment(commentsComment, post, page.getId());
            users.add(user);
            commentsToSave.add(comment);
          }
        }
      }
    }
    while (comments.getNextPage() != null) {
      comments = facebook.commentOperations().getComments(post.getId(), comments.getNextPage());
      totalComments += comments.size();

      for (Comment comment : comments) {
        User user =
            users
                .stream()
                .filter(f -> f.getId().equals(comment.getFrom().getId()))
                .findFirst()
                .orElse(new User(comment.getFrom().getId(), comment.getFrom().getName(), page));
        user.addComment(comment, post, page.getId());
        users.add(user);
        commentsToSave.add(comment);
        if (comment.getCommentCount() != null && comment.getCommentCount() > 0) {
          PagedList<Comment> commentsComments =
              facebook.commentOperations().getComments(comment.getId());
          for (Comment commentsComment : commentsComments) {

            user =
                users
                    .stream()
                    .filter(f -> f.getId().equals(commentsComment.getFrom().getId()))
                    .findFirst()
                    .orElse(new User(comment.getFrom().getId(), comment.getFrom().getName(), page));
            user.addComment(commentsComment, post, page.getId());
            users.add(user);
            commentsToSave.add(comment);
          }
          while (commentsComments.getNextPage() != null) {
            commentsComments =
                facebook.commentOperations().getComments(post.getId(), comments.getNextPage());
            for (Comment commentsComment : commentsComments) {
              user =
                  users
                      .stream()
                      .filter(f -> f.getId().equals(commentsComment.getFrom().getId()))
                      .findFirst()
                      .orElse(
                          new User(comment.getFrom().getId(), comment.getFrom().getName(), page));
              user.addComment(commentsComment, post, page.getId());
              users.add(user);
              commentsToSave.add(comment);
            }
          }
        }
      }
    }
    post.getExtraData().putIfAbsent("commentsCount", totalComments);
  }