package com.abbidot.tracker.adapter

import android.content.Context
import android.view.View
import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.list.RecyclerViewHolder
import com.abbidot.tracker.R
import com.abbidot.tracker.bean.DFUStateBean

/**
 *Created  by .yzq on 2023/4/17/017.
 * @link
 * @description:
 */
class DFUStateAdapter(
    ctx: Context, list: MutableList<DFUStateBean>?
) : BaseRecyclerAdapter<DFUStateBean>(ctx, list) {
    override fun getEmptyLayoutId(viewType: Int) = 0

    override fun getItemLayoutId(viewType: Int) = R.layout.item_tracker_dfu_state

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: DFUStateBean) {
        val textView = holder!!.getTextView(R.id.item_dfu_state_name)
        val stateName = if (item.progress in 1..100) {
            "${item.stateName}${item.progress}%"
        } else {
            item.stateName
        }
        textView.text = stateName

        if (position == getData().size - 1) {
            holder.getView(R.id.item_dfu_state_progress).visibility = View.VISIBLE
            holder.getView(R.id.item_dfu_state_ok).visibility = View.GONE
        } else {
            holder.getView(R.id.item_dfu_state_progress).visibility = View.GONE
            holder.getView(R.id.item_dfu_state_ok).visibility = View.VISIBLE
        }
    }
}