package com.swago.home.search

import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.google.android.material.imageview.ShapeableImageView
import com.swago.baseswago.cusview.MediumTextView
import com.swago.baseswago.cusview.SwagoLevelView
import com.swago.baseswago.model.MomentModel
import com.swago.baseswago.model.home.HomeModel
import com.swago.baseswago.util.AppContext
import com.swago.home.R
import de.hdodenhof.circleimageview.CircleImageView

/**
 *@date 2021/12/2 13:44
 *description:
 */
class SearchAdapter :
    BaseQuickAdapter<MomentModel, BaseViewHolder>(R.layout.item_search, arrayListOf()) {

    override fun convert(helper: BaseViewHolder, item: MomentModel) {
        helper.apply {
            helper.apply {
                itemView.findViewById<MediumTextView>(R.id.tvName).text = item.user_name
                setText(R.id.tvId, AppContext.getContext().resources.getString(R.string.id_x).format(item.user_account))
                if (item.user_sex == 0) {
                    setImageResource(R.id.ivSex, R.mipmap.info_male)
                } else {
                    setImageResource(R.id.ivSex, R.mipmap.info_female)
                }

                setVisible(R.id.ivStatus, true)
                if (item.is_follow == 1){
                    setImageResource(R.id.ivStatus, R.mipmap.followed)
                }else{
                    setImageResource(R.id.ivStatus, R.mipmap.follow)
                }
                addOnClickListener(R.id.ivStatus)
                val tvLevel = itemView.findViewById<SwagoLevelView>(R.id.tvLevel)
                tvLevel.setUserLevel(item.user_level)
                val ivAvatar = itemView.findViewById<CircleImageView>(R.id.ivAvatar)
                Glide.with(itemView.context).load(item.user_head_img_url)
                    .placeholder(R.mipmap.default_avatar)
                    .error(R.mipmap.default_avatar).centerCrop().into(ivAvatar)
            }

        }
    }
}