package com.jimind.sportdemo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.jimind.sportdemo.MyApplication;
import com.jimind.sportdemo.R;
import com.jimind.sportdemo.base.BaseRecyclerAdapter;
import com.jimind.sportdemo.base.BaseViewHolder;
import com.jimind.sportdemo.bean.Course;
import com.jimind.sportdemo.listener.MyClickListener;
import com.jimind.sportdemo.utils.CommonUtils;
import com.jimind.sportdemo.utils.Constant;
import com.jimind.sportdemo.utils.GlideApp;

/**
 * 课程列表
 *
 * @author Any
 */
public class CourseAdapter extends BaseRecyclerAdapter<Course> {

    private MyClickListener mListener;

    public CourseAdapter(Context context) {
        super(context);
        mListener = (MyClickListener) mContext;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_course_list;
    }

    @Override
    protected void onBindItemHolder(final BaseViewHolder holder, final int position) {
        ImageView ivCourse = holder.getView(R.id.iv_course);
        TextView tvGrade = holder.getView(R.id.tv_grade);
        TextView tvCourseName = holder.getView(R.id.tv_course_china);
        ProgressBar progressBar = holder.getView(R.id.pb_little_star);

        final Course course = mDataList.get(position);
        tvGrade.setText(course.getGradeName());
        tvCourseName.setText(course.getCourseName());
        progressBar.setProgress(course.getDifficultyLevel() * CommonUtils.dip2px(mContext, 8));
        GlideApp
                .with(mContext)
                .load(Constant.LABEL+MyApplication.getInstance().getHost()
                +Constant.RESOURCE_PORT + course.getCourseListUrl())
                .into(ivCourse);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.click(holder.getAdapterPosition());
            }
        });
    }
}
