package com.swago.user.task

import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.swago.baseswago.model.mine.TaskModel
import com.swago.user.R

/**
 *@date 2021/11/25 21:53
 *description:
 */
class TaskAdapter : BaseQuickAdapter<TaskModel, BaseViewHolder>(
    R.layout.item_task,
    arrayListOf()) {
    override fun convert(helper: BaseViewHolder, item: TaskModel) {
        helper.apply {
            setText(R.id.tvTitle,item.task_name)
            setText(R.id.tvReward,item.task_desc)
            //(1经验值2金币值)
            if (item.task_reward_type == 1){
                setText(R.id.tvRewardType,R.string.exp)
            }else if (item.task_reward_type == 2){
                setText(R.id.tvRewardType,R.string.coin)
            }
            setText(R.id.tvRewardTypeValue,"+${item.task_reward_value}")

            //0待完成1已完成可领取2领取已完成
            when(item.task_status){
                0 -> {
                    setTextColor(R.id.tvStatus,ContextCompat.getColor(mContext,R.color._ffffff))
                    setTextColor(R.id.tvCount,ContextCompat.getColor(mContext,R.color._ffffff))
                    setText(R.id.tvStatus,R.string.uncomplete)
                    setBackgroundRes(R.id.clReceive,R.drawable.shape_ff9300_5)
                }

                1 -> {
                    setTextColor(R.id.tvStatus,ContextCompat.getColor(mContext,R.color._ffffff))
                    setTextColor(R.id.tvCount,ContextCompat.getColor(mContext,R.color._ffffff))
                    setText(R.id.tvStatus,R.string.receive)
                    setBackgroundRes(R.id.clReceive,R.drawable.shape_black_5)
                }

                2 -> {
                    setTextColor(R.id.tvStatus,ContextCompat.getColor(mContext,R.color._868686))
                    setTextColor(R.id.tvCount,ContextCompat.getColor(mContext,R.color._868686))
                    setText(R.id.tvStatus,R.string.complete)
                    setBackgroundRes(R.id.clReceive,R.drawable.shape_f7f8fa_5)
                }
            }
            setText(R.id.tvCount,"(${item.task_success_num}/${item.task_total_num})")

        }
    }
}