package com.zxhl.main.page.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.cms.widget.RecycleImageView
import com.zxhl.main.R
import kotlinx.android.synthetic.main.activity_layout_user_details_hw.*

/**
 * @author (wangXuewei)
 * @datetime 2022-04-15 18:10 GMT+8
 * @detail :
 */
class UserPhotosAdapter : BaseRecyclerAdapter<String, RecyclerView.ViewHolder> {
    private var mPosition: Int = 0
    private var mContext: Context? = null
    private val listener: OnRecycleItemClickListener<String>

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

    fun setSelectPhoto(pos: Int) {
        mPosition = pos;
        notifyDataSetChanged()
    }


    override fun onCreateViewHolder(holder: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return ViewHolder(
            LayoutInflater.from(holder.context)
                .inflate(R.layout.item_layout_user_photo, holder, false)
        )
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is ViewHolder) {
            val data = mList[position]
            holder.item_photo.setLoadImageUrl(data, R.drawable.pano_sdk_bad_request_error,5)
            if (mPosition == position) {
                holder.item_view.background = mContext?.getDrawable(R.drawable.shape_ffffff_r5)
            } else {
                holder.item_view.background = null
            }
            holder.item_view.setOnClickListener {
                listener.onItemClick(it, position, data)
            }
        }

    }

    inner class ViewHolder : RecyclerView.ViewHolder {

        val item_view: RelativeLayout;
        val item_photo: RecycleImageView;

        constructor(itemView: View) : super(itemView) {
            item_view = itemView.findViewById(R.id.id_rl_item_user_photo_view)
            item_photo = itemView.findViewById(R.id.id_img_item_user_photo)
        }
    }
}