package com.daya.live_teaching.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cooleshow.base.utils.GlideImageLoaderUtils;
import com.daya.live_teaching.R;
import com.daya.live_teaching.model.ClassMember;
import com.daya.live_teaching.ui.base.BaseRecyclerAdapter;
import com.daya.live_teaching.ui.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;

/**
 * Description:
 * Copyright  : Copyright (c) 2019
 * Company    : 大雅乐盟
 * Author     : r
 * Date       : 2020/6/9 10:43
 */
public class AccompanimentDownloadListAdapter extends BaseRecyclerAdapter<AccompanimentDownloadListAdapter.ViewHolder> {

    private Context mContext;
    List<ClassMember> menberList = new ArrayList<>();
    private String musicScoreAccompanimentId;

    public AccompanimentDownloadListAdapter(Context context) {
        this.mContext = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflater = LayoutInflater.from(mContext).inflate(R.layout.layout_accompaniment_download_list_item, parent, false);
        return new ViewHolder(inflater);
    }

    @Override
    public int getItemCount() {
        return menberList.size();
    }

    public void setData(List<ClassMember> classMembers, String musicScoreAccompanimentId) {
        this.musicScoreAccompanimentId = musicScoreAccompanimentId;
        this.menberList.clear();
        this.menberList.addAll(classMembers);
        notifyDataSetChanged();
    }

    public class ViewHolder extends BaseViewHolder {
        ImageView ivPortrait;
        TextView tvName;
        TextView tvStatus;

        public ViewHolder(View itemView) {
            super(itemView);
            ivPortrait = itemView.findViewById(R.id.iv_portrait);
            tvName = itemView.findViewById(R.id.tv_name);
            tvStatus = itemView.findViewById(R.id.tv_status);
        }

        @Override
        protected void onBind(int position) {
            ClassMember member = menberList.get(position);
            GlideImageLoaderUtils.getInstance().loadCircleImage(mContext, member.getHeadUrl(), ivPortrait);
            tvName.setText(member.getUserName());

            for (ClassMember.ScheduleStudentMusicScoresBean musicScoresBean : member.getScheduleStudentMusicScores()) {
                if (musicScoreAccompanimentId.equals(musicScoresBean.getMusicScoreAccompanimentId())) {
                    if (musicScoresBean.getDownStatus() == 1) {
                        tvStatus.setText("已下载");
                        tvStatus.setTextColor(mContext.getResources().getColor(com.cooleshow.base.R.color.color_666666));
                    } else if (musicScoresBean.getDownStatus() == 2) {
                        tvStatus.setText("下载失败");
                        tvStatus.setTextColor(mContext.getResources().getColor(com.cooleshow.base.R.color.common_red));
                    } else {
                        tvStatus.setText("下载中");
                        tvStatus.setTextColor(mContext.getResources().getColor(R.color.live_text_green));
                    }
                    break;
                }
            }

        }
    }

    public OnSubViewClickListener onSubViewClickListener;

    public interface OnSubViewClickListener {
        void onSubViewClick(int type, String userId);
    }


    public void setOnSubViewClickListener(OnSubViewClickListener listener) {
        this.onSubViewClickListener = listener;
    }
}
