package com.bc_chat.circle.adapetr

import android.content.Context
import com.bc_chat.bc_base.entity.contact.Dynamic
import com.bc_chat.contacts.R
import com.zhaohaoting.framework.abs.adapter.ListToAdapter
import com.bc_chat.contacts.databinding.ItemDynamicLayoutBinding
import com.zhaohaoting.framework.imagepicker.bean.MediaItem

/**
 * author：Created by zhaohaoting on 2019/8/27
 * email：526309416@qq.com
 * desc：
 */
class DynamicAdapter(val context: Context) : ListToAdapter<Dynamic, List<Dynamic>>(context) {
    override fun getItemLayoutId(type: Int): Int = R.layout.item_dynamic_layout

    override fun onBindViewHolderHF(baseViewHolder: BaseViewHolder<*>?, realPosition: Int, data: Dynamic?) {
        val binding = baseViewHolder?.dataBinding as ItemDynamicLayoutBinding
        data?.let {
            onDynamicClickListener?.let { onDynamicClickListener ->
                binding.dynamicView.setDynamicClickListener(onDynamicClickListener)
            }
            binding.dynamicView.updateView(it,realPosition)
        }
    }

    fun setOnDynamicClickListener(onDynamicClickListener: OnDynamicClickListener) {
        this.onDynamicClickListener = onDynamicClickListener
    }

    private var onDynamicClickListener: OnDynamicClickListener? = null

    interface OnDynamicClickListener {
        fun itemImageClick(imageList: List<MediaItem>, index: Int, realPosition: Int)

        fun itemPhotoClick(uid: String)

    }
}