Search in sources :

Example 1 with LocalMedia

use of com.yalantis.ucrop.entity.LocalMedia in project Atom_Android by Rogrand-Dev.

the class ShowImageAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    //动态计算照片的宽度进行显示
    RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) holder.imageView.getLayoutParams();
    layoutParams.width = (DensityUtils.getScreenWidth(mContext) - DensityUtils.dp2px(mContext, 6) * 2) / 3;
    layoutParams.height = layoutParams.width;
    holder.imageView.setLayoutParams(layoutParams);
    if (getItemViewType(position) == TYPE_SELECT) {
        holder.imageView.setImageResource(R.drawable.ic_add_service_pic);
        holder.imageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onItemControlListener != null) {
                    onItemControlListener.onItemControl(TYPE_SELECT, holder.getAdapterPosition());
                }
            }
        });
        holder.mDelete.setVisibility(View.GONE);
    } else {
        holder.mDelete.setVisibility(View.VISIBLE);
        holder.mDelete.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onItemControlListener != null) {
                    onItemControlListener.onItemControl(TYPE_SHOW, holder.getAdapterPosition());
                }
            }
        });
        LocalMedia media = mAllDatas.get(position);
        String path = "";
        if (media.isCut() && !media.isCompressed()) {
            //裁剪过
            path = media.getCutPath();
        } else if (media.isCompressed() || (media.isCut() && media.isCompressed())) {
            //压缩过,或者裁剪过后压缩过,以是否压缩为准
            path = media.getCompressPath();
        } else {
            //原图
            path = media.getPath();
        }
        int type = media.getType();
        switch(type) {
            case 1:
                //图片
                Glide.with(mContext).load(path).centerCrop().placeholder(R.drawable.ic_add_service_pic).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.imageView);
                break;
            case 2:
                //视频
                Glide.with(mContext).load(path).thumbnail(0.5f).into(holder.imageView);
                break;
        }
    }
}
Also used : RelativeLayout(android.widget.RelativeLayout) LocalMedia(com.yalantis.ucrop.entity.LocalMedia) ImageView(android.widget.ImageView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1 BindView (butterknife.BindView)1 LocalMedia (com.yalantis.ucrop.entity.LocalMedia)1