package com.jimind.sportdemo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
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.Section;
import com.jimind.sportdemo.listener.MyClickListener;
import com.jimind.sportdemo.utils.Constant;
import com.jimind.sportdemo.utils.GlideApp;
import com.jimind.sportdemo.utils.TimeFormatUtils;

/**
 * 课程详情
 *
 * @author Any
 */
public class SectionAdapter extends BaseRecyclerAdapter<Section> {

    private MyClickListener mListener;

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

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

    @Override
    protected void onBindItemHolder(final BaseViewHolder holder, final int position) {
        ImageView ivSection = holder.getView(R.id.iv_section);
        TextView tvSectionTitle = holder.getView(R.id.tv_section_title);
        TextView tvSectionDuration = holder.getView(R.id.tv_section_duration);

        final Section section = mDataList.get(position);

        GlideApp.with(mContext)
                .load(Constant.LABEL+MyApplication.getInstance().getHost()
                        + Constant.RESOURCE_PORT + section.getSectionUrl())
                .into(ivSection);
        tvSectionTitle.setText(section.getSectionName());
        tvSectionDuration.setText(TimeFormatUtils.formatSeconds(section.getSectionDuration()));

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


}
