package com.ym.game.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.ym.library.base.BaseRecyclerAdapter
import com.ym.ddhy.R
import com.ym.library.module.SinginEntity

/**
 *Craeted by ${junqi.li}
 *Craeted by 2020/9/12
 */
class SigninDropsAdapter :
    BaseRecyclerAdapter<SinginEntity.SignInfoListEntity, SigninDropsAdapter.SigninDropsHolder> {
    private var mContext: Context? = null

    constructor(content: Context?) : super() {
        mContext = content
    }

    override fun getItemCount(): Int {
        return mList.size
    }


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

//        val layoutParams = holder.tvDay.layoutParams as LinearLayout.LayoutParams
//
//        val screenWidth = PhoneUtils.getScreenWidth(AppliContext.get())-Utils.dip2px(66)
//
//        val i = (screenWidth -Utils.dip2px(10))/7
//        if(position==mList.size-1){
//            layoutParams.width = i+Utils.dip2px(20)
//        }else{
//            layoutParams.width = i
//        }
//        Log.e("huang","screenWidth: "+screenWidth + "  width: "+(i-Utils.dip2px(10)))
//
//        holder.tvDay.layoutParams = layoutParams
//
//        Log.e("huang","screenWidth: "+layoutParams.width)



        if (mList.size > 0) {
            val data = mList[position]
            holder.tvDay.text = "第${data.id}天"
            if (data.status == 1) {
                holder.tvStatus.text = "已领"
                holder.ivStatus.setImageResource(R.drawable.tab_2)
            } else {
                holder.tvStatus.text = "+${data.awardNum}"
                holder.ivStatus.setImageResource(R.drawable.tab_1)
            }
            if (data.id == 7) {
                holder.tvStatus.text = "???"
                holder.ivStatus.setImageResource(R.drawable.tab_3)
            }
        }


    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SigninDropsHolder {

        return SigninDropsHolder(
            LayoutInflater.from(mContext).inflate(R.layout.item_signin_drops, parent, false)
        )

    }

    inner class SigninDropsHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val ivStatus: ImageView = itemView.findViewById(R.id.iv_item_signin_status)
        val tvDay: TextView = itemView.findViewById(R.id.tv_item_signin_day)
        val tvStatus: TextView = itemView.findViewById(R.id.tv_item_signin_status)
    }
}