Exemple #1
0
  /*
   * get the latest version of this post
   */
  private void updatePost() {
    if (mPost == null || !mPost.isWP()) return;

    ReaderActions.UpdateResultListener resultListener =
        new ReaderActions.UpdateResultListener() {
          @Override
          public void onUpdateResult(ReaderActions.UpdateResult result) {
            switch (result) {
              case CHANGED:
                // post has changed, so get latest version
                mPost = ReaderPostTable.getPost(mBlogId, mPostId);
                mIsPostChanged = true;
                break;
              case FAILED:
                // failed to get post, so do nothing here
                return;
              default:
                // unchanged
                break;
            }

            // determine whether we need to update likes/comments
            if (mPost.numLikes != ReaderLikeTable.getNumLikesForPost(mPost)) updateLikes();
            if (mPost.numReplies != ReaderCommentTable.getNumCommentsForPost(mPost))
              updateComments();
          }
        };
    ReaderPostActions.updatePost(mPost, resultListener);
  }
Exemple #2
0
  /*
   * triggered when user chooses to like or follow
   */
  public void doPostAction(View btnAction, ReaderPostActions.PostAction action, ReaderPost post) {
    boolean isSelected = btnAction.isSelected();
    btnAction.setSelected(!isSelected);
    ReaderAniUtils.zoomAction(btnAction);

    if (!ReaderPostActions.performPostAction(this, action, post, null)) {
      btnAction.setSelected(isSelected);
      return;
    }

    // get the post again, since it has changed
    mPost = ReaderPostTable.getPost(mBlogId, mPostId);
    mIsPostChanged = true;

    // call returns before api completes, but local version of post will have been changed
    // so refresh to show those changes
    switch (action) {
      case TOGGLE_LIKE:
        refreshLikes();
        break;
      case TOGGLE_FOLLOW:
        refreshFollowed();
        break;
    }
  }
Exemple #3
0
  /*
   * get the latest likes for this post
   */
  private void updateLikes() {
    if (mPost == null || !mPost.isWP()) return;

    ReaderActions.UpdateResultListener resultListener =
        new ReaderActions.UpdateResultListener() {
          @Override
          public void onUpdateResult(ReaderActions.UpdateResult result) {
            if (result == ReaderActions.UpdateResult.CHANGED) {
              // get post again since likes have been updated
              mPost = ReaderPostTable.getPost(mBlogId, mPostId);
              refreshLikes();
            }
          }
        };
    ReaderPostActions.updateLikesForPost(mPost, resultListener);
  }