package com.renrenliao.im.ui.adapter

import android.widget.ImageView
import android.widget.TextView
import androidx.lifecycle.LifecycleOwner
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.renrenliao.im.R
import com.renrenliao.im.ext.gone
import com.renrenliao.im.ext.visible
import com.renrenliao.im.im.AlarmEntity
import com.renrenliao.im.im.AlarmType
import com.renrenliao.im.model.repository.LocalDataSource
import com.renrenliao.im.utils.GlideUtils
import com.renrenliao.im.utils.LogUtils
import com.renrenliao.im.utils.MDateUtils
import com.renrenliao.im.viewmodel.AlarmViewModel

/**
 **@ClassName AlarmAdapter
 **@Description
 **@Author gan
 **@Date 2022/5/27 15:07
 **/
class AlarmAdapter:BaseQuickAdapter<AlarmEntity,BaseViewHolder>(R.layout.item_alarm) {

    override fun convert(holder: BaseViewHolder, item: AlarmEntity) {
        val tvTitle = holder.getView<TextView>(R.id.tv_title)
        val tvDate = holder.getView<TextView>(R.id.tv_date)
        val tvMsg = holder.getView<TextView>(R.id.tv_alarm_msg)
        val ivAvatar = holder.getView<ImageView>(R.id.iv_avatar)
        val tvNum = holder.getView<TextView>(R.id.tv_flag_num)
        val tvTitleLeft = holder.getView<TextView>(R.id.tv_title_left)
        val ivTop = holder.getView<ImageView>(R.id.iv_istop)

        tvTitle.text = item.name
        tvMsg.text = item.msg
        tvDate.text = item.time?.let { MDateUtils.getTimeStr_auto(it,true) }

        if (item.num==0){
            tvNum.gone()
        }else{
            tvNum.visible()
            tvNum.text = item.num.toString()
        }
        if (item.isTop){
            ivTop.visible()
        }else{
            ivTop.gone()
        }

        when(item.msgType){
            //添加好友
            AlarmType.ADDFRIENDREQUEST.value ->{
                ivAvatar.setImageResource(R.drawable.ic_alarms_addfriendrequest_message)
            }
            //加好友被拒绝
            AlarmType.ADDFRIENDBEREJECT.value ->{

            }
            //好友消息
            AlarmType.REVICEMESSAGE.value ->{
                GlideUtils.loadUserImage(ivAvatar,item.getAvatarUrl())
            }
        }
    }
}