use of me.zhanghai.android.douya.ui.SizedImageItem in project Douya by DreaminginCodeZH.
the class BroadcastLayout method bindRebroadcastedAttachmentImages.
private void bindRebroadcastedAttachmentImages(Broadcast broadcast, Broadcast rebroadcastedBroadcast) {
boolean hasRebroadcastedBroadcast = rebroadcastedBroadcast != null;
ViewUtils.setVisibleOrGone(mRebroadcastedLayout, hasRebroadcastedBroadcast);
if (hasRebroadcastedBroadcast) {
setRebroadcastedAttachmentImagesLayoutOnClickListener(rebroadcastedBroadcast);
ViewUtils.setVisibleOrGone(mRebroadcastedBroadcastDeletedText, rebroadcastedBroadcast.isDeleted);
if (rebroadcastedBroadcast.isDeleted) {
mRebroadcastedNameText.setText(null);
mRebroadcastedActionText.setText(null);
mRebroadcastedTextText.setText(null);
} else {
mRebroadcastedNameText.setText(rebroadcastedBroadcast.author.name);
mRebroadcastedActionText.setText(rebroadcastedBroadcast.action);
mRebroadcastedTextText.setText(rebroadcastedBroadcast.getTextWithEntities(mRebroadcastedTextText.getContext()));
}
} else {
mRebroadcastedAttachmentImagesLayout.setOnClickListener(null);
}
Broadcast contentBroadcast = hasRebroadcastedBroadcast ? rebroadcastedBroadcast : broadcast;
BroadcastAttachment attachment = contentBroadcast.attachment;
List<? extends SizedImageItem> images = contentBroadcast.attachment != null && contentBroadcast.attachment.imageList != null ? contentBroadcast.attachment.imageList.images : contentBroadcast.images;
if (attachment != null) {
mAttachmentLayout.setVisibility(VISIBLE);
mAttachmentTitleText.setText(attachment.title);
CharSequence attachmentDescription = attachment.getTextWithEntities();
if (TextUtils.isEmpty(attachmentDescription) && images.isEmpty()) {
attachmentDescription = attachment.url;
}
mAttachmentDescriptionText.setText(attachmentDescription);
boolean hasAttachmentImage = attachment.image != null && images.isEmpty();
ViewUtils.setVisibleOrGone(mAttachmentImage, hasAttachmentImage);
if (hasAttachmentImage) {
ImageUtils.loadImage(mAttachmentImage, attachment.image);
}
String attachmentUrl = attachment.url;
if (!TextUtils.isEmpty(attachmentUrl)) {
mAttachmentLayout.setOnClickListener(view -> UriHandler.open(attachmentUrl, view.getContext()));
} else {
mAttachmentLayout.setOnClickListener(null);
}
} else {
mAttachmentLayout.setVisibility(GONE);
}
boolean hasSingleImage = images.size() == 1;
ViewUtils.setVisibleOrGone(mSingleImageLayout, hasSingleImage);
if (hasSingleImage) {
SizedImageItem image = images.get(0);
mSingleImageLayout.loadImage(image);
mSingleImageLayout.setOnClickListener(view -> {
Context context = view.getContext();
context.startActivity(GalleryActivity.makeIntent(image, context));
});
}
boolean hasImageList = images.size() > 1;
ViewUtils.setVisibleOrGone(mImageListLayout, hasImageList);
if (hasImageList) {
mImageListDescriptionText.setText(mImageListDescriptionText.getContext().getString(R.string.broadcast_image_list_count_format, images.size()));
mImageListAdapter.replace(images);
mImageListAdapter.setOnItemClickListener((parent, itemView, item, position) -> {
Context context = itemView.getContext();
context.startActivity(GalleryActivity.makeImageListIntent(images, position, context));
});
}
boolean rebroadecastedAttachmentImagesVisible = hasRebroadcastedBroadcast || attachment != null || !images.isEmpty();
ViewUtils.setVisibleOrGone(mRebroadcastedAttachmentImagesLayout, rebroadecastedAttachmentImagesVisible);
ViewUtils.setVisibleOrGone(mRebroadcastedAttachmentImagesSpace, rebroadecastedAttachmentImagesVisible);
}
use of me.zhanghai.android.douya.ui.SizedImageItem in project Douya by DreaminginCodeZH.
the class ProfileBroadcastsLayout method bind.
public void bind(User user, List<Broadcast> broadcastList) {
Context context = getContext();
View.OnClickListener viewMoreListener = view -> context.startActivity(BroadcastListActivity.makeIntent(user, context));
mTitleText.setOnClickListener(viewMoreListener);
mViewMoreText.setOnClickListener(viewMoreListener);
int i = 0;
for (Broadcast broadcast : broadcastList) {
if (i >= BROADCAST_COUNT_MAX) {
break;
}
if (broadcast.rebroadcastedBroadcast != null) {
continue;
}
if (i >= mBroadcastList.getChildCount()) {
ViewUtils.inflateInto(R.layout.profile_broadcast_item, mBroadcastList);
}
View broadcastLayout = mBroadcastList.getChildAt(i);
broadcastLayout.setVisibility(VISIBLE);
BroadcastLayoutHolder holder = (BroadcastLayoutHolder) broadcastLayout.getTag();
if (holder == null) {
holder = new BroadcastLayoutHolder(broadcastLayout);
broadcastLayout.setTag(holder);
ViewUtils.setTextViewLinkClickable(holder.textText);
}
// HACK: Should not change on rebind.
if (holder.boundBroadcastId != broadcast.id) {
SizedImageItem image = null;
if (broadcast.attachment != null) {
image = broadcast.attachment.image;
}
if (image == null) {
List<? extends SizedImageItem> images = broadcast.attachment != null && broadcast.attachment.imageList != null ? broadcast.attachment.imageList.images : broadcast.images;
if (images.size() > 0) {
image = images.get(0);
}
}
if (image != null) {
holder.image.setVisibility(VISIBLE);
ImageUtils.loadImage(holder.image, image);
} else {
holder.image.setVisibility(GONE);
}
CharSequence text = broadcast.getTextWithEntities(context);
if (TextUtils.isEmpty(text) && broadcast.attachment != null) {
text = broadcast.attachment.title;
}
holder.textText.setText(text);
boolean hasTime = !TextUtils.isEmpty(broadcast.createTime);
ViewUtils.setVisibleOrGone(holder.timeText, hasTime);
if (hasTime) {
holder.timeText.setDoubanTime(broadcast.createTime);
}
ViewUtils.setVisibleOrGone(holder.timeActionSpace, hasTime);
holder.actionText.setText(broadcast.action);
broadcastLayout.setOnClickListener(view -> context.startActivity(BroadcastActivity.makeIntent(broadcast, context)));
holder.boundBroadcastId = broadcast.id;
}
++i;
}
ViewUtils.setVisibleOrGone(mBroadcastList, i != 0);
ViewUtils.setVisibleOrGone(mEmptyView, i == 0);
if (user.broadcastCount > i) {
mViewMoreText.setText(context.getString(R.string.view_more_with_count_format, user.broadcastCount));
} else {
mViewMoreText.setVisibility(GONE);
}
for (int count = mBroadcastList.getChildCount(); i < count; ++i) {
mBroadcastList.getChildAt(i).setVisibility(GONE);
}
}
Aggregations