|
@@ -3,6 +3,8 @@ 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.BitmapDrawable
|
|
import android.graphics.drawable.BitmapDrawable
|
|
|
|
+import android.graphics.drawable.Drawable
|
|
|
|
+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
|
|
@@ -16,9 +18,13 @@ 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.bumptech.glide.Glide
|
|
|
|
+import com.bumptech.glide.request.target.CustomTarget
|
|
|
|
+import com.bumptech.glide.request.transition.Transition
|
|
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.baseroom.SwagoRoomManager
|
|
|
|
+import com.swago.baseswago.constant.UrlConstant
|
|
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
|
|
@@ -36,6 +42,9 @@ import com.swago.room.R
|
|
import com.swago.room.adapter.bitmap.CenterAlignImageSpan
|
|
import com.swago.room.adapter.bitmap.CenterAlignImageSpan
|
|
import com.swago.room.adapter.bitmap.CustomImageSpan
|
|
import com.swago.room.adapter.bitmap.CustomImageSpan
|
|
import com.swago.room.adapter.bitmap.HtmlImageGetter
|
|
import com.swago.room.adapter.bitmap.HtmlImageGetter
|
|
|
|
+import java.io.File
|
|
|
|
+import java.io.FileOutputStream
|
|
|
|
+import java.io.IOException
|
|
import java.util.*
|
|
import java.util.*
|
|
import kotlin.collections.ArrayList
|
|
import kotlin.collections.ArrayList
|
|
|
|
|
|
@@ -51,16 +60,6 @@ class RoomChatAdapter :
|
|
*/
|
|
*/
|
|
private val iconBitmapCachePool: HashMap<String, Bitmap> = HashMap()
|
|
private val iconBitmapCachePool: HashMap<String, Bitmap> = HashMap()
|
|
private val localImageKey = ArrayList<String>()
|
|
private val localImageKey = ArrayList<String>()
|
|
- private val badgeBitmap by lazy {
|
|
|
|
- BitmapUtils.getBitmapFromPath(UserInfo.getUserInfo()?.badge_special)
|
|
|
|
- }
|
|
|
|
- private val bubbleChat by lazy {
|
|
|
|
- val path = "${AppContext.getContext().getExternalFilesDir(null)!!.path}/swagoFile/mmexport1718256766828.png"
|
|
|
|
- BitmapUtils.getBitmapFromPath(path)
|
|
|
|
- }
|
|
|
|
- private val userid by lazy {
|
|
|
|
- UserInfo.getUserInfo()?.id
|
|
|
|
- }
|
|
|
|
|
|
|
|
companion object {
|
|
companion object {
|
|
const val LEVEL_KEY = "level"
|
|
const val LEVEL_KEY = "level"
|
|
@@ -90,6 +89,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
|
|
@@ -167,7 +169,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) {
|
|
@@ -208,6 +210,16 @@ class RoomChatAdapter :
|
|
}else{
|
|
}else{
|
|
setBackgroundRes(R.id.tvContent, R.drawable.shape_20000000_14)
|
|
setBackgroundRes(R.id.tvContent, R.drawable.shape_20000000_14)
|
|
}
|
|
}
|
|
|
|
+ UserInfo.getUserInfo()?.chat_special = "https://apple-1304432552.cos.ap-shanghai.myqcloud.com/outdianjiu.png"
|
|
|
|
+ mContext?.let {
|
|
|
|
+ UserInfo.getUserInfo()?.chat_special?.let {chatUrl ->
|
|
|
|
+ DianJiuUtil.loadDian9Tu(it ,chatUrl ){ drawable ->
|
|
|
|
+ drawable?.let { drawable ->
|
|
|
|
+ tvContent.background = drawable
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
RoomMsgType.SYSTEM_MESSAGE -> {
|
|
RoomMsgType.SYSTEM_MESSAGE -> {
|
|
@@ -292,7 +304,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(
|
|
@@ -384,7 +396,7 @@ class RoomChatAdapter :
|
|
.append("'> ")
|
|
.append("'> ")
|
|
}
|
|
}
|
|
|
|
|
|
- if (item is UserJoinRoomBean && badgeBitmap != null) {
|
|
|
|
|
|
+ if (item is UserJoinRoomBean && !item.badgeSpecial.isNullOrEmpty()) {
|
|
count++
|
|
count++
|
|
sb.append("<img src='" + "file:///xx/")
|
|
sb.append("<img src='" + "file:///xx/")
|
|
.append(BADGE_KEY).append(".png")
|
|
.append(BADGE_KEY).append(".png")
|
|
@@ -403,7 +415,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(
|
|
@@ -459,12 +471,7 @@ class RoomChatAdapter :
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (item.getSenderId() == userid){
|
|
|
|
- bubbleChat?.let {
|
|
|
|
- tvContent.background = DianJiuUtil.setNinePatchImage(mContext , it)
|
|
|
|
- }
|
|
|
|
|
|
|
|
- }
|
|
|
|
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) {
|
|
@@ -476,7 +483,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
|
|
@@ -558,12 +565,32 @@ class RoomChatAdapter :
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
)
|
|
)
|
|
}else if (imageSpan.source != null && imageSpan!!.source!!.contains(BADGE_KEY)) {
|
|
}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.badgeSpecial)){
|
|
|
|
+ Glide.with(mContext)
|
|
|
|
+ .asBitmap()
|
|
|
|
+ .load(item.badgeSpecial)
|
|
|
|
+ .override(50)
|
|
|
|
+ .into(object : CustomTarget<Bitmap>() {
|
|
|
|
+ override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
|
|
|
|
+ span.setSpan(
|
|
|
|
+ setBadge(resource, helper.itemView as ViewGroup),
|
|
|
|
+ start,
|
|
|
|
+ end,
|
|
|
|
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
|
|
+ )
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
+ tvContent.text = span.formatAr()
|
|
|
|
+ }else{
|
|
|
|
+ tvContent.text = span
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onLoadCleared(placeholder: Drawable?) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
}else {
|
|
}else {
|
|
span.setSpan(newImageSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
span.setSpan(newImageSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
}
|
|
}
|
|
@@ -761,10 +788,10 @@ class RoomChatAdapter :
|
|
return CustomImageSpan(mContext, bm, CustomImageSpan.ALIGN_FONTCENTER)
|
|
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)
|
|
val imageView = ImageView(mContext)
|
|
viewGroup.addView(imageView)
|
|
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 {
|
|
private fun setLevel(iSenderLevel: Int, viewGroup: ViewGroup): CustomImageSpan {
|