package com.zxbw.modulemain.adapter

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.recyclerview.widget.RecyclerView
import com.zxbw.modulemain.R
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.cms.widget.RecycleImageView


class CashTaskListAdapter : BaseRecyclerAdapter<Any, CashTaskListAdapter.ViewHolder> {
    private var mContext: Activity? = null
    private val listener: OnRecycleItemClickListener<Any>

    constructor(
        content: Activity?,
        listener: OnRecycleItemClickListener<Any>
    ) : super() {
        mContext = content
        this.listener = listener
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        if (position == 0) {
            holder.id_tv_task_title?.text = "看视频"
            holder.id_img_task_icon?.setImageResource(R.drawable.icon_task_kanshipin)
            holder.id_tv_task_desc?.text = "每日看视频领取大量幸运币"
            holder.id_img_task_btn_icon?.visibility = View.VISIBLE
            holder.id_tv_task_btn_desc?.text = "+100/次"
            holder.id_ll_progress_view?.visibility = View.VISIBLE
        } else {
            holder.id_tv_task_title?.text = "整点抢红包"
            holder.id_img_task_icon?.setImageResource(R.drawable.icon_task_zhengdianqianghongbao)
            holder.id_tv_task_desc?.text = "整点开枪 抢完即止 幸运可拿888元"
            holder.id_img_task_btn_icon?.visibility = View.GONE
            holder.id_tv_task_btn_desc?.text = "点我抢"
            holder.id_ll_progress_view?.visibility = View.GONE
        }

        holder.id_ll_task_btn?.setOnClickListener {
            listener.onItemClick(it, position, null)
        }
    }

    override fun getItemCount(): Int {
        return 2
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(AppContext.get())
                .inflate(R.layout.item_layout_cash_task_view, parent, false)
        )
    }

    class ViewHolder : RecyclerView.ViewHolder {
        var id_ll_cash_task_view: LinearLayout?
        var id_img_task_icon: ImageView?
        var id_tv_task_title: TextView?
        var id_tv_task_desc: TextView?
        var id_ll_progress_view: LinearLayout?
        var id_task_progress_view: ProgressBar?
        var id_tv_task_progress_desc: TextView?
        var id_tv_task_progress_rate: TextView?
        var id_ll_task_btn: LinearLayout?
        var id_img_task_btn_icon: ImageView?
        var id_tv_task_btn_desc: TextView?

        constructor(
            itemView: View
        ) : super(itemView) {
            id_ll_cash_task_view = itemView.findViewById<LinearLayout>(R.id.id_ll_cash_task_view)
            id_img_task_icon = itemView.findViewById<ImageView>(R.id.id_img_task_icon)
            id_tv_task_title = itemView.findViewById<TextView>(R.id.id_tv_task_title)
            id_tv_task_desc = itemView.findViewById<TextView>(R.id.id_tv_task_desc)
            id_ll_progress_view = itemView.findViewById<LinearLayout>(R.id.id_ll_progress_view)
            id_task_progress_view = itemView.findViewById<ProgressBar>(R.id.id_task_progress_view)
            id_tv_task_progress_desc =
                itemView.findViewById<TextView>(R.id.id_tv_task_progress_desc)
            id_tv_task_progress_rate =
                itemView.findViewById<TextView>(R.id.id_tv_task_progress_rate)
            id_ll_task_btn = itemView.findViewById<LinearLayout>(R.id.id_ll_task_btn)
            id_img_task_btn_icon = itemView.findViewById<ImageView>(R.id.id_img_task_btn_icon)
            id_tv_task_btn_desc = itemView.findViewById<TextView>(R.id.id_tv_task_btn_desc)
        }
    }
}