package com.tenlionsoft.baselib.core.widget.base;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.core.beans.AddFileBean;

import java.util.List;

/**
 * 作者 : Adam on 2018/11/10.
 * 邮箱 : itgaojian@163.com
 * 描述 : 文件Adapter
 */
public class ShowFileAdapter extends BaseRecyclerAdapter<AddFileBean, ShowFileHolder> {
    public ShowFileAdapter(Context ctx, List<AddFileBean> list) {
        super(ctx, list);
    }

    @Override
    public ShowFileHolder createHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext)
            .inflate(R.layout.item_show_file, parent, false);
        return new ShowFileHolder(itemView);
    }

    @Override
    public void bindHolder(ShowFileHolder applyServicePhotoHolder, int i) {
        if (TextUtils.isEmpty(mData.get(i).getPath())) {
            Glide.with(mContext)
                .load(R.drawable.ic_file_add)
                .into(applyServicePhotoHolder.mIvPhoto);
        } else {
            RequestOptions options = new RequestOptions()
                .transform(new GlideRoundTransform(mContext, 5))
                .error(R.drawable.ic_img_load_err)
                .placeholder(R.drawable.ic_img_loading);
            if (mData.get(i).getFileType() == 1) {
                //文档
                Glide.with(mContext)
                    .load(R.drawable.ic_file_word)
                    .apply(options)
                    .into(applyServicePhotoHolder.mIvPhoto);
            } else if (mData.get(i).getFileType() == 2) {
                //图片
                Glide.with(mContext)
                    .load(mData.get(i).getPath())
                    .apply(options)
                    .into(applyServicePhotoHolder.mIvPhoto);
            } else if (mData.get(i).getFileType() == 3) {
                //视频
                Glide.with(mContext)
                    .load(R.drawable.ic_file_video)
                    .apply(options)
                    .into(applyServicePhotoHolder.mIvPhoto);
            } else if (mData.get(i).getFileType() == 4) {
                //音频
                Glide.with(mContext)
                    .load(R.drawable.ic_file_audio)
                    .apply(options)
                    .into(applyServicePhotoHolder.mIvPhoto);
            }
        }
    }

}
