Selaa lähdekoodia

feat: 聊天气泡

tongmengxiao 4 kuukautta sitten
vanhempi
commit
62b2697e8c

+ 44 - 0
baseswago/src/main/java/com/swago/baseswago/model/MomentModel.java

@@ -33,6 +33,10 @@ public class MomentModel implements Parcelable {
     private int is_cup;
     private int user_broadcast_type; //直播间类型(1视频2语音)
     private int broadcast_password_status;//是否密码房(1是0否)
+    private String head_special;
+    private String badge_special;
+    private String join_special;
+    private String chat_special;
 
     public MomentModel(){
 
@@ -55,6 +59,10 @@ public class MomentModel implements Parcelable {
         is_cup = in.readInt();
         user_broadcast_type = in.readInt();
         broadcast_password_status = in.readInt();
+        head_special = in.readString();
+        badge_special = in.readString();
+        join_special = in.readString();
+        chat_special = in.readString();
     }
 
     @Override
@@ -75,6 +83,10 @@ public class MomentModel implements Parcelable {
         dest.writeInt(is_cup);
         dest.writeInt(user_broadcast_type);
         dest.writeInt(broadcast_password_status);
+        dest.writeString(head_special);
+        dest.writeString(badge_special);
+        dest.writeString(join_special);
+        dest.writeString(chat_special);
     }
 
     @Override
@@ -237,4 +249,36 @@ public class MomentModel implements Parcelable {
     public void setBroadcast_password_status(int broadcast_password_status) {
         this.broadcast_password_status = broadcast_password_status;
     }
+
+    public String getHead_special() {
+        return head_special;
+    }
+
+    public void setHead_special(String head_special) {
+        this.head_special = head_special;
+    }
+
+    public String getBadge_special() {
+        return badge_special;
+    }
+
+    public void setBadge_special(String badge_special) {
+        this.badge_special = badge_special;
+    }
+
+    public String getJoin_special() {
+        return join_special;
+    }
+
+    public void setJoin_special(String join_special) {
+        this.join_special = join_special;
+    }
+
+    public String getChat_special() {
+        return chat_special;
+    }
+
+    public void setChat_special(String chat_special) {
+        this.chat_special = chat_special;
+    }
 }

+ 42 - 0
baseswago/src/main/java/com/swago/baseswago/util/BitmapUtils.kt

@@ -5,9 +5,14 @@ import android.content.Context
 import android.graphics.Bitmap
 import android.graphics.BitmapFactory
 import android.graphics.drawable.Drawable
+import android.graphics.drawable.NinePatchDrawable
 import android.text.TextUtils
 import com.bumptech.glide.Glide
+import com.bumptech.glide.load.DataSource
+import com.bumptech.glide.load.engine.GlideException
+import com.bumptech.glide.request.RequestListener
 import com.bumptech.glide.request.target.CustomTarget
+import com.bumptech.glide.request.target.Target
 import com.bumptech.glide.request.transition.Transition
 import com.swago.baseswago.constant.UrlConstant
 import com.swago.baseswago.inter.ApiManager
@@ -64,4 +69,41 @@ object BitmapUtils {
                 }
             })
     }
+
+    fun loadFile(context: Context, url:String, size:Int,response: ((resource: Bitmap?) -> Unit)?=null){
+        Glide.with(context)
+            .asBitmap()
+            .override(size)
+            .load(url)
+            .listener(object : RequestListener<Bitmap>{
+                override fun onLoadFailed(
+                    p0: GlideException?,
+                    p1: Any?,
+                    p2: Target<Bitmap>?,
+                    p3: Boolean
+                ): Boolean {
+                    response?.invoke(null)
+                    return false
+                }
+
+                override fun onResourceReady(
+                    bitmap: Bitmap?,
+                    p1: Any?,
+                    p2: Target<Bitmap>?,
+                    p3: DataSource?,
+                    p4: Boolean
+                ): Boolean {
+                    return false
+                }
+            } )
+            .into(object : CustomTarget<Bitmap>() {
+                override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
+                    response?.invoke(resource)
+                }
+
+                override fun onLoadCleared(placeholder: Drawable?) {
+
+                }
+            })
+    }
 }

BIN
baseswago/src/main/res/mipmap-xxhdpi/bg_chat_purple.9.png


BIN
baseswago/src/main/res/mipmap-xxhdpi/bg_chat_white.9.png


+ 16 - 9
home/src/main/java/com/swago/home/ChatDetailActivity.kt

@@ -127,21 +127,28 @@ class ChatDetailActivity  : BaseXActivity<ActivityChatDetailBinding>() {
             }
         })
 
-        UserInfo.getUserInfo()?.chat_special?.let {chatUrl ->
-            DianJiuUtil.loadDian9Tu(this ,chatUrl ){ drawable ->
-                drawable?.let {
-                    messageRecyclerView.rightBubble = it
+        if (UserInfo.getUserInfo() != null && !TextUtils.isEmpty(UserInfo.getUserInfo()?.chat_special)){
+            UserInfo.getUserInfo()?.chat_special?.let {chatUrl ->
+                DianJiuUtil.loadDian9Tu(this ,chatUrl ){ drawable ->
+                    drawable?.let {
+                        messageRecyclerView.rightBubble = it
+                    }
                 }
             }
+        } else {
+            messageRecyclerView.rightBubble = ContextCompat.getDrawable(this ,R.mipmap.bg_chat_white)
         }
 
-            if (!TextUtils.isEmpty(chatSpecial)){
-                DianJiuUtil.loadDian9Tu(this ,chatSpecial ){ drawable ->
-                    drawable?.let {
-                        messageRecyclerView.leftBubble = it
-                    }
+        if (!TextUtils.isEmpty(chatSpecial)){
+            DianJiuUtil.loadDian9Tu(this ,chatSpecial ){ drawable ->
+                drawable?.let {
+                    messageRecyclerView.leftBubble = it
                 }
             }
+        } else {
+            messageRecyclerView.leftBubble = ContextCompat.getDrawable(this ,R.mipmap.bg_chat_purple)
+
+        }
 
 
     }

+ 15 - 16
home/src/main/java/com/swago/home/MineFragment.kt

@@ -28,10 +28,12 @@ class MineFragment : BaseXFragment<FragmentMineBinding>() {
 
     private val userVm by viewModels<UserVm>()
     private val payVm by viewModels<PayVm>()
+    private var svgaParser:SVGAParser? = null
     override fun loadData() {
     }
 
     override fun initOther() {
+        svgaParser = SVGAParser(activity)
         if (SwagoInfo.isGooglePackage()){
             binding.tvXWithdrawal.visibility = View.GONE
         }else{
@@ -42,22 +44,6 @@ class MineFragment : BaseXFragment<FragmentMineBinding>() {
             }
         }
 
-        UserInfo.getUserInfo()?.let {
-            if (!it.head_special.isNullOrEmpty()){
-                val svgaParser = SVGAParser(activity)
-                svgaParser.decodeFromURL(URL(it.head_special), object :SVGAParser.ParseCompletion{
-                    override fun onComplete(videoItem: SVGAVideoEntity) {
-                        val drawable = SVGADrawable(videoItem)
-                        binding.svgAvatar.setImageDrawable(drawable)
-                        binding.svgAvatar.startAnimation()
-                    }
-
-                    override fun onError() {
-                    }
-                })
-            }
-        }
-
         binding.llFans.setOnClickListener(object: NoDoubleClickListener(){
             override fun onClick() {
                 ARouter.getInstance()
@@ -230,6 +216,19 @@ class MineFragment : BaseXFragment<FragmentMineBinding>() {
             }else{
                 binding.tvModifyPassword.visibility = View.GONE
             }
+
+            if (!it.head_special.isNullOrEmpty()){
+                svgaParser?.decodeFromURL(URL(it.head_special), object :SVGAParser.ParseCompletion{
+                    override fun onComplete(videoItem: SVGAVideoEntity) {
+                        val drawable = SVGADrawable(videoItem)
+                        binding.svgAvatar.setImageDrawable(drawable)
+                        binding.svgAvatar.startAnimation()
+                    }
+
+                    override fun onError() {
+                    }
+                })
+            }
         }
 
         payVm.benefitLiveData.observe(this){

+ 9 - 23
room/src/main/java/com/swago/room/adapter/RoomChatAdapter.kt

@@ -210,7 +210,6 @@ class RoomChatAdapter :
                     }else{
                         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 ->
@@ -566,29 +565,16 @@ class RoomChatAdapter :
                     )
                 }else if (imageSpan.source != null && imageSpan!!.source!!.contains(BADGE_KEY)) {
                     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?) {
+                        BitmapUtils.loadFile(mContext,item.badgeSpecial,50){
+                            it?.let {
+                                span.setSpan(
+                                    setBadge(it, helper.itemView as ViewGroup),
+                                    start,
+                                    end,
+                                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+                            }
 
-                                }
-                            })
+                        }
                     }
 
             }else {

+ 15 - 3
room/src/main/java/com/swago/room/bean/UserRoomModel.kt

@@ -199,14 +199,26 @@ class UserRoomModel : IRoomInfo {
     }
 
     override fun getHeadSpecial(): String {
-        return roomModel?.head_special ?: ""
+        return if (RoleType.user == SwagoRoomManager.roleType) {
+            momentModel?.head_special ?: ""
+        } else {
+            roomModel?.head_special ?: ""
+        }
     }
 
     override fun getBadgeSpecial(): String {
-        return roomModel?.badge_special ?: ""
+        return if (RoleType.user == SwagoRoomManager.roleType) {
+            momentModel?.badge_special ?: ""
+        } else {
+            roomModel?.badge_special ?: ""
+        }
     }
 
     override fun getChatSpecial(): String {
-        return roomModel?.chat_special ?: ""
+        return if (RoleType.user == SwagoRoomManager.roleType) {
+            momentModel?.chat_special ?: ""
+        } else {
+            roomModel?.chat_special ?: ""
+        }
     }
 }

+ 42 - 0
room/src/main/java/com/swago/room/gift/control/XSvgPlayer.kt

@@ -85,6 +85,48 @@ class XSvgPlayer : ConstraintLayout {
         }
     }
 
+    fun playJoinRoomSvga(svgaUrl:String?){
+        if (svgaUrl.isNullOrEmpty()){
+            return
+        }
+        svgaParser!!.let {
+            LogUtil.d("svgPlayer","xxx--$isPlaying")
+            it.decodeFromURL(URL(svgaUrl),object:SVGAParser.ParseCompletion{
+                override fun onComplete(videoItem: SVGAVideoEntity) {
+                    binding!!.apply {
+                        val drawable = SVGADrawable(videoItem)
+                        svgaImageView.visibility = View.VISIBLE
+                        svgaImageView.setImageDrawable(drawable)
+                        svgaImageView.loops = 1
+                        svgaImageView.callback = callback
+                        LogUtil.d("svgPlayer","onComplete--$isPlaying")
+                        if (!isPlaying){
+                            svgaImageView.startAnimation()
+                            isPlaying = true
+                        }
+
+                    }
+
+                }
+
+                override fun onError() {
+                    binding?.apply {
+                        isPlaying = false
+                        LogUtil.d("svgPlayer","onError--$isPlaying")
+                        svgaImageView.visibility = View.GONE
+                        nextSvgPlay?.invoke()
+                    }
+                }
+            },object:SVGAParser.PlayCallback{
+                override fun onPlay(file: List<File>) {
+                    LogUtil.d("svgPlayer","onPlay--${file.size}")
+                }
+
+            })
+
+        }
+    }
+
     fun clear(){
         binding?.apply {
             isPlaying = false

+ 27 - 0
room/src/main/java/com/swago/room/manager/JoinRoomManager.kt

@@ -29,6 +29,7 @@ import com.swago.loadUrl
 import com.swago.room.R
 import de.hdodenhof.circleimageview.CircleImageView
 import java.io.File
+import java.net.URL
 import java.util.LinkedList
 
 class JoinRoomManager : IRoomActiveListener {
@@ -46,6 +47,7 @@ class JoinRoomManager : IRoomActiveListener {
     private var clBg: ConstraintLayout? = null
     private var clTwo: ConstraintLayout? = null
     private var clOne: LinearLayout? = null
+    private var svgaAvatar: SVGAImageView? = null
     private var animationSet: AnimatorSet? = null
     private val waitingTime = 1000L
 
@@ -70,6 +72,7 @@ class JoinRoomManager : IRoomActiveListener {
             swagoLevel = view.findViewById(R.id.swagoLevel)
             swagoLevelOne = view.findViewById(R.id.swagoLevelOne)
             joinRoomRootView = view.findViewById(R.id.rootView)
+            svgaAvatar = view.findViewById(R.id.svgAvatar)
             initViewAnimation()
             loopStart()
             SwagoRoomManager.addListener(this@JoinRoomManager)
@@ -120,6 +123,18 @@ class JoinRoomManager : IRoomActiveListener {
                 clBg?.setBackgroundResource(R.mipmap.join_ten_fourteen)
                 animationSet?.start()
                 joinRoomRootView?.visibility = View.VISIBLE
+                if (!userJoinRoomBean.headSpecial.isNullOrEmpty()) {
+                    svgParser?.decodeFromURL(URL(userJoinRoomBean.headSpecial), object :SVGAParser.ParseCompletion{
+                        override fun onComplete(videoItem: SVGAVideoEntity) {
+                            val drawable = SVGADrawable(videoItem)
+                            svgaAvatar?.setImageDrawable(drawable)
+                            svgaAvatar?.startAnimation()
+                        }
+
+                        override fun onError() {
+                        }
+                    })
+                }
             }
             in 15..19 -> {
                 clOne?.visibility = View.GONE
@@ -132,6 +147,18 @@ class JoinRoomManager : IRoomActiveListener {
                 clBg?.setBackgroundResource(R.mipmap.join_fifteen_nineteen)
                 animationSet?.start()
                 joinRoomRootView?.visibility = View.VISIBLE
+                if (!userJoinRoomBean.headSpecial.isNullOrEmpty()) {
+                    svgParser?.decodeFromURL(URL(userJoinRoomBean.headSpecial), object :SVGAParser.ParseCompletion{
+                        override fun onComplete(videoItem: SVGAVideoEntity) {
+                            val drawable = SVGADrawable(videoItem)
+                            svgaAvatar?.setImageDrawable(drawable)
+                            svgaAvatar?.startAnimation()
+                        }
+
+                        override fun onError() {
+                        }
+                    })
+                }
             }
             else -> {
                 clOne?.visibility = View.GONE

+ 1 - 0
room/src/main/java/com/swago/room/user/UserRoomFragment.kt

@@ -246,6 +246,7 @@ class UserRoomFragment : BaseComFragment<FragmentBaseComBinding>() {
     override fun joinedRoom(iRoomInfo: IRoomInfo) {
         super.joinedRoom(iRoomInfo)
         SwagoRoomManager.iRoomInfo?.let {
+            binding.xSvgaPlayer.playJoinRoomSvga(iRoomInfo.getJoinSpecial())
             if (it.getAudioNotice().isNotEmpty()){
                 AudioNoticeUserDialog.newInstance().show(childFragmentManager,"AudioNoticeUserDialog")
             }

+ 6 - 1
room/src/main/java/com/swago/room/vm/MsgVm.kt

@@ -56,6 +56,7 @@ import com.swago.baseswago.model.live.WishGift
 import com.swago.baseswago.model.live.audio.*
 import com.swago.baseswago.model.live.gift.IMGiftModel
 import com.swago.baseswago.util.AppContext
+import com.swago.baseswago.util.BitmapUtils
 import com.swago.baseswago.util.UserInfo
 import com.swago.room.audio.AudioRoomManager
 import com.swago.room.audio.IAudioRoomListener
@@ -174,9 +175,13 @@ class MsgVm(application: Application) : AbsMsgVm(application) {
             ) {
                 if (SwagoRoomManager.roleType == RoleType.user || it.data?.senderCode != UserInfo.getUserInfo()?.user_account) {
                     it.data?.let {
-                        newChatMsgFun?.invoke(it)
                         updateHotValue?.invoke(it.hotValue)
                         joinRoomManager.addJoinRoomData(it)
+                        it.badgeSpecial?.let {badgeSpecial ->
+                            BitmapUtils.loadFile(AppContext.getContext() , badgeSpecial, 50){ bitmap ->
+                                newChatMsgFun?.invoke(it)
+                            }
+                        }
                     }
                 }
             }

+ 31 - 10
room/src/main/res/layout/view_user_join_room.xml

@@ -76,28 +76,49 @@
             android:layout_width="260dp"
             android:layout_height="60dp">
 
-            <de.hdodenhof.circleimageview.CircleImageView
-                android:id="@+id/ivAvatar"
+            <androidx.constraintlayout.widget.ConstraintLayout
+                android:id="@+id/clAvatar"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
                 app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintTop_toTopOf="parent"
                 app:layout_constraintBottom_toBottomOf="parent"
-                android:layout_marginStart="12dp"
-                android:layout_width="36dp"
-                android:layout_height="36dp"/>
+                android:layout_marginStart="8dp">
+                <de.hdodenhof.circleimageview.CircleImageView
+                    android:id="@+id/ivAvatar"
+                    app:layout_constraintStart_toStartOf="parent"
+                    app:layout_constraintTop_toTopOf="parent"
+                    app:layout_constraintBottom_toBottomOf="parent"
+                    app:layout_constraintEnd_toEndOf="parent"
+                    android:layout_width="36dp"
+                    android:layout_height="36dp"/>
+                <com.opensource.svgaplayer.SVGAImageView
+                    android:id="@+id/svgAvatar"
+                    android:layout_width="44dp"
+                    android:layout_height="44dp"
+                    android:visibility="visible"
+                    app:autoPlay="true"
+                    app:loopCount="0"
+                    app:layout_constraintStart_toStartOf="parent"
+                    app:layout_constraintTop_toTopOf="parent"
+                    app:layout_constraintEnd_toEndOf="parent"
+                    app:layout_constraintBottom_toBottomOf="parent"/>
+            </androidx.constraintlayout.widget.ConstraintLayout>
+
 
 
             <com.swago.baseswago.cusview.SwagoLevelView
                 android:id="@+id/swagoLevel"
                 android:layout_marginStart="5dp"
-                app:layout_constraintStart_toEndOf="@+id/ivAvatar"
-                app:layout_constraintTop_toTopOf="@+id/ivAvatar"
+                app:layout_constraintStart_toEndOf="@+id/clAvatar"
+                app:layout_constraintTop_toTopOf="@+id/clAvatar"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"/>
 
             <TextView
                 android:id="@+id/tvName"
                 app:layout_constraintStart_toEndOf="@+id/swagoLevel"
-                app:layout_constraintTop_toTopOf="@+id/ivAvatar"
+                app:layout_constraintTop_toTopOf="@+id/clAvatar"
                 android:layout_marginStart="5dp"
                 android:layout_marginEnd="20dp"
                 android:textSize="12dp"
@@ -110,8 +131,8 @@
 
             <TextView
                 android:id="@+id/tvJoin"
-                app:layout_constraintStart_toEndOf="@+id/ivAvatar"
-                app:layout_constraintBottom_toBottomOf="@+id/ivAvatar"
+                app:layout_constraintStart_toEndOf="@+id/clAvatar"
+                app:layout_constraintBottom_toBottomOf="@+id/clAvatar"
                 android:layout_marginEnd="20dp"
                 android:layout_marginStart="5dp"
                 android:textSize="10dp"

+ 3 - 3
tuikit/src/main/res/layout/message_adapter_content_text.xml

@@ -3,7 +3,7 @@
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:gravity="center_vertical"
-    android:minHeight="36dp"
+    android:minHeight="31dp"
     android:orientation="horizontal">
 
     <TextView
@@ -14,8 +14,8 @@
         android:textColor="@color/black_font_color"
         android:paddingLeft="7dp"
         android:paddingRight="7dp"
-        android:paddingTop="10dp"
-        android:paddingBottom="10dp"
+        android:paddingTop="5dp"
+        android:paddingBottom="5dp"
         android:maxWidth="276dp"
         android:textSize="16.5sp" />
 </LinearLayout>

+ 19 - 10
user/src/main/java/com/swago/user/store/StoreBuyDialog.kt

@@ -51,19 +51,28 @@ class StoreBuyDialog : BaseXDFragment<DialogStoreDetailBinding>(){
         storeBean?.let {
             binding.tvName.text = it.product_name
             binding.tvCoin.text = "${it.product_coin}"
-            binding.ivIcon.visibility = if (it.product_url?.endsWith("svga") == true) View.GONE else View.VISIBLE
-            binding.ivIcon.loadUrl(AppContext.getContext(),it.product_url?:"")
-            svgaParser?.decodeFromURL(URL(it.product_url), object : SVGAParser.ParseCompletion{
-                override fun onComplete(videoItem: SVGAVideoEntity) {
-                    val drawable = SVGADrawable(videoItem)
-                    binding.svgContent.setImageDrawable(drawable)
-                    binding.svgContent.startAnimation()
-                }
+            if (!it.product_svg_url.isNullOrEmpty() && it.product_svg_url?.endsWith(".svga") == true){
+                binding.ivIcon.visibility = View.GONE
+                svgaParser?.decodeFromURL(URL(it.product_svg_url), object : SVGAParser.ParseCompletion{
+                    override fun onComplete(videoItem: SVGAVideoEntity) {
+                        val drawable = SVGADrawable(videoItem)
+                        binding.svgContent.setImageDrawable(drawable)
+                        binding.svgContent.startAnimation()
+                    }
 
-                override fun onError() {
+                    override fun onError() {
 
+                    }
+                })
+            } else {
+                binding.ivIcon.visibility = View.VISIBLE
+                it.product_url?.let { imageUrl ->
+                    binding.ivIcon.loadUrl(AppContext.getContext(),imageUrl)
                 }
-            })
+            }
+
+
+
         }
     }
 

+ 1 - 1
user/src/main/res/layout/dialog_store_detail.xml

@@ -40,7 +40,7 @@
                 android:maxWidth="120dp"
                 android:textColor="#ffffff"
                 android:textSize="16sp"
-                android:layout_marginTop="@dimen/dp_4"
+                android:layout_marginTop="@dimen/dp_10"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintTop_toBottomOf="@+id/ivIcon"