コード例 #1
0
    @Override
    protected CommentList doInBackground(Void... args) {
      if (!hasActivity()) return null;

      Blog blog = WordPress.getCurrentBlog();
      if (blog == null) {
        isError = true;
        return null;
      }

      // the first time this is called, make sure comments deleted on server are removed
      // from the local database
      if (!mHasCheckedDeletedComments && !isLoadingMore) {
        mHasCheckedDeletedComments = true;
        ApiHelper.removeDeletedComments(blog);
      }

      Map<String, Object> hPost = new HashMap<String, Object>();
      if (isLoadingMore) {
        int numExisting = getCommentAdapter().getCount();
        hPost.put("offset", numExisting);
        hPost.put("number", COMMENTS_PER_PAGE);
      } else {
        hPost.put("number", COMMENTS_PER_PAGE);
      }

      Object[] params = {blog.getRemoteBlogId(), blog.getUsername(), blog.getPassword(), hPost};
      try {
        return ApiHelper.refreshComments(getActivity(), blog, params);
      } catch (Exception e) {
        isError = true;
        return null;
      }
    }