package com.bc_chat.circle.adapetr

import android.content.Context
import com.bc_chat.bc_base.entity.contact.UserCircleDetailModel
import com.bc_chat.contacts.R
import com.bc_chat.contacts.databinding.ItemUserCircleBinding
import com.zhaohaoting.framework.abs.adapter.AbsRecyclerAdapter
import com.zhaohaoting.framework.utils.format.MsTransformation
import com.zhaohaoting.framework.utils.glid.GlideUtils

/**
 * author：Created by zhaohaoting on 2019/8/28
 * email：526309416@qq.com
 * desc：
 */
class UserCircleAdapter(context: Context, var commentModel: UserCircleDetailModel = UserCircleDetailModel()) : AbsRecyclerAdapter<UserCircleDetailModel.Topic, UserCircleDetailModel>(context, commentModel.list) {

    private var photo: String? = ""

    override fun getItemLayoutId(type: Int): Int = R.layout.item_user_circle

    override fun getData(): UserCircleDetailModel {
        return commentModel
    }

    override fun onBindViewHolderHF(baseViewHolder: AbsRecyclerAdapter.BaseViewHolder<*>?, realPosition: Int, data: UserCircleDetailModel.Topic?) {
        val binding = baseViewHolder?.dataBinding as ItemUserCircleBinding
        GlideUtils.loadCircleImage(context, photo, binding.ivPhoto)
        binding.tvTitle.text = data?.title
        binding.tvCommentCount.text = data?.comments_count.toString()
        binding.tvTime.text = MsTransformation.formatTimesBefore1(data?.c_time!! * 1000, System.currentTimeMillis())
    }

    override fun notifyDataChanged(data: UserCircleDetailModel?, isRefresh: Boolean) {
        data?.let {
            photo = it.photo
            if (isRefresh) {
                commentModel.list?.clear()
            }
            commentModel.list?.addAll(data.list!!)
            notifyDataSetChanged()
        }
    }
}