Search in sources :

Example 1 with SizedImageItem

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);
}
Also used : Context(android.content.Context) BroadcastAttachment(me.zhanghai.android.douya.network.api.info.frodo.BroadcastAttachment) SizedImageItem(me.zhanghai.android.douya.ui.SizedImageItem) Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast)

Example 2 with SizedImageItem

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);
    }
}
Also used : Context(android.content.Context) Context(android.content.Context) ImageUtils(me.zhanghai.android.douya.util.ImageUtils) LinearLayout(android.widget.LinearLayout) BroadcastListActivity(me.zhanghai.android.douya.broadcast.ui.BroadcastListActivity) ButterKnife(butterknife.ButterKnife) ViewUtils(me.zhanghai.android.douya.util.ViewUtils) TimeTextView(me.zhanghai.android.douya.ui.TimeTextView) ImageView(android.widget.ImageView) TextUtils(android.text.TextUtils) R(me.zhanghai.android.douya.R) BindView(butterknife.BindView) User(me.zhanghai.android.douya.network.api.info.apiv2.User) List(java.util.List) TextView(android.widget.TextView) AttributeSet(android.util.AttributeSet) BroadcastActivity(me.zhanghai.android.douya.broadcast.ui.BroadcastActivity) View(android.view.View) SizedImageItem(me.zhanghai.android.douya.ui.SizedImageItem) Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast) FriendlyCardView(me.zhanghai.android.douya.ui.FriendlyCardView) SizedImageItem(me.zhanghai.android.douya.ui.SizedImageItem) Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast) TimeTextView(me.zhanghai.android.douya.ui.TimeTextView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View) FriendlyCardView(me.zhanghai.android.douya.ui.FriendlyCardView)

Aggregations

Context (android.content.Context)2 Broadcast (me.zhanghai.android.douya.network.api.info.frodo.Broadcast)2 SizedImageItem (me.zhanghai.android.douya.ui.SizedImageItem)2 TextUtils (android.text.TextUtils)1 AttributeSet (android.util.AttributeSet)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1 List (java.util.List)1 R (me.zhanghai.android.douya.R)1 BroadcastActivity (me.zhanghai.android.douya.broadcast.ui.BroadcastActivity)1 BroadcastListActivity (me.zhanghai.android.douya.broadcast.ui.BroadcastListActivity)1 User (me.zhanghai.android.douya.network.api.info.apiv2.User)1 BroadcastAttachment (me.zhanghai.android.douya.network.api.info.frodo.BroadcastAttachment)1 FriendlyCardView (me.zhanghai.android.douya.ui.FriendlyCardView)1 TimeTextView (me.zhanghai.android.douya.ui.TimeTextView)1 ImageUtils (me.zhanghai.android.douya.util.ImageUtils)1