Search in sources :

Example 1 with VideoViewHolder

use of com.yiw.circledemo.adapter.viewholder.VideoViewHolder in project CircleDemo by Naoki2015.

the class CircleAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
    if (getItemViewType(position) == TYPE_HEAD) {
    //HeaderViewHolder holder = (HeaderViewHolder) viewHolder;
    } else {
        final int circlePosition = position - HEADVIEW_SIZE;
        final CircleViewHolder holder = (CircleViewHolder) viewHolder;
        final CircleItem circleItem = (CircleItem) datas.get(circlePosition);
        final String circleId = circleItem.getId();
        String name = circleItem.getUser().getName();
        String headImg = circleItem.getUser().getHeadUrl();
        final String content = circleItem.getContent();
        String createTime = circleItem.getCreateTime();
        final List<FavortItem> favortDatas = circleItem.getFavorters();
        final List<CommentItem> commentsDatas = circleItem.getComments();
        boolean hasFavort = circleItem.hasFavort();
        boolean hasComment = circleItem.hasComment();
        Glide.with(context).load(headImg).diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.color.bg_no_photo).transform(new GlideCircleTransform(context)).into(holder.headIv);
        holder.nameTv.setText(name);
        holder.timeTv.setText(createTime);
        if (!TextUtils.isEmpty(content)) {
            holder.contentTv.setExpand(circleItem.isExpand());
            holder.contentTv.setExpandStatusListener(new ExpandTextView.ExpandStatusListener() {

                @Override
                public void statusChange(boolean isExpand) {
                    circleItem.setExpand(isExpand);
                }
            });
            holder.contentTv.setText(UrlUtils.formatUrlString(content));
        }
        holder.contentTv.setVisibility(TextUtils.isEmpty(content) ? View.GONE : View.VISIBLE);
        if (DatasUtil.curUser.getId().equals(circleItem.getUser().getId())) {
            holder.deleteBtn.setVisibility(View.VISIBLE);
        } else {
            holder.deleteBtn.setVisibility(View.GONE);
        }
        holder.deleteBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //删除
                if (presenter != null) {
                    presenter.deleteCircle(circleId);
                }
            }
        });
        if (hasFavort || hasComment) {
            if (hasFavort) {
                //处理点赞列表
                holder.praiseListView.setOnItemClickListener(new PraiseListView.OnItemClickListener() {

                    @Override
                    public void onClick(int position) {
                        String userName = favortDatas.get(position).getUser().getName();
                        String userId = favortDatas.get(position).getUser().getId();
                        Toast.makeText(MyApplication.getContext(), userName + " &id = " + userId, Toast.LENGTH_SHORT).show();
                    }
                });
                holder.praiseListView.setDatas(favortDatas);
                holder.praiseListView.setVisibility(View.VISIBLE);
            } else {
                holder.praiseListView.setVisibility(View.GONE);
            }
            if (hasComment) {
                //处理评论列表
                holder.commentList.setOnItemClickListener(new CommentListView.OnItemClickListener() {

                    @Override
                    public void onItemClick(int commentPosition) {
                        CommentItem commentItem = commentsDatas.get(commentPosition);
                        if (DatasUtil.curUser.getId().equals(commentItem.getUser().getId())) {
                            //复制或者删除自己的评论
                            CommentDialog dialog = new CommentDialog(context, presenter, commentItem, circlePosition);
                            dialog.show();
                        } else {
                            //回复别人的评论
                            if (presenter != null) {
                                CommentConfig config = new CommentConfig();
                                config.circlePosition = circlePosition;
                                config.commentPosition = commentPosition;
                                config.commentType = CommentConfig.Type.REPLY;
                                config.replyUser = commentItem.getUser();
                                presenter.showEditTextBody(config);
                            }
                        }
                    }
                });
                holder.commentList.setOnItemLongClickListener(new CommentListView.OnItemLongClickListener() {

                    @Override
                    public void onItemLongClick(int commentPosition) {
                        //长按进行复制或者删除
                        CommentItem commentItem = commentsDatas.get(commentPosition);
                        CommentDialog dialog = new CommentDialog(context, presenter, commentItem, circlePosition);
                        dialog.show();
                    }
                });
                holder.commentList.setDatas(commentsDatas);
                holder.commentList.setVisibility(View.VISIBLE);
            } else {
                holder.commentList.setVisibility(View.GONE);
            }
            holder.digCommentBody.setVisibility(View.VISIBLE);
        } else {
            holder.digCommentBody.setVisibility(View.GONE);
        }
        holder.digLine.setVisibility(hasFavort && hasComment ? View.VISIBLE : View.GONE);
        final SnsPopupWindow snsPopupWindow = holder.snsPopupWindow;
        //判断是否已点赞
        String curUserFavortId = circleItem.getCurUserFavortId(DatasUtil.curUser.getId());
        if (!TextUtils.isEmpty(curUserFavortId)) {
            snsPopupWindow.getmActionItems().get(0).mTitle = "取消";
        } else {
            snsPopupWindow.getmActionItems().get(0).mTitle = "赞";
        }
        snsPopupWindow.update();
        snsPopupWindow.setmItemClickListener(new PopupItemClickListener(circlePosition, circleItem, curUserFavortId));
        holder.snsBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                //弹出popupwindow
                snsPopupWindow.showPopupWindow(view);
            }
        });
        holder.urlTipTv.setVisibility(View.GONE);
        switch(holder.viewType) {
            case // 处理链接动态的链接内容和和图片
            CircleViewHolder.TYPE_URL:
                if (holder instanceof URLViewHolder) {
                    String linkImg = circleItem.getLinkImg();
                    String linkTitle = circleItem.getLinkTitle();
                    Glide.with(context).load(linkImg).into(((URLViewHolder) holder).urlImageIv);
                    ((URLViewHolder) holder).urlContentTv.setText(linkTitle);
                    ((URLViewHolder) holder).urlBody.setVisibility(View.VISIBLE);
                    ((URLViewHolder) holder).urlTipTv.setVisibility(View.VISIBLE);
                }
                break;
            case // 处理图片
            CircleViewHolder.TYPE_IMAGE:
                if (holder instanceof ImageViewHolder) {
                    final List<PhotoInfo> photos = circleItem.getPhotos();
                    if (photos != null && photos.size() > 0) {
                        ((ImageViewHolder) holder).multiImageView.setVisibility(View.VISIBLE);
                        ((ImageViewHolder) holder).multiImageView.setList(photos);
                        ((ImageViewHolder) holder).multiImageView.setOnItemClickListener(new MultiImageView.OnItemClickListener() {

                            @Override
                            public void onItemClick(View view, int position) {
                                //imagesize是作为loading时的图片size
                                ImagePagerActivity.ImageSize imageSize = new ImagePagerActivity.ImageSize(view.getMeasuredWidth(), view.getMeasuredHeight());
                                List<String> photoUrls = new ArrayList<String>();
                                for (PhotoInfo photoInfo : photos) {
                                    photoUrls.add(photoInfo.url);
                                }
                                ImagePagerActivity.startImagePagerActivity(((MainActivity) context), photoUrls, position, imageSize);
                            }
                        });
                    } else {
                        ((ImageViewHolder) holder).multiImageView.setVisibility(View.GONE);
                    }
                }
                break;
            case CircleViewHolder.TYPE_VIDEO:
                if (holder instanceof VideoViewHolder) {
                    ((VideoViewHolder) holder).videoView.setVideoUrl(circleItem.getVideoUrl());
                    //视频封面图片
                    ((VideoViewHolder) holder).videoView.setVideoImgUrl(circleItem.getVideoImgUrl());
                    ((VideoViewHolder) holder).videoView.setPostion(position);
                    ((VideoViewHolder) holder).videoView.setOnPlayClickListener(new CircleVideoView.OnPlayClickListener() {

                        @Override
                        public void onPlayClick(int pos) {
                            curPlayIndex = pos;
                        }
                    });
                }
                break;
            default:
                break;
        }
    }
}
Also used : PhotoInfo(com.yiw.circledemo.bean.PhotoInfo) CircleViewHolder(com.yiw.circledemo.adapter.viewholder.CircleViewHolder) PraiseListView(com.yiw.circledemo.widgets.PraiseListView) VideoViewHolder(com.yiw.circledemo.adapter.viewholder.VideoViewHolder) CommentConfig(com.yiw.circledemo.bean.CommentConfig) SnsPopupWindow(com.yiw.circledemo.widgets.SnsPopupWindow) ImageViewHolder(com.yiw.circledemo.adapter.viewholder.ImageViewHolder) ArrayList(java.util.ArrayList) List(java.util.List) GlideCircleTransform(com.yiw.circledemo.utils.GlideCircleTransform) CommentListView(com.yiw.circledemo.widgets.CommentListView) MultiImageView(com.yiw.circledemo.widgets.MultiImageView) FavortItem(com.yiw.circledemo.bean.FavortItem) ExpandTextView(com.yiw.circledemo.widgets.ExpandTextView) CircleVideoView(com.yiw.circledemo.widgets.CircleVideoView) ExpandTextView(com.yiw.circledemo.widgets.ExpandTextView) CommentListView(com.yiw.circledemo.widgets.CommentListView) View(android.view.View) MultiImageView(com.yiw.circledemo.widgets.MultiImageView) PraiseListView(com.yiw.circledemo.widgets.PraiseListView) RecyclerView(android.support.v7.widget.RecyclerView) CommentDialog(com.yiw.circledemo.widgets.dialog.CommentDialog) ImagePagerActivity(com.yiw.circledemo.activity.ImagePagerActivity) URLViewHolder(com.yiw.circledemo.adapter.viewholder.URLViewHolder) CommentItem(com.yiw.circledemo.bean.CommentItem) CircleItem(com.yiw.circledemo.bean.CircleItem) CircleVideoView(com.yiw.circledemo.widgets.CircleVideoView)

Example 2 with VideoViewHolder

use of com.yiw.circledemo.adapter.viewholder.VideoViewHolder in project CircleDemo by Naoki2015.

the class CircleAdapter method onCreateViewHolder.

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    RecyclerView.ViewHolder viewHolder = null;
    if (viewType == TYPE_HEAD) {
        View headView = LayoutInflater.from(parent.getContext()).inflate(R.layout.head_circle, parent, false);
        viewHolder = new HeaderViewHolder(headView);
    } else {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_circle_item, parent, false);
        if (viewType == CircleViewHolder.TYPE_URL) {
            viewHolder = new URLViewHolder(view);
        } else if (viewType == CircleViewHolder.TYPE_IMAGE) {
            viewHolder = new ImageViewHolder(view);
        } else if (viewType == CircleViewHolder.TYPE_VIDEO) {
            viewHolder = new VideoViewHolder(view);
        }
    }
    return viewHolder;
}
Also used : URLViewHolder(com.yiw.circledemo.adapter.viewholder.URLViewHolder) ImageViewHolder(com.yiw.circledemo.adapter.viewholder.ImageViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) CircleVideoView(com.yiw.circledemo.widgets.CircleVideoView) ExpandTextView(com.yiw.circledemo.widgets.ExpandTextView) CommentListView(com.yiw.circledemo.widgets.CommentListView) View(android.view.View) MultiImageView(com.yiw.circledemo.widgets.MultiImageView) PraiseListView(com.yiw.circledemo.widgets.PraiseListView) RecyclerView(android.support.v7.widget.RecyclerView) VideoViewHolder(com.yiw.circledemo.adapter.viewholder.VideoViewHolder)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageViewHolder (com.yiw.circledemo.adapter.viewholder.ImageViewHolder)2 URLViewHolder (com.yiw.circledemo.adapter.viewholder.URLViewHolder)2 VideoViewHolder (com.yiw.circledemo.adapter.viewholder.VideoViewHolder)2 CircleVideoView (com.yiw.circledemo.widgets.CircleVideoView)2 CommentListView (com.yiw.circledemo.widgets.CommentListView)2 ExpandTextView (com.yiw.circledemo.widgets.ExpandTextView)2 MultiImageView (com.yiw.circledemo.widgets.MultiImageView)2 PraiseListView (com.yiw.circledemo.widgets.PraiseListView)2 ImagePagerActivity (com.yiw.circledemo.activity.ImagePagerActivity)1 CircleViewHolder (com.yiw.circledemo.adapter.viewholder.CircleViewHolder)1 CircleItem (com.yiw.circledemo.bean.CircleItem)1 CommentConfig (com.yiw.circledemo.bean.CommentConfig)1 CommentItem (com.yiw.circledemo.bean.CommentItem)1 FavortItem (com.yiw.circledemo.bean.FavortItem)1 PhotoInfo (com.yiw.circledemo.bean.PhotoInfo)1 GlideCircleTransform (com.yiw.circledemo.utils.GlideCircleTransform)1 SnsPopupWindow (com.yiw.circledemo.widgets.SnsPopupWindow)1 CommentDialog (com.yiw.circledemo.widgets.dialog.CommentDialog)1