/* * changes the like on the passed post */ private void togglePostLike() { if (!isAdded() || !hasPost() || !NetworkUtils.checkConnection(getActivity())) { return; } boolean isAskingToLike = !mPost.isLikedByCurrentUser; ReaderIconCountView likeCount = (ReaderIconCountView) getView().findViewById(R.id.count_likes); likeCount.setSelected(isAskingToLike); ReaderAnim.animateLikeButton(likeCount.getImageView(), isAskingToLike); if (!ReaderPostActions.performLikeAction(mPost, isAskingToLike)) { likeCount.setSelected(!isAskingToLike); return; } // get the post again since it has changed, then refresh to show changes mPost = ReaderPostTable.getPost(mBlogId, mPostId, false); refreshLikes(); refreshIconCounts(); if (isAskingToLike) { AnalyticsUtils.trackWithBlogDetails(AnalyticsTracker.Stat.READER_ARTICLE_LIKED, mBlogId); } else { AnalyticsUtils.trackWithBlogDetails(AnalyticsTracker.Stat.READER_ARTICLE_UNLIKED, mBlogId); } }
private void refreshIconCounts() { if (!isAdded() || !hasPost() || !canShowFooter()) { return; } final ReaderIconCountView countLikes = (ReaderIconCountView) getView().findViewById(R.id.count_likes); final ReaderIconCountView countComments = (ReaderIconCountView) getView().findViewById(R.id.count_comments); if (canShowCommentCount()) { countComments.setCount(mPost.numReplies); countComments.setVisibility(View.VISIBLE); countComments.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ReaderActivityLauncher.showReaderComments(getActivity(), mPost.blogId, mPost.postId); } }); } else { countComments.setVisibility(View.INVISIBLE); countComments.setOnClickListener(null); } if (canShowLikeCount()) { countLikes.setCount(mPost.numLikes); countLikes.setVisibility(View.VISIBLE); countLikes.setSelected(mPost.isLikedByCurrentUser); if (mIsLoggedOutReader) { countLikes.setEnabled(false); } else if (mPost.canLikePost()) { countLikes.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { togglePostLike(); } }); } // if we know refreshLikes() is going to show the liking users, force liking user // views to take up space right now if (mPost.numLikes > 0 && mLikingUsersView.getVisibility() == View.GONE) { mLikingUsersView.setVisibility(View.INVISIBLE); mLikingUsersDivider.setVisibility(View.INVISIBLE); } } else { countLikes.setVisibility(View.INVISIBLE); countLikes.setOnClickListener(null); } }