package com.abbidot.tracker.adapter

import android.content.Context
import android.text.TextUtils
import android.view.View
import androidx.fragment.app.FragmentActivity
import coil.load
import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.list.RecyclerViewHolder
import com.abbidot.tracker.R
import com.abbidot.tracker.bean.MenuTxtBean
import com.abbidot.tracker.ui.activity.help.FeedbackActivity
import java.io.File

/**
 *Created  by .yzq on 2022/3/23/023.
 * @link
 * @description:反馈上传的图片
 */
class FeedbackImageAdapter(
    ctx: Context, activity: FragmentActivity, list: MutableList<MenuTxtBean>?
) : BaseRecyclerAdapter<MenuTxtBean>(ctx, list) {

    private val mActivity = activity as FeedbackActivity

    override fun getEmptyLayoutId(viewType: Int) = 0

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

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: MenuTxtBean) {
        val imageView = holder!!.getImageView(R.id.show_select_image)
        val deleteView = holder.getTextView(R.id.delete_image_cancel)
        if (TextUtils.isEmpty(item.imageUrl)) {
            imageView.load(R.drawable.ico_photo)
            deleteView.visibility = View.GONE
            imageView.setOnClickListener {
//                ViewUtil.instance.goSelectPhoto(
//                    mActivity,
//                    ResultCode.ResultCode_1,
//                    count = mActivity.mLimitPhotoCount - (getData().size - 1)
//                )
            }
        } else {
            imageView.setOnClickListener(null)
            imageView.load(File(item.imageUrl))
            deleteView.visibility = View.VISIBLE
            deleteView.setOnClickListener {
                val list = getData()
                mActivity.deletePhoto(list, item)
            }
        }
    }
}