package com.duben.microtribe.ui.adapter

import android.app.Activity
import android.view.View
import android.widget.CheckBox
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.duben.library.utils.GlideUtils
import com.duben.microtribe.R
import com.duben.microtribe.mvp.model.VedioBean
import kotlinx.android.synthetic.main.fragment_main.*

/**
 *  @author Assen
 *  @date 2023/7/5
 *  @desc
 */
class FollowAdapter(var activity: Activity) :
    BaseQuickAdapter<VedioBean, BaseViewHolder>(R.layout.item_follow) {

    private var showEdit = false

    override fun convert(holder: BaseViewHolder, item: VedioBean) {
        holder.getView<CheckBox>(R.id.cb).isChecked = item.isChecked
        holder.getView<CheckBox>(R.id.cb).setOnCheckedChangeListener { buttonView, isChecked ->
            item.isChecked = isChecked
        }
        holder.getView<View>(R.id.fm_mask).visibility = if (showEdit) View.VISIBLE else View.GONE
        holder.getView<TextView>(R.id.title_tv).text = item.title
        holder.getView<TextView>(R.id.info_tv).text = "观看至第${item.seeIndex}集"
        holder.getView<TextView>(R.id.complete_tv).text =
            if (item.completeStatus == 0) "已完结" else "更新中"
        GlideUtils.loadImageViewGifForCenterCrop(
            context,
            item.coverImage,
            holder.getView(R.id.image_iv)
        )
    }

    // 设置编辑状态
    fun setEditStyle(showEdit: Boolean) {
        this.showEdit = showEdit
        // 清除选中状态
        if (!this.showEdit) {
            for (datum in data) {
                datum.isChecked = false
            }
        }
        notifyDataSetChanged()
    }

    // 设置编辑状态
    fun getEditStyle(): Boolean {
        return this.showEdit
    }

    // 全选
    fun fullChoice() {
        for (datum in data) {
            datum.isChecked = true
        }
        notifyDataSetChanged()
    }
}