|
@@ -2,7 +2,7 @@ package com.swago.room.adapter
|
|
|
|
|
|
import android.graphics.Bitmap
|
|
|
import android.graphics.Color
|
|
|
-import android.graphics.drawable.BitmapDrawable
|
|
|
+import android.graphics.drawable.NinePatchDrawable
|
|
|
import android.os.Build
|
|
|
import android.text.*
|
|
|
import android.text.method.LinkMovementMethod
|
|
@@ -18,7 +18,6 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|
|
import androidx.core.content.ContextCompat
|
|
|
import com.chad.library.adapter.base.BaseQuickAdapter
|
|
|
import com.chad.library.adapter.base.BaseViewHolder
|
|
|
-import com.swago.baseswago.baseroom.SwagoRoomManager
|
|
|
import com.swago.baseswago.cusview.LiangView
|
|
|
import com.swago.baseswago.cusview.SwagoLevelView
|
|
|
import com.swago.baseswago.im.IRoomChat
|
|
@@ -27,8 +26,9 @@ import com.swago.baseswago.model.im.FollowSuccessMsgBean
|
|
|
import com.swago.baseswago.model.im.IMLevelUpMsgBean
|
|
|
import com.swago.baseswago.model.im.RoomChatMsgBean
|
|
|
import com.swago.baseswago.model.im.UserJoinRoomBean
|
|
|
+import com.swago.baseswago.util.AppContext
|
|
|
import com.swago.baseswago.util.BitmapUtils
|
|
|
-import com.swago.baseswago.util.UserInfo
|
|
|
+import com.swago.baseswago.util.DianJiuUtil
|
|
|
import com.swago.formatAr
|
|
|
import com.swago.room.R
|
|
|
import com.swago.room.adapter.bitmap.CenterAlignImageSpan
|
|
@@ -49,15 +49,6 @@ class RoomChatAdapter :
|
|
|
*/
|
|
|
private val iconBitmapCachePool: HashMap<String, Bitmap> = HashMap()
|
|
|
private val localImageKey = ArrayList<String>()
|
|
|
- private val badgeBitmap by lazy {
|
|
|
- BitmapUtils.getBitmapFromPath(UserInfo.getUserInfo()?.badge_special)
|
|
|
- }
|
|
|
- private val bubbleChat by lazy {
|
|
|
- BitmapUtils.getBitmapFromPath(UserInfo.getUserInfo()?.chat_special)
|
|
|
- }
|
|
|
- private val userid by lazy {
|
|
|
- UserInfo.getUserInfo()?.id
|
|
|
- }
|
|
|
|
|
|
companion object {
|
|
|
const val LEVEL_KEY = "level"
|
|
@@ -87,6 +78,9 @@ class RoomChatAdapter :
|
|
|
|
|
|
var showUserInfoDialog: ((iChatMsg: IRoomChat) -> Unit)? = null
|
|
|
|
|
|
+ fun setChatAndBadge(chatDrawable: NinePatchDrawable , badgeBitmap: Bitmap){
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
override fun convert(helper: BaseViewHolder, item: IRoomChat) {
|
|
|
var count = 0
|
|
@@ -152,6 +146,12 @@ class RoomChatAdapter :
|
|
|
.append("'> ")
|
|
|
}
|
|
|
|
|
|
+ if (item is RoomChatMsgBean && !item.badge_special.isNullOrEmpty()) {
|
|
|
+ count++
|
|
|
+ sb.append("<img src='" + "file:///xx/")
|
|
|
+ .append(BADGE_KEY).append(".png")
|
|
|
+ .append("'> ")
|
|
|
+ }
|
|
|
count++
|
|
|
sb.append("<img src='" + "file:///xx/")
|
|
|
.append(LEVEL_KEY).append(".png")
|
|
@@ -164,7 +164,7 @@ class RoomChatAdapter :
|
|
|
val glideImageGetter = HtmlImageGetter(mContext, tvContent, 14, localImageKey)
|
|
|
val fromHtml = Html.fromHtml(sb.toString(), glideImageGetter, null)
|
|
|
span = SpannableString(fromHtml)
|
|
|
- setHtml(span, helper, item)
|
|
|
+ setHtml(span, helper, item,tvContent)
|
|
|
|
|
|
|
|
|
if (span.length < item.getSenderName().length + count) {
|
|
@@ -205,6 +205,15 @@ class RoomChatAdapter :
|
|
|
}else{
|
|
|
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 -> {
|
|
@@ -289,7 +298,7 @@ class RoomChatAdapter :
|
|
|
val glideImageGetter = HtmlImageGetter(mContext, tvContent, 14, localImageKey)
|
|
|
val fromHtml = Html.fromHtml(sb.toString(), glideImageGetter, null)
|
|
|
span = SpannableString(fromHtml)
|
|
|
- setHtml(span, helper, item)
|
|
|
+ setHtml(span, helper, item,tvContent)
|
|
|
|
|
|
if (span.length < item.getSenderName().length + count) {
|
|
|
span.setSpan(
|
|
@@ -381,7 +390,7 @@ class RoomChatAdapter :
|
|
|
.append("'> ")
|
|
|
}
|
|
|
|
|
|
- if (item is UserJoinRoomBean && badgeBitmap != null) {
|
|
|
+ if (item is UserJoinRoomBean && !item.androidBadgeSpecial.isNullOrEmpty()) {
|
|
|
count++
|
|
|
sb.append("<img src='" + "file:///xx/")
|
|
|
.append(BADGE_KEY).append(".png")
|
|
@@ -400,7 +409,7 @@ class RoomChatAdapter :
|
|
|
val glideImageGetter = HtmlImageGetter(mContext, tvContent, 14, localImageKey)
|
|
|
val fromHtml = Html.fromHtml(sb.toString(), glideImageGetter, null)
|
|
|
span = SpannableString(fromHtml)
|
|
|
- setHtml(span, helper, item)
|
|
|
+ setHtml(span, helper, item,tvContent)
|
|
|
|
|
|
if (span.length < item.getSenderName().length + count) {
|
|
|
span.setSpan(
|
|
@@ -456,9 +465,7 @@ class RoomChatAdapter :
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- if (bubbleChat != null && item.getSenderId() == userid){
|
|
|
- tvContent.background = BitmapDrawable(mContext.resources , bubbleChat)
|
|
|
- }
|
|
|
+
|
|
|
tvContent.movementMethod = LinkMovementMethod.getInstance()
|
|
|
tvContent.highlightColor = Color.TRANSPARENT
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
@@ -470,7 +477,7 @@ class RoomChatAdapter :
|
|
|
}
|
|
|
|
|
|
|
|
|
- private fun setHtml(span: SpannableString, helper: BaseViewHolder, item: IRoomChat) {
|
|
|
+ private fun setHtml(span: SpannableString, helper: BaseViewHolder, item: IRoomChat, tvContent:TextView) {
|
|
|
try {
|
|
|
val imageSpans = span.getSpans(0, span.length, ImageSpan::class.java)
|
|
|
var i = 0
|
|
@@ -552,12 +559,30 @@ class RoomChatAdapter :
|
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
|
)
|
|
|
}else if (imageSpan.source != null && imageSpan!!.source!!.contains(BADGE_KEY)) {
|
|
|
- span.setSpan(
|
|
|
- setBadge(helper.itemView as ViewGroup),
|
|
|
- start,
|
|
|
- end,
|
|
|
- Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
|
- )
|
|
|
+ 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)
|
|
|
}
|
|
@@ -755,10 +780,10 @@ class RoomChatAdapter :
|
|
|
return CustomImageSpan(mContext, bm, CustomImageSpan.ALIGN_FONTCENTER)
|
|
|
}
|
|
|
|
|
|
- private fun setBadge(viewGroup: ViewGroup): CustomImageSpan {
|
|
|
+ private fun setBadge(bitmap: Bitmap,viewGroup: ViewGroup): CustomImageSpan {
|
|
|
val imageView = ImageView(mContext)
|
|
|
viewGroup.addView(imageView)
|
|
|
- return CustomImageSpan(mContext, badgeBitmap, CustomImageSpan.ALIGN_FONTCENTER)
|
|
|
+ return CustomImageSpan(mContext, bitmap, CustomImageSpan.ALIGN_FONTCENTER)
|
|
|
}
|
|
|
|
|
|
private fun setLevel(iSenderLevel: Int, viewGroup: ViewGroup): CustomImageSpan {
|