package com.zswc.creativity.adapter

import android.graphics.Color
import android.graphics.Typeface
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.TextUtils
import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.view.View
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.google.gson.Gson
import com.qmuiteam.qmui.kotlin.onClick
import com.zswc.creativity.R
import com.zswc.creativity.activity.ArticleDetailActivity
import com.zswc.creativity.databinding.ItemMsgBinding
import com.zswc.creativity.model.MsgList
import com.zswc.creativity.utils.VerifyUtils
import com.zswc.creativity.vmodel.MsgVModel
import com.ysnows.base.base.BAdapter
import com.ysnows.base.utils.UiSwitch

class MsgAdapter(var vm: MsgVModel) : BAdapter<MsgList, BaseDataBindingHolder<ItemMsgBinding>>(R.layout.item_msg) {

    override fun convert(holder: BaseDataBindingHolder<ItemMsgBinding>, item: MsgList) {
        holder.dataBinding?.vm = vm
        holder.dataBinding?.item = item

        if (item.is_read) {//已读
            holder.dataBinding?.tvTitle?.text = item.title
        } else {

            var title = item.title + "·"
            var spannableString = SpannableStringBuilder(title)
            //设置颜色
            spannableString.setSpan(ForegroundColorSpan(Color.RED), title.length - 1, title.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
            //设置大小
            spannableString.setSpan(AbsoluteSizeSpan(30, true), title.length - 1, title.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
            //设置字体
            spannableString.setSpan(StyleSpan(Typeface.BOLD), title.length - 1, title.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            holder.dataBinding?.tvTitle?.text = spannableString


        }
        holder.dataBinding?.ll!!.onClick {
            item.is_read = true

            UiSwitch.bundle(context, ArticleDetailActivity::class.java, Bundle().apply {
                putString("type", "-1")
                putString("content", Gson().toJson(item))
            })


        }


    }
}
