/* * user tapped follow button to follow/unfollow the blog this post is from */ private void togglePostFollowed() { if (!isAdded() || !hasPost()) { return; } final boolean isAskingToFollow = !ReaderPostTable.isPostFollowed(mPost); final ReaderFollowButton followButton = (ReaderFollowButton) getView().findViewById(R.id.follow_button); ReaderActions.ActionListener listener = new ReaderActions.ActionListener() { @Override public void onActionResult(boolean succeeded) { if (!isAdded()) { return; } followButton.setEnabled(true); if (!succeeded) { int resId = (isAskingToFollow ? R.string.reader_toast_err_follow_blog : R.string.reader_toast_err_unfollow_blog); ToastUtils.showToast(getActivity(), resId); followButton.setIsFollowedAnimated(!isAskingToFollow); } } }; followButton.setEnabled(false); if (ReaderBlogActions.followBlogForPost(mPost, isAskingToFollow, listener)) { followButton.setIsFollowedAnimated(isAskingToFollow); } }
@Override protected void onPostExecute(Boolean result) { mIsPostTaskRunning = false; if (!isAdded()) { return; } if (!result) { // post couldn't be loaded which means it doesn't exist in db, so request it from // the server if it hasn't already been requested if (!mHasAlreadyRequestedPost) { mHasAlreadyRequestedPost = true; AppLog.i(T.READER, "reader post detail > post not found, requesting it"); requestPost(); } return; } if (!canShowFooter()) { mLayoutFooter.setVisibility(View.GONE); } // add padding to the scrollView to make room for the top and bottom toolbars - this also // ensures the scrollbar matches the content so it doesn't disappear behind the toolbars int topPadding = (mAutoHideToolbarListener != null ? mToolbarHeight : 0); int bottomPadding = (canShowFooter() ? mLayoutFooter.getHeight() : 0); mScrollView.setPadding(0, topPadding, 0, bottomPadding); // scrollView was hidden in onCreateView, show it now that we have the post mScrollView.setVisibility(View.VISIBLE); // render the post in the webView mRenderer = new ReaderPostRenderer(mReaderWebView, mPost); mRenderer.beginRender(); txtTitle.setText( mPost.hasTitle() ? mPost.getTitle() : getString(R.string.reader_untitled_post)); followButton.setVisibility(mIsLoggedOutReader ? View.GONE : View.VISIBLE); if (!mIsLoggedOutReader) { followButton.setIsFollowed(mPost.isFollowedByCurrentUser); followButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { togglePostFollowed(); } }); } // clicking the header shows blog preview if (getPostListType() != ReaderPostListType.BLOG_PREVIEW) { layoutHeader.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ReaderActivityLauncher.showReaderBlogPreview(v.getContext(), mPost); } }); } if (mPost.hasBlogName()) { txtBlogName.setText(mPost.getBlogName()); txtBlogName.setVisibility(View.VISIBLE); } else if (mPost.hasBlogUrl()) { txtBlogName.setText(UrlUtils.getDomainFromUrl(mPost.getBlogUrl())); txtBlogName.setVisibility(View.VISIBLE); } else { txtBlogName.setVisibility(View.GONE); } int avatarSz = getResources().getDimensionPixelSize(R.dimen.avatar_sz_medium); if (mPost.hasBlogUrl()) { String imageUrl = GravatarUtils.blavatarFromUrl(mPost.getBlogUrl(), avatarSz); imgAvatar.setImageUrl(imageUrl, WPNetworkImageView.ImageType.BLAVATAR); } else { imgAvatar.setImageUrl( mPost.getPostAvatarForDisplay(avatarSz), WPNetworkImageView.ImageType.AVATAR); } if (mPost.hasAuthorName()) { txtAuthor.setText(mPost.getAuthorName()); txtAuthor.setVisibility(View.VISIBLE); } else { txtAuthor.setVisibility(View.GONE); } String dateLine; if (mPost.hasBlogUrl()) { dateLine = UrlUtils.getDomainFromUrl(mPost.getBlogUrl()) + " \u2022 " + DateTimeUtils.javaDateToTimeSpan(mPost.getDatePublished()); } else { dateLine = DateTimeUtils.javaDateToTimeSpan(mPost.getDatePublished()); } txtDateLine.setText(dateLine); final String tagToDisplay = mPost.getTagForDisplay(null); if (!TextUtils.isEmpty(tagToDisplay)) { txtTag.setText(ReaderUtils.makeHashTag(tagToDisplay)); txtTag.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ReaderTag tag = new ReaderTag(tagToDisplay, ReaderTagType.FOLLOWED); ReaderActivityLauncher.showReaderTagPreview(v.getContext(), tag); } }); } if (canShowFooter() && mLayoutFooter.getVisibility() != View.VISIBLE) { AniUtils.fadeIn(mLayoutFooter, AniUtils.Duration.LONG); } refreshIconCounts(); }