use of org.wordpress.android.widgets.WPNetworkImageView in project WordPress-Android by wordpress-mobile.
the class ReaderSimplePostView method showFeaturedImage.
private void showFeaturedImage(final View postView) {
final WPNetworkImageView imgFeatured = (WPNetworkImageView) postView.findViewById(R.id.image_featured);
// post must have an excerpt in order to show featured image (not enough space otherwise)
if (!mSimplePost.hasFeaturedImageUrl() || !mSimplePost.hasExcerpt()) {
imgFeatured.setVisibility(View.GONE);
return;
}
// featured image has height set to MATCH_PARENT so wait for parent view's layout to complete
// before loading image so we can set the image height correctly, then tell the imageView
// to crop the downloaded image to fit the exact width/height of the view
postView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
postView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int featuredImageWidth = DisplayUtils.dpToPx(getContext(), getContext().getResources().getDimensionPixelSize(R.dimen.reader_simple_post_image_width));
int cropWidth = featuredImageWidth;
int cropHeight = postView.getHeight();
String photonUrl = PhotonUtils.getPhotonImageUrl(mSimplePost.getFeaturedImageUrl(), cropWidth, cropHeight);
imgFeatured.setImageUrl(photonUrl, WPNetworkImageView.ImageType.PHOTO, null, cropWidth, cropHeight);
}
});
imgFeatured.setVisibility(View.VISIBLE);
}
use of org.wordpress.android.widgets.WPNetworkImageView in project WordPress-Android by wordpress-mobile.
the class ReaderSimplePostView method showPost.
public void showPost(ReaderSimplePost simplePost, ViewGroup parent, boolean isGlobal, final OnSimplePostClickListener listener) {
mSimplePost = simplePost;
int avatarSize = DisplayUtils.dpToPx(getContext(), getResources().getDimensionPixelSize(R.dimen.avatar_sz_extra_small));
LayoutInflater inflater = LayoutInflater.from(getContext());
View postView = inflater.inflate(R.layout.reader_simple_post_view, parent, false);
TextView txtTitle = (TextView) postView.findViewById(R.id.text_simple_post_title);
TextView txtExcerpt = (TextView) postView.findViewById(R.id.text_simple_post_excerpt);
View siteHeader = postView.findViewById(R.id.layout_simple_post_site_header);
txtTitle.setText(mSimplePost.getTitle());
if (mSimplePost.hasExcerpt()) {
txtExcerpt.setText(mSimplePost.getExcerpt());
txtExcerpt.setVisibility(View.VISIBLE);
} else {
txtExcerpt.setVisibility(View.GONE);
}
// site header only appears for global related posts
if (isGlobal) {
WPNetworkImageView imgAvatar = (WPNetworkImageView) siteHeader.findViewById(R.id.image_avatar);
TextView txtSiteName = (TextView) siteHeader.findViewById(R.id.text_site_name);
TextView txtAuthorName = (TextView) siteHeader.findViewById(R.id.text_author_name);
txtSiteName.setText(mSimplePost.getSiteName());
txtAuthorName.setText(mSimplePost.getAuthorName());
if (mSimplePost.hasAuthorAvatarUrl()) {
imgAvatar.setVisibility(View.VISIBLE);
String avatarUrl = GravatarUtils.fixGravatarUrl(mSimplePost.getAuthorAvatarUrl(), avatarSize);
imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
} else {
imgAvatar.setVisibility(View.GONE);
}
ReaderFollowButton btnFollow = (ReaderFollowButton) siteHeader.findViewById(R.id.simple_post_follow_button);
btnFollow.setIsFollowed(mSimplePost.isFollowing());
btnFollow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
toggleFollowStatus((ReaderFollowButton) v);
}
});
siteHeader.setVisibility(View.VISIBLE);
} else {
siteHeader.setVisibility(View.GONE);
}
showFeaturedImage(postView);
postView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onSimplePostClick(view, mSimplePost.getSiteId(), mSimplePost.getPostId());
}
}
});
parent.addView(postView);
}
use of org.wordpress.android.widgets.WPNetworkImageView in project WordPress-Android by wordpress-mobile.
the class ReaderTagHeaderView method initView.
private void initView(Context context) {
View view = inflate(context, R.layout.reader_tag_header_view, this);
mImageView = (WPNetworkImageView) view.findViewById(R.id.image_tag_header);
mTxtAttribution = (TextView) view.findViewById(R.id.text_attribution);
}
use of org.wordpress.android.widgets.WPNetworkImageView in project WordPress-Android by wordpress-mobile.
the class ReaderCommentsPostHeaderView method setPost.
public void setPost(final ReaderPost post) {
if (post == null)
return;
TextView txtTitle = (TextView) findViewById(R.id.text_post_title);
TextView txtBlogName = (TextView) findViewById(R.id.text_blog_name);
TextView txtDateline = (TextView) findViewById(R.id.text_post_dateline);
WPNetworkImageView imgAvatar = (WPNetworkImageView) findViewById(R.id.image_post_avatar);
txtTitle.setText(post.getTitle());
if (post.hasBlogName()) {
txtBlogName.setText(post.getBlogName());
} else {
txtBlogName.setText(R.string.reader_untitled_post);
}
java.util.Date dtPost = DateTimeUtils.dateFromIso8601(post.getDatePublished());
String dateLine = DateTimeUtils.javaDateToTimeSpan(dtPost, WordPress.getContext());
if (post.isCommentsOpen || post.numReplies > 0) {
dateLine += " • " + ReaderUtils.getShortCommentLabelText(getContext(), post.numReplies);
}
if (post.canLikePost() || post.numLikes > 0) {
dateLine += " • " + ReaderUtils.getShortLikeLabelText(getContext(), post.numLikes);
}
txtDateline.setText(dateLine);
int avatarSz = getResources().getDimensionPixelSize(R.dimen.avatar_sz_extra_small);
String avatarUrl;
if (post.hasBlogUrl()) {
avatarUrl = GravatarUtils.blavatarFromUrl(post.getBlogUrl(), avatarSz);
imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.BLAVATAR);
} else {
avatarUrl = post.getPostAvatarForDisplay(avatarSz);
imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
}
}
use of org.wordpress.android.widgets.WPNetworkImageView in project WordPress-Android by wordpress-mobile.
the class CommentDetailFragment method showComment.
/*
* display the current comment
*/
private void showComment() {
if (!isAdded() || getView() == null)
return;
// these two views contain all the other views except the progress bar
final ScrollView scrollView = (ScrollView) getView().findViewById(R.id.scroll_view);
final View layoutBottom = getView().findViewById(R.id.layout_bottom);
// hide container views when comment is null (will happen when opened from a notification)
if (mComment == null) {
scrollView.setVisibility(View.GONE);
layoutBottom.setVisibility(View.GONE);
if (mNote != null) {
SiteModel site = mSiteStore.getSiteBySiteId(mNote.getSiteId());
if (site == null) {
ToastUtils.showToast(getActivity(), R.string.error_load_comment);
return;
}
// Check if the comment is already in our store
CommentModel comment = mCommentStore.getCommentBySiteAndRemoteId(site, mNote.getCommentId());
if (comment != null) {
// It exists, then show it as a "Notification"
showCommentAsNotification(mNote, site, comment);
} else {
// It's not in our store yet, request it.
RemoteCommentPayload payload = new RemoteCommentPayload(site, mNote.getCommentId());
mDispatcher.dispatch(CommentActionBuilder.newFetchCommentAction(payload));
setProgressVisible(true);
// Show a "temporary" comment built from the note data, the view will be refreshed once the
// comment has been fetched.
showCommentAsNotification(mNote, site, null);
}
}
return;
}
scrollView.setVisibility(View.VISIBLE);
layoutBottom.setVisibility(View.VISIBLE);
// Add action buttons footer
if (mNote == null && mLayoutButtons.getParent() == null) {
mCommentContentLayout.addView(mLayoutButtons);
}
final WPNetworkImageView imgAvatar = (WPNetworkImageView) getView().findViewById(R.id.image_avatar);
final TextView txtName = (TextView) getView().findViewById(R.id.text_name);
final TextView txtDate = (TextView) getView().findViewById(R.id.text_date);
txtName.setText(mComment.getAuthorName() == null ? getString(R.string.anonymous) : HtmlUtils.fastUnescapeHtml(mComment.getAuthorName()));
txtDate.setText(DateTimeUtils.javaDateToTimeSpan(DateTimeUtils.dateFromIso8601(mComment.getDatePublished()), WordPress.getContext()));
int maxImageSz = getResources().getDimensionPixelSize(R.dimen.reader_comment_max_image_size);
CommentUtils.displayHtmlComment(mTxtContent, mComment.getContent(), maxImageSz, mImageLoader);
int avatarSz = getResources().getDimensionPixelSize(R.dimen.avatar_sz_large);
if (mComment.getAuthorProfileImageUrl() != null) {
imgAvatar.setImageUrl(GravatarUtils.fixGravatarUrl(mComment.getAuthorProfileImageUrl(), avatarSz), WPNetworkImageView.ImageType.AVATAR);
} else if (mComment.getAuthorEmail() != null) {
String avatarUrl = GravatarUtils.gravatarFromEmail(mComment.getAuthorEmail(), avatarSz);
imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
} else {
imgAvatar.setImageUrl(null, WPNetworkImageView.ImageType.AVATAR);
}
updateStatusViews();
// navigate to author's blog when avatar or name clicked
if (mComment.getAuthorUrl() != null) {
View.OnClickListener authorListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
ReaderActivityLauncher.openUrl(getActivity(), mComment.getAuthorUrl());
}
};
imgAvatar.setOnClickListener(authorListener);
txtName.setOnClickListener(authorListener);
txtName.setTextColor(ContextCompat.getColor(getActivity(), R.color.reader_hyperlink));
} else {
txtName.setTextColor(ContextCompat.getColor(getActivity(), R.color.grey_darken_30));
}
showPostTitle(mSite, mComment.getRemotePostId());
// make sure reply box is showing
if (mLayoutReply.getVisibility() != View.VISIBLE && canReply()) {
AniUtils.animateBottomBar(mLayoutReply, true);
if (mEditReply != null && mShouldFocusReplyField) {
mEditReply.performClick();
disableShouldFocusReplyField();
}
}
getFragmentManager().invalidateOptionsMenu();
}
Aggregations