コード例 #1
0
  /** similar to updatePost, but used when post doesn't already exist in local db */
  public static void requestPost(
      final long blogId, final long postId, final ActionListener actionListener) {
    String path = "read/sites/" + blogId + "/posts/" + postId + "/?meta=site,likes";

    com.wordpress.rest.RestRequest.Listener listener =
        new RestRequest.Listener() {
          @Override
          public void onResponse(JSONObject jsonObject) {
            ReaderPost post = ReaderPost.fromJson(jsonObject);
            ReaderPostTable.addOrUpdatePost(post);
            handlePostLikes(post, jsonObject);
            if (actionListener != null) {
              actionListener.onActionResult(true);
            }
          }
        };
    RestRequest.ErrorListener errorListener =
        new RestRequest.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(T.READER, volleyError);
            if (actionListener != null) {
              actionListener.onActionResult(false);
            }
          }
        };
    AppLog.d(T.READER, "requesting post");
    WordPress.getRestClientUtilsV1_2().get(path, null, null, listener, errorListener);
  }
コード例 #2
0
  /*
   * get the latest version of this post - note that the post is only considered changed if the
   * like/comment count has changed, or if the current user's like/follow status has changed
   */
  public static void updatePost(
      final ReaderPost originalPost, final UpdateResultListener resultListener) {
    String path =
        "read/sites/" + originalPost.blogId + "/posts/" + originalPost.postId + "/?meta=site,likes";

    com.wordpress.rest.RestRequest.Listener listener =
        new RestRequest.Listener() {
          @Override
          public void onResponse(JSONObject jsonObject) {
            handleUpdatePostResponse(originalPost, jsonObject, resultListener);
          }
        };
    RestRequest.ErrorListener errorListener =
        new RestRequest.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(T.READER, volleyError);
            if (resultListener != null) {
              resultListener.onUpdateResult(UpdateResult.FAILED);
            }
          }
        };
    AppLog.d(T.READER, "updating post");
    WordPress.getRestClientUtilsV1_2().get(path, null, null, listener, errorListener);
  }