package com.cooleshow.student.adapter;

import android.text.TextUtils;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;

import com.airbnb.lottie.LottieAnimationView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.student.R;
import com.cooleshow.student.bean.RecommendTalentListBean;

import androidx.annotation.NonNull;

/**
 * Author by pq, Date on 2022/8/30.
 */
public class HomeRecommendTalentAdapter extends BaseQuickAdapter<RecommendTalentListBean, BaseViewHolder> {

    public HomeRecommendTalentAdapter() {
        super(R.layout.item_home_recommend_talent_layot);
        addChildClickViewIds(R.id.tv_focus);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, RecommendTalentListBean data) {
        //头像
        ImageView iv_avatar = holder.getView(R.id.iv_avatar);
        GlideUtils.INSTANCE.loadImage(getContext(), data.avatar, iv_avatar, R.drawable.icon_teacher_default_head);
        //昵称
        holder.setText(R.id.tv_name, data.username);
        //毕业院校
        holder.setText(R.id.tv_tip, TextUtils.isEmpty(data.graduateSchool) ? "认证达人" : data.graduateSchool);
        //是否直播中
        View tv_live_tip = holder.getView(R.id.tv_live_tip);
        LottieAnimationView view_live_anim = holder.getView(R.id.view_live_anim);
        if (data.living) {
            view_live_anim.setVisibility(View.VISIBLE);
            view_live_anim.playAnimation();
            tv_live_tip.setVisibility(View.VISIBLE);
        } else {
            view_live_anim.pauseAnimation();
            view_live_anim.setVisibility(View.GONE);
            tv_live_tip.setVisibility(View.GONE);
        }
        TextView tv_focus = holder.getView(R.id.tv_focus);

        if (data.isFocus) {
            tv_focus.setBackgroundResource(R.drawable.shape_border_f0f0f0_1dp);
            tv_focus.setTextColor(getContext().getResources().getColor(R.color.color_999999));
        } else {
            tv_focus.setBackgroundResource(R.drawable.shape_2dc7aa_12dp);
            tv_focus.setTextColor(getContext().getResources().getColor(R.color.white));
        }
    }
}
