|
@@ -2,6 +2,7 @@ package com.swago.room.adapter
|
|
|
|
|
|
import android.graphics.Bitmap
|
|
import android.graphics.Bitmap
|
|
import android.graphics.Color
|
|
import android.graphics.Color
|
|
|
|
+import android.graphics.drawable.NinePatchDrawable
|
|
import android.os.Build
|
|
import android.os.Build
|
|
import android.text.*
|
|
import android.text.*
|
|
import android.text.method.LinkMovementMethod
|
|
import android.text.method.LinkMovementMethod
|
|
@@ -11,12 +12,12 @@ import android.text.style.ImageSpan
|
|
import android.view.LayoutInflater
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
|
+import android.widget.ImageView
|
|
import android.widget.TextView
|
|
import android.widget.TextView
|
|
import androidx.constraintlayout.widget.ConstraintLayout
|
|
import androidx.constraintlayout.widget.ConstraintLayout
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.core.content.ContextCompat
|
|
import com.chad.library.adapter.base.BaseQuickAdapter
|
|
import com.chad.library.adapter.base.BaseQuickAdapter
|
|
import com.chad.library.adapter.base.BaseViewHolder
|
|
import com.chad.library.adapter.base.BaseViewHolder
|
|
-import com.swago.baseswago.baseroom.SwagoRoomManager
|
|
|
|
import com.swago.baseswago.cusview.LiangView
|
|
import com.swago.baseswago.cusview.LiangView
|
|
import com.swago.baseswago.cusview.SwagoLevelView
|
|
import com.swago.baseswago.cusview.SwagoLevelView
|
|
import com.swago.baseswago.im.IRoomChat
|
|
import com.swago.baseswago.im.IRoomChat
|
|
@@ -25,6 +26,9 @@ import com.swago.baseswago.model.im.FollowSuccessMsgBean
|
|
import com.swago.baseswago.model.im.IMLevelUpMsgBean
|
|
import com.swago.baseswago.model.im.IMLevelUpMsgBean
|
|
import com.swago.baseswago.model.im.RoomChatMsgBean
|
|
import com.swago.baseswago.model.im.RoomChatMsgBean
|
|
import com.swago.baseswago.model.im.UserJoinRoomBean
|
|
import com.swago.baseswago.model.im.UserJoinRoomBean
|
|
|
|
+import com.swago.baseswago.util.AppContext
|
|
|
|
+import com.swago.baseswago.util.BitmapUtils
|
|
|
|
+import com.swago.baseswago.util.DianJiuUtil
|
|
import com.swago.formatAr
|
|
import com.swago.formatAr
|
|
import com.swago.room.R
|
|
import com.swago.room.R
|
|
import com.swago.room.adapter.bitmap.CenterAlignImageSpan
|
|
import com.swago.room.adapter.bitmap.CenterAlignImageSpan
|
|
@@ -48,6 +52,7 @@ class RoomChatAdapter :
|
|
|
|
|
|
companion object {
|
|
companion object {
|
|
const val LEVEL_KEY = "level"
|
|
const val LEVEL_KEY = "level"
|
|
|
|
+ const val BADGE_KEY = "badge"
|
|
const val PRETTY_KEY = "pretty"//靓号
|
|
const val PRETTY_KEY = "pretty"//靓号
|
|
const val VIP_KEY = "vip"//每日首冲
|
|
const val VIP_KEY = "vip"//每日首冲
|
|
const val IS_OFFICIAL = "official"
|
|
const val IS_OFFICIAL = "official"
|
|
@@ -60,6 +65,7 @@ class RoomChatAdapter :
|
|
|
|
|
|
init {
|
|
init {
|
|
localImageKey.add(LEVEL_KEY)
|
|
localImageKey.add(LEVEL_KEY)
|
|
|
|
+ localImageKey.add(BADGE_KEY)
|
|
localImageKey.add(PRETTY_KEY)
|
|
localImageKey.add(PRETTY_KEY)
|
|
localImageKey.add(VIP_KEY)
|
|
localImageKey.add(VIP_KEY)
|
|
localImageKey.add(IS_OFFICIAL)
|
|
localImageKey.add(IS_OFFICIAL)
|
|
@@ -72,6 +78,9 @@ class RoomChatAdapter :
|
|
|
|
|
|
var showUserInfoDialog: ((iChatMsg: IRoomChat) -> Unit)? = null
|
|
var showUserInfoDialog: ((iChatMsg: IRoomChat) -> Unit)? = null
|
|
|
|
|
|
|
|
+ fun setChatAndBadge(chatDrawable: NinePatchDrawable , badgeBitmap: Bitmap){
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
override fun convert(helper: BaseViewHolder, item: IRoomChat) {
|
|
override fun convert(helper: BaseViewHolder, item: IRoomChat) {
|
|
var count = 0
|
|
var count = 0
|
|
@@ -137,6 +146,12 @@ class RoomChatAdapter :
|
|
.append("'> ")
|
|
.append("'> ")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (item is RoomChatMsgBean && !item.badge_special.isNullOrEmpty()) {
|
|
|
|
+ count++
|
|
|
|
+ sb.append("<img src='" + "file:///xx/")
|
|
|
|
+ .append(BADGE_KEY).append(".png")
|
|
|
|
+ .append("'> ")
|
|
|
|
+ }
|
|
count++
|
|
count++
|
|
sb.append("<img src='" + "file:///xx/")
|
|
sb.append("<img src='" + "file:///xx/")
|
|
.append(LEVEL_KEY).append(".png")
|
|
.append(LEVEL_KEY).append(".png")
|
|
@@ -149,7 +164,7 @@ class RoomChatAdapter :
|
|
val glideImageGetter = HtmlImageGetter(mContext, tvContent, 14, localImageKey)
|
|
val glideImageGetter = HtmlImageGetter(mContext, tvContent, 14, localImageKey)
|
|
val fromHtml = Html.fromHtml(sb.toString(), glideImageGetter, null)
|
|
val fromHtml = Html.fromHtml(sb.toString(), glideImageGetter, null)
|
|
span = SpannableString(fromHtml)
|
|
span = SpannableString(fromHtml)
|
|
- setHtml(span, helper, item)
|
|
|
|
|
|
+ setHtml(span, helper, item,tvContent)
|
|
|
|
|
|
|
|
|
|
if (span.length < item.getSenderName().length + count) {
|
|
if (span.length < item.getSenderName().length + count) {
|
|
@@ -190,6 +205,15 @@ class RoomChatAdapter :
|
|
}else{
|
|
}else{
|
|
setBackgroundRes(R.id.tvContent, R.drawable.shape_20000000_14)
|
|
setBackgroundRes(R.id.tvContent, R.drawable.shape_20000000_14)
|
|
}
|
|
}
|
|
|
|
+ mContext?.let {
|
|
|
|
+ if (item is RoomChatMsgBean&&!item.android_chat_special.isNullOrEmpty()){
|
|
|
|
+ DianJiuUtil.loadDian9Tu(it ,item.android_chat_special ){ drawable ->
|
|
|
|
+ drawable?.let { drawable ->
|
|
|
|
+ tvContent.background = drawable
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
RoomMsgType.SYSTEM_MESSAGE -> {
|
|
RoomMsgType.SYSTEM_MESSAGE -> {
|
|
@@ -274,7 +298,7 @@ class RoomChatAdapter :
|
|
val glideImageGetter = HtmlImageGetter(mContext, tvContent, 14, localImageKey)
|
|
val glideImageGetter = HtmlImageGetter(mContext, tvContent, 14, localImageKey)
|
|
val fromHtml = Html.fromHtml(sb.toString(), glideImageGetter, null)
|
|
val fromHtml = Html.fromHtml(sb.toString(), glideImageGetter, null)
|
|
span = SpannableString(fromHtml)
|
|
span = SpannableString(fromHtml)
|
|
- setHtml(span, helper, item)
|
|
|
|
|
|
+ setHtml(span, helper, item,tvContent)
|
|
|
|
|
|
if (span.length < item.getSenderName().length + count) {
|
|
if (span.length < item.getSenderName().length + count) {
|
|
span.setSpan(
|
|
span.setSpan(
|
|
@@ -366,6 +390,13 @@ class RoomChatAdapter :
|
|
.append("'> ")
|
|
.append("'> ")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (item is UserJoinRoomBean && !item.androidBadgeSpecial.isNullOrEmpty()) {
|
|
|
|
+ count++
|
|
|
|
+ sb.append("<img src='" + "file:///xx/")
|
|
|
|
+ .append(BADGE_KEY).append(".png")
|
|
|
|
+ .append("'> ")
|
|
|
|
+ }
|
|
|
|
+
|
|
count++
|
|
count++
|
|
sb.append("<img src='" + "file:///xx/")
|
|
sb.append("<img src='" + "file:///xx/")
|
|
.append(LEVEL_KEY).append(".png")
|
|
.append(LEVEL_KEY).append(".png")
|
|
@@ -378,7 +409,7 @@ class RoomChatAdapter :
|
|
val glideImageGetter = HtmlImageGetter(mContext, tvContent, 14, localImageKey)
|
|
val glideImageGetter = HtmlImageGetter(mContext, tvContent, 14, localImageKey)
|
|
val fromHtml = Html.fromHtml(sb.toString(), glideImageGetter, null)
|
|
val fromHtml = Html.fromHtml(sb.toString(), glideImageGetter, null)
|
|
span = SpannableString(fromHtml)
|
|
span = SpannableString(fromHtml)
|
|
- setHtml(span, helper, item)
|
|
|
|
|
|
+ setHtml(span, helper, item,tvContent)
|
|
|
|
|
|
if (span.length < item.getSenderName().length + count) {
|
|
if (span.length < item.getSenderName().length + count) {
|
|
span.setSpan(
|
|
span.setSpan(
|
|
@@ -432,8 +463,19 @@ class RoomChatAdapter :
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ mContext?.let {
|
|
|
|
+ if (item is UserJoinRoomBean&&!item.androidChatSpecial.isNullOrEmpty()){
|
|
|
|
+ DianJiuUtil.loadDian9Tu(it ,item.androidChatSpecial ){ drawable ->
|
|
|
|
+ drawable?.let { drawable ->
|
|
|
|
+ tvContent.background = drawable
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
tvContent.movementMethod = LinkMovementMethod.getInstance()
|
|
tvContent.movementMethod = LinkMovementMethod.getInstance()
|
|
tvContent.highlightColor = Color.TRANSPARENT
|
|
tvContent.highlightColor = Color.TRANSPARENT
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
@@ -445,7 +487,7 @@ class RoomChatAdapter :
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private fun setHtml(span: SpannableString, helper: BaseViewHolder, item: IRoomChat) {
|
|
|
|
|
|
+ private fun setHtml(span: SpannableString, helper: BaseViewHolder, item: IRoomChat, tvContent:TextView) {
|
|
try {
|
|
try {
|
|
val imageSpans = span.getSpans(0, span.length, ImageSpan::class.java)
|
|
val imageSpans = span.getSpans(0, span.length, ImageSpan::class.java)
|
|
var i = 0
|
|
var i = 0
|
|
@@ -526,7 +568,32 @@ class RoomChatAdapter :
|
|
end,
|
|
end,
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
)
|
|
)
|
|
- }else {
|
|
|
|
|
|
+ }else if (imageSpan.source != null && imageSpan!!.source!!.contains(BADGE_KEY)) {
|
|
|
|
+ if(item is UserJoinRoomBean && !TextUtils.isEmpty(item.androidBadgeSpecial)){
|
|
|
|
+ BitmapUtils.loadFile(AppContext.getContext(),item.androidBadgeSpecial){
|
|
|
|
+ it?.let {
|
|
|
|
+ span.setSpan(
|
|
|
|
+ setBadge(it, helper.itemView as ViewGroup),
|
|
|
|
+ start,
|
|
|
|
+ end,
|
|
|
|
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } else if (item is RoomChatMsgBean && !TextUtils.isEmpty(item.badge_special)){
|
|
|
|
+ BitmapUtils.loadFile(AppContext.getContext(),item.badge_special){
|
|
|
|
+ it?.let {
|
|
|
|
+ span.setSpan(
|
|
|
|
+ setBadge(it, helper.itemView as ViewGroup),
|
|
|
|
+ start,
|
|
|
|
+ end,
|
|
|
|
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }else {
|
|
span.setSpan(newImageSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
span.setSpan(newImageSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
}
|
|
}
|
|
span.removeSpan(imageSpan)
|
|
span.removeSpan(imageSpan)
|
|
@@ -723,6 +790,11 @@ class RoomChatAdapter :
|
|
return CustomImageSpan(mContext, bm, CustomImageSpan.ALIGN_FONTCENTER)
|
|
return CustomImageSpan(mContext, bm, CustomImageSpan.ALIGN_FONTCENTER)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun setBadge(bitmap: Bitmap,viewGroup: ViewGroup): CustomImageSpan {
|
|
|
|
+ val imageView = ImageView(mContext)
|
|
|
|
+ viewGroup.addView(imageView)
|
|
|
|
+ return CustomImageSpan(mContext, bitmap, CustomImageSpan.ALIGN_FONTCENTER)
|
|
|
|
+ }
|
|
|
|
|
|
private fun setLevel(iSenderLevel: Int, viewGroup: ViewGroup): CustomImageSpan {
|
|
private fun setLevel(iSenderLevel: Int, viewGroup: ViewGroup): CustomImageSpan {
|
|
var level = iSenderLevel.toString()
|
|
var level = iSenderLevel.toString()
|