Pārlūkot izejas kodu

fix: join animal peek

tongmengxiao 5 mēneši atpakaļ
vecāks
revīzija
00e9fe3cd4

+ 8 - 1
room/src/main/java/com/swago/room/base/BaseComFragment.kt

@@ -79,6 +79,7 @@ import com.swago.room.hongbao.RedEnvelopeDialog
 import com.swago.room.inter.IFooter
 import com.swago.room.inter.IHeader
 import com.swago.room.lianmai.LianMaiVm
+import com.swago.room.manager.JoinAnimalManager
 import com.swago.room.piaotiao.WaftManager
 import com.swago.room.pk.IPKListener
 import com.swago.room.pk.PKStateManager
@@ -163,6 +164,10 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
         SvgPlayerManager()
     }
 
+    private val joinAnimalManager by lazy {
+        JoinAnimalManager()
+    }
+
     private val waftManager by lazy {
         WaftManager()
     }
@@ -227,6 +232,7 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
         chatAdapter.setNewData(dataChatList)
         context?.let {
             svgPlayerManager.init(it, binding.xSvgaPlayer, binding.svgDanDaoView)
+            joinAnimalManager.init(it, binding.xSvgaPlayer)
         }
 
         activity?.let {
@@ -642,7 +648,8 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
         }
 
         msgVm.joinRoomFun = {
-            binding.xSvgaPlayer.playJoinRoomSvga(it.androidJoinSpecial)
+            //svg播放
+            joinAnimalManager.addSvgUrl(it)
         }
 
         userVm.userInfoLiveData.observe(this) {

+ 4 - 3
room/src/main/java/com/swago/room/gift/control/XSvgPlayer.kt

@@ -10,6 +10,7 @@ import com.opensource.svgaplayer.SVGACallback
 import com.opensource.svgaplayer.SVGADrawable
 import com.opensource.svgaplayer.SVGAParser
 import com.opensource.svgaplayer.SVGAVideoEntity
+import com.swago.baseswago.model.im.UserJoinRoomBean
 import com.swago.baseswago.model.live.gift.IMGiftModel
 import com.swago.baseswago.util.LogUtil
 import com.swago.room.databinding.ViewSvgaBinding
@@ -85,13 +86,13 @@ class XSvgPlayer : ConstraintLayout {
         }
     }
 
-    fun playJoinRoomSvga(svgaUrl:String?){
-        if (svgaUrl.isNullOrEmpty()){
+    fun playJoinRoomSvga(userJoinRoomBean: UserJoinRoomBean?){
+        if (userJoinRoomBean == null || userJoinRoomBean.androidJoinSpecial.isNullOrEmpty()){
             return
         }
         svgaParser!!.let {
             LogUtil.d("svgPlayer","xxx--$isPlaying")
-            it.decodeFromURL(URL(svgaUrl),object:SVGAParser.ParseCompletion{
+            it.decodeFromURL(URL(userJoinRoomBean.androidJoinSpecial),object:SVGAParser.ParseCompletion{
                 override fun onComplete(videoItem: SVGAVideoEntity) {
                     binding!!.apply {
                         val drawable = SVGADrawable(videoItem)

+ 82 - 0
room/src/main/java/com/swago/room/manager/JoinAnimalManager.kt

@@ -0,0 +1,82 @@
+package com.swago.room.manager
+
+import android.content.Context
+import com.opensource.svgaplayer.SVGAParser
+import com.swago.baseswago.baseroom.IRoomActiveListener
+import com.swago.baseswago.baseroom.IRoomInfo
+import com.swago.baseswago.baseroom.SwagoRoomManager
+import com.swago.baseswago.model.im.UserJoinRoomBean
+import com.swago.baseswago.model.live.gift.IMGiftModel
+import com.swago.baseswago.util.LogUtil
+import com.swago.room.gift.control.XSvgPlayer
+import java.util.*
+
+/**
+ *@date 2021/12/11 16:42
+ *description:
+ */
+class JoinAnimalManager : IRoomActiveListener {
+
+    private val svgListQueue = LinkedList<UserJoinRoomBean>()
+    private var xSvgPlayer: XSvgPlayer? = null
+
+    fun init(context: Context, xSvgPlayer: XSvgPlayer) {
+        SVGAParser.shareParser().init(context)
+        this.xSvgPlayer = xSvgPlayer
+        SwagoRoomManager.addListener(this)
+
+        this.xSvgPlayer?.nextSvgPlay = {
+            svgListQueue.poll()
+            val uerJoinRoomBean = svgListQueue.peek()
+            LogUtil.d("SvgPlayerManager","${svgListQueue.size}")
+            if (uerJoinRoomBean==null){
+                LogUtil.d("SvgPlayerManager","clear svgListQueue")
+                svgListQueue.clear()
+            }else{
+                if (this.xSvgPlayer==null){
+                    svgListQueue.clear()
+                    LogUtil.d("SvgPlayerManager","xSvgPlayer 为空")
+                }else{
+                    this.xSvgPlayer!!.playJoinRoomSvga(uerJoinRoomBean)
+                }
+
+            }
+        }
+    }
+
+    override fun changeRoom(iRoomInfo: IRoomInfo) {
+        svgListQueue.clear()
+        xSvgPlayer?.clear()
+    }
+
+    override fun leaveRoom(iRoomInfo: IRoomInfo) {
+        svgListQueue.clear()
+        xSvgPlayer?.clear()
+    }
+
+    override fun joinedRoom(iRoomInfo: IRoomInfo) {
+
+    }
+
+    override fun endRoom(iRoomInfo: IRoomInfo?) {
+
+    }
+
+    override fun closeRoomed() {
+        svgListQueue.clear()
+        xSvgPlayer?.clear()
+        SwagoRoomManager.removeListener(this)
+    }
+
+    fun addSvgUrl(userJoinRoomBean: UserJoinRoomBean?) {
+        userJoinRoomBean?.let {
+            if (svgListQueue.isEmpty()) {
+                LogUtil.d("SvgPlayerManager","数据源没有数据 新增一条")
+                svgListQueue.add(it)
+                this.xSvgPlayer?.playJoinRoomSvga(it)
+            } else {
+                svgListQueue.add(it)
+            }
+        }
+    }
+}