61 lines
2.1 KiB
Kotlin
61 lines
2.1 KiB
Kotlin
package com.xscm.modulemain.adapter
|
|
|
|
import android.content.Context
|
|
import android.text.SpannableStringBuilder
|
|
import android.text.SpannedString
|
|
import android.text.style.ForegroundColorSpan
|
|
import android.widget.TextView
|
|
import androidx.compose.ui.graphics.Color
|
|
import com.chad.library.adapter.base.BaseQuickAdapter
|
|
import com.chad.library.adapter.base.BaseViewHolder
|
|
import com.xscm.modulemain.R
|
|
import com.xscm.moduleutil.bean.HeartCpBean
|
|
import com.xscm.moduleutil.utils.ImageUtils
|
|
import com.xscm.moduleutil.utils.TimeUtils
|
|
|
|
|
|
class ItemCpHeartAdapter(
|
|
val context: Context,
|
|
val userId: Int,
|
|
layoutId: Int,
|
|
data: MutableList<HeartCpBean.GiftLog>?
|
|
) :
|
|
BaseQuickAdapter<HeartCpBean.GiftLog, BaseViewHolder>(layoutId, data) {
|
|
override fun convert(helper: BaseViewHolder, item: HeartCpBean.GiftLog) {
|
|
|
|
ImageUtils.loadHead(item.from_user_info.avatar, helper.getView(R.id.iv_head))
|
|
helper.setText(R.id.tv_name, item.from_user_info.nickname)
|
|
helper.setText(R.id.tv_time, TimeUtils.getDateToStringNoZ(item.createtime))
|
|
|
|
val tv = helper.getView(R.id.tv_name) as TextView
|
|
|
|
val cid = if (userId == item.from_user_id) {
|
|
tv.setTextColor(context.getColor(R.color.ffff53cc))
|
|
R.color.ff4a89ff
|
|
} else {
|
|
tv.setTextColor(context.getColor(R.color.ff4a89ff))
|
|
R.color.ffff53cc
|
|
}
|
|
if (item.remark.contains(item.to_user_info.nickname)) {
|
|
val builder = getContentColor(item.to_user_info.nickname, item.remark, cid)
|
|
helper.setText(R.id.tv_content, builder)
|
|
} else {
|
|
helper.setText(R.id.tv_content, item.remark)
|
|
}
|
|
}
|
|
|
|
private fun getContentColor(
|
|
userName: String,
|
|
content: String,
|
|
cid: Int
|
|
): SpannableStringBuilder {
|
|
val builder = SpannableStringBuilder()
|
|
val start = content.indexOf(userName)
|
|
val end = start + userName.length
|
|
builder.append(content)
|
|
val colorSpan = ForegroundColorSpan(context.getColor(cid))
|
|
builder.setSpan(colorSpan, start, end, SpannedString.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
return builder
|
|
}
|
|
|
|
} |