Pārlūkot izejas kodu

入场特效更换

admin 1 gadu atpakaļ
vecāks
revīzija
6ced1cc2b2

BIN
room/src/main/assets/join_five.svga


BIN
room/src/main/assets/join_four.svga


BIN
room/src/main/assets/join_one.svga


BIN
room/src/main/assets/join_three.svga


BIN
room/src/main/assets/join_two.svga


+ 110 - 97
room/src/main/java/com/swago/room/manager/JoinRoomManager.kt

@@ -4,62 +4,72 @@ import android.animation.Animator
 import android.view.ViewStub
 import android.animation.AnimatorSet
 import android.animation.ObjectAnimator
-import android.util.Log
 import android.view.View
 import android.view.animation.AccelerateInterpolator
 import android.view.animation.DecelerateInterpolator
+import android.widget.ImageView
+import android.widget.LinearLayout
 import android.widget.TextView
+import android.widget.Toast
 import androidx.constraintlayout.widget.ConstraintLayout
 import androidx.fragment.app.FragmentActivity
-import com.airbnb.lottie.LottieAnimationView
-import com.airbnb.lottie.LottieComposition
-import com.airbnb.lottie.LottieCompositionFactory
+import com.opensource.svgaplayer.SVGADrawable
+import com.opensource.svgaplayer.SVGAImageView
+import com.opensource.svgaplayer.SVGAParser
+import com.opensource.svgaplayer.SVGAVideoEntity
 import com.swago.baseswago.baseroom.IRoomActiveListener
 import com.swago.baseswago.baseroom.IRoomInfo
 import com.swago.baseswago.baseroom.SwagoRoomManager
-import com.swago.baseswago.constant.UrlConstant
+import com.swago.baseswago.cusview.SwagoLevelView
 import com.swago.baseswago.model.im.UserJoinRoomBean
+import com.swago.baseswago.util.AppContext
 import com.swago.baseswago.util.DpPxUtil
-import com.swago.baseswago.util.FileUtil
 import com.swago.baseswago.util.SwagoInfo
 import com.swago.loadUrl
 import com.swago.room.R
 import de.hdodenhof.circleimageview.CircleImageView
 import java.io.File
-import java.io.FileInputStream
-import java.io.FileNotFoundException
 import java.util.LinkedList
-import java.util.zip.ZipInputStream
 
 class JoinRoomManager : IRoomActiveListener {
 
     private var mActivity: FragmentActivity? = null
     private var isRunning = false
-    private var lottieView: LottieAnimationView? = null
+    private var svgaImageView: SVGAImageView? = null
     private var tvName: TextView? = null
+    private var tvNameOne: TextView? = null
+    private var ivLevelLogo: ImageView? = null
+    private var swagoLevel: SwagoLevelView? = null
+    private var swagoLevelOne: SwagoLevelView? = null
     private var ivAvatar: CircleImageView? = null
     private var joinRoomRootView: ConstraintLayout? = null
     private var clBg: ConstraintLayout? = null
+    private var clTwo: ConstraintLayout? = null
+    private var clOne: LinearLayout? = null
     private var animationSet: AnimatorSet? = null
-    private var lottieMoto: LottieComposition? = null
-    private var lottieCar: LottieComposition? = null
-    private var lottieBoat: LottieComposition? = null
-    private var lottieRider: LottieComposition? = null
     private val waitingTime = 1000L
 
+    private var svgParser: SVGAParser? = null
+
     private var joinRoomList = LinkedList<UserJoinRoomBean>()
     private var canAddData = true
 
     fun initViewStub(viewStub: ViewStub?, activity: FragmentActivity?) {
         mActivity = activity
+        svgParser = SVGAParser(mActivity)
         viewStub?.apply {
             val view = this.inflate()
-            lottieView = view.findViewById(R.id.lottieView)
+            svgaImageView = view.findViewById(R.id.svgaImageView)
             clBg = view.findViewById(R.id.clBg)
+            clTwo = view.findViewById(R.id.clTwo)
+            clOne = view.findViewById(R.id.clOne)
             tvName = view.findViewById(R.id.tvName)
+            tvNameOne = view.findViewById(R.id.tvNameOne)
             ivAvatar = view.findViewById(R.id.ivAvatar)
+            ivLevelLogo = view.findViewById(R.id.ivLevelLogo)
+            swagoLevel = view.findViewById(R.id.swagoLevel)
+            swagoLevelOne = view.findViewById(R.id.swagoLevelOne)
             joinRoomRootView = view.findViewById(R.id.rootView)
-            initLottieComposition()
             initViewAnimation()
             loopStart()
             SwagoRoomManager.addListener(this@JoinRoomManager)
@@ -88,56 +98,85 @@ class JoinRoomManager : IRoomActiveListener {
 
     private fun playJoinRoomAnimation(userJoinRoomBean: UserJoinRoomBean) {
         isRunning = true
-        joinRoomRootView?.visibility = View.VISIBLE
-        mActivity?.let { ivAvatar?.loadUrl(it, userJoinRoomBean.userAvatar) }
-        tvName?.text = userJoinRoomBean.senderName
-        if (userJoinRoomBean.isBenefit == 1) {
-            if (lottieRider == null) {
-                isRunning = false
-            } else {
-                lottieRider?.let {
-                    clBg?.setBackgroundResource(R.drawable.shape_e87230_ddb558_all_20)
-                    lottieView?.setComposition(it)
-                    lottieView?.playAnimation()
-                    animationSet?.start()
-                }
+        ivLevelLogo?.visibility = View.GONE
+        clBg?.setBackgroundResource(android.R.color.transparent)
+        when(userJoinRoomBean.senderLevel){
+            in 0..9 ->{
+                clOne?.visibility = View.VISIBLE
+                clTwo?.visibility = View.GONE
+                tvNameOne?.text = userJoinRoomBean.senderName
+                swagoLevelOne?.setUserLevel(userJoinRoomBean.senderLevel)
+                animationSet?.start()
+                joinRoomRootView?.visibility = View.VISIBLE
             }
-        } else {
-            if (userJoinRoomBean.senderLevel in 20..39) {
-                if (lottieMoto == null) {
-                    isRunning = false
-                } else {
-                    lottieMoto?.let {
-                        clBg?.setBackgroundResource(R.drawable.shape_6720d1_180c72_20)
-                        lottieView?.setComposition(it)
-                        lottieView?.playAnimation()
-                        animationSet?.start()
-                    }
-                }
+            in 10..14 -> {
+                clOne?.visibility = View.GONE
+                clTwo?.visibility = View.VISIBLE
+                ivLevelLogo?.visibility = View.VISIBLE
+                ivLevelLogo?.setImageResource(R.mipmap.join_ten_logo)
+                mActivity?.let { ivAvatar?.loadUrl(it, userJoinRoomBean.userAvatar) }
+                tvName?.text = userJoinRoomBean.senderName
+                swagoLevel?.setUserLevel(userJoinRoomBean.senderLevel)
+                clBg?.setBackgroundResource(R.mipmap.join_ten_fourteen)
+                animationSet?.start()
+                joinRoomRootView?.visibility = View.VISIBLE
             }
-            if (userJoinRoomBean.senderLevel in 40..59) {
-                if (lottieCar == null) {
-                    isRunning = false
-                } else {
-                    lottieCar?.let {
-                        clBg?.setBackgroundResource(R.drawable.shape_f8614b_8c2922_20)
-                        lottieView?.setComposition(it)
-                        lottieView?.playAnimation()
-                        animationSet?.start()
-                    }
-                }
+            in 15..19 -> {
+                clOne?.visibility = View.GONE
+                clTwo?.visibility = View.VISIBLE
+                ivLevelLogo?.visibility = View.VISIBLE
+                ivLevelLogo?.setImageResource(R.mipmap.join_fifteen_logo)
+                mActivity?.let { ivAvatar?.loadUrl(it, userJoinRoomBean.userAvatar) }
+                tvName?.text = userJoinRoomBean.senderName
+                swagoLevel?.setUserLevel(userJoinRoomBean.senderLevel)
+                clBg?.setBackgroundResource(R.mipmap.join_fifteen_nineteen)
+                animationSet?.start()
+                joinRoomRootView?.visibility = View.VISIBLE
             }
+            else -> {
+                clOne?.visibility = View.GONE
+                clTwo?.visibility = View.VISIBLE
+                mActivity?.let { ivAvatar?.loadUrl(it, userJoinRoomBean.userAvatar) }
+                tvName?.text = userJoinRoomBean.senderName
+                swagoLevel?.setUserLevel(userJoinRoomBean.senderLevel)
 
-            if (userJoinRoomBean.senderLevel >= 60) {
-                if (lottieBoat == null) {
-                    isRunning = false
-                } else {
-                    lottieBoat?.let {
-                        clBg?.setBackgroundResource(R.drawable.shape_434343_000000_20)
-                        lottieView?.setComposition(it)
-                        lottieView?.playAnimation()
-                        animationSet?.start()
+                var path = ""
+                svgParser?.let {
+                    if (userJoinRoomBean.isBenefit == 1) {
+                        path = "join_four.svga"
+                    } else {
+                        if (userJoinRoomBean.senderLevel in 20..39) {
+                            path = "join_five.svga"
+                        }
+                        if (userJoinRoomBean.senderLevel in 40..59) {
+                            path = "join_three.svga"
+                        }
+                        if (userJoinRoomBean.senderLevel in 60..79) {
+                            path = "join_two.svga"
+                        }
+                        if (userJoinRoomBean.senderLevel >= 80) {
+                            path = "join_one.svga"
+                        }
                     }
+                    it.decodeFromAssets(path, object : SVGAParser.ParseCompletion {
+                        override fun onComplete(videoItem: SVGAVideoEntity) {
+                            val drawable = SVGADrawable(videoItem)
+                            svgaImageView?.setImageDrawable(drawable)
+                            svgaImageView?.loops = 99999
+                            animationSet?.start()
+                            svgaImageView?.startAnimation()
+                            joinRoomRootView?.visibility = View.VISIBLE
+                        }
+
+                        override fun onError() {
+                            Toast.makeText(AppContext.getContext(), "播放异常", Toast.LENGTH_SHORT).show()
+                        }
+                    }, object : SVGAParser.PlayCallback {
+                        override fun onPlay(file: List<File>) {
+                        }
+
+                    })
+
                 }
             }
         }
@@ -175,6 +214,11 @@ class JoinRoomManager : IRoomActiveListener {
                     }
 
                     override fun onAnimationEnd(p0: Animator?) {
+                        svgaImageView?.apply {
+                            if (isAnimating){
+                                stopAnimation()
+                            }
+                        }
                         joinRoomRootView?.visibility = View.INVISIBLE
                         isRunning = false
                     }
@@ -189,42 +233,6 @@ class JoinRoomManager : IRoomActiveListener {
         }
     }
 
-    private fun initLottieComposition() {
-        try {
-            LottieCompositionFactory.fromZipStream(
-                ZipInputStream(FileInputStream(UrlConstant.lottieResourcePath + File.separator + "lottiemoto.zip")),
-                "lottiemoto"
-            ).addListener {
-                lottieMoto = it
-            }
-
-            LottieCompositionFactory.fromZipStream(
-                ZipInputStream(FileInputStream(UrlConstant.lottieResourcePath + File.separator + "lottiecar.zip")),
-                "lottiecar"
-            ).addListener {
-                lottieCar = it
-            }
-
-            LottieCompositionFactory.fromZipStream(
-                ZipInputStream(FileInputStream(UrlConstant.lottieResourcePath + File.separator + "lottieboat.zip")),
-                "lottieboat"
-            ).addListener {
-                lottieBoat = it
-            }
-
-            LottieCompositionFactory.fromZipStream(
-                ZipInputStream(FileInputStream(UrlConstant.lottieResourcePath + File.separator + "lottierider.zip")),
-                "lottierider"
-            ).addListener {
-                lottieRider = it
-            }
-        } catch (e: FileNotFoundException) {
-            FileUtil.deleteFile(File(UrlConstant.lottieResourcePath))
-            e.printStackTrace()
-        }
-    }
-
-
     fun addJoinRoomData(joinRoomBean: UserJoinRoomBean) {
         joinRoomList.add(joinRoomBean)
     }
@@ -236,6 +244,11 @@ class JoinRoomManager : IRoomActiveListener {
     }
 
     private fun clearJoinRoomAnimation() {
+        svgaImageView?.apply {
+            if (isAnimating){
+                stopAnimation()
+            }
+        }
         animationSet?.cancel()
         joinRoomList.clear()
         joinRoomRootView?.visibility = View.INVISIBLE

+ 101 - 34
room/src/main/res/layout/view_user_join_room.xml

@@ -9,63 +9,130 @@
     android:layout_height="wrap_content">
 
 
-    <com.airbnb.lottie.LottieAnimationView
-        android:id="@+id/lottieView"
-        app:lottie_autoPlay="false"
-        app:lottie_loop="false"
+    <LinearLayout
+        android:id="@+id/clOne"
+        android:orientation="horizontal"
+        android:padding="5dp"
+        android:visibility="gone"
+        android:background="@drawable/shape_ff56b7_12"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"/>
-
-    <androidx.constraintlayout.widget.ConstraintLayout
-        android:id="@+id/clBg"
-        android:layoutDirection="ltr"
-        android:background="@drawable/shape_6c55ff_20"
-        android:layout_marginStart="20dp"
-        android:layout_marginBottom="250dp"
-        app:layout_constraintStart_toStartOf="@+id/lottieView"
-        app:layout_constraintBottom_toBottomOf="@+id/lottieView"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
 
-        <de.hdodenhof.circleimageview.CircleImageView
-            android:id="@+id/ivAvatar"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="parent"
-             app:layout_constraintBottom_toBottomOf="parent"
-            android:layout_margin="5dp"
-            android:layout_width="30dp"
-            android:layout_height="30dp"/>
+        <com.swago.baseswago.cusview.SwagoLevelView
+            android:id="@+id/swagoLevelOne"
+            android:layout_marginStart="5dp"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
 
         <TextView
-            android:id="@+id/tvName"
-            app:layout_constraintStart_toEndOf="@+id/ivAvatar"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintTop_toTopOf="@+id/ivAvatar"
+            android:id="@+id/tvNameOne"
             android:layout_marginStart="5dp"
-            android:layout_marginEnd="20dp"
             android:textSize="12dp"
             android:textStyle="bold"
-            tools:text="swago"
+            tools:text="swagodfdfdsfsdfdfdfsfdsf"
+            android:maxLines="1"
+            android:ellipsize="end"
+            android:maxWidth="100dp"
             android:textColor="@color/white"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"/>
 
         <TextView
-            android:id="@+id/tvJoin"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintStart_toEndOf="@+id/ivAvatar"
-            app:layout_constraintBottom_toBottomOf="@+id/ivAvatar"
             android:layout_marginEnd="20dp"
             android:layout_marginStart="5dp"
-            android:textSize="10dp"
+            android:textSize="12dp"
             android:textStyle="bold"
             android:text="@string/join_room"
             android:textColor="@color/white"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"/>
+    </LinearLayout>
+
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/clTwo"
+        android:visibility="visible"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content">
+
+        <com.opensource.svgaplayer.SVGAImageView
+            android:id="@+id/svgaImageView"
+            app:lottie_autoPlay="false"
+            app:lottie_loop="false"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            android:layout_width="260dp"
+            android:layout_height="60dp"/>
+
+        <androidx.constraintlayout.widget.ConstraintLayout
+            android:id="@+id/clBg"
+            android:layoutDirection="ltr"
+            app:layout_constraintStart_toStartOf="@+id/svgaImageView"
+            app:layout_constraintBottom_toBottomOf="@+id/svgaImageView"
+            android:layout_width="260dp"
+            android:layout_height="60dp">
+
+            <de.hdodenhof.circleimageview.CircleImageView
+                android:id="@+id/ivAvatar"
+                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"/>
+
+
+            <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"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+
+            <TextView
+                android:id="@+id/tvName"
+                app:layout_constraintStart_toEndOf="@+id/swagoLevel"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintTop_toTopOf="@+id/ivAvatar"
+                android:layout_marginStart="5dp"
+                android:layout_marginEnd="20dp"
+                android:textSize="12dp"
+                android:textStyle="bold"
+                tools:text="swago"
+                android:textColor="@color/white"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"/>
+
+            <TextView
+                android:id="@+id/tvJoin"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toEndOf="@+id/ivAvatar"
+                app:layout_constraintBottom_toBottomOf="@+id/ivAvatar"
+                android:layout_marginEnd="20dp"
+                android:layout_marginStart="5dp"
+                android:textSize="10dp"
+                android:textStyle="bold"
+                android:text="@string/join_room"
+                android:textColor="@color/white"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"/>
+
+            <ImageView
+                android:id="@+id/ivLevelLogo"
+                app:layout_constraintEnd_toEndOf="parent"
+                android:layout_width="60dp"
+                android:layout_height="match_parent"/>
+
+        </androidx.constraintlayout.widget.ConstraintLayout>
 
     </androidx.constraintlayout.widget.ConstraintLayout>
 
+
+
+
 </androidx.constraintlayout.widget.ConstraintLayout>

BIN
room/src/main/res/mipmap-xxhdpi/join_fifteen_logo.webp


BIN
room/src/main/res/mipmap-xxhdpi/join_fifteen_nineteen.webp


BIN
room/src/main/res/mipmap-xxhdpi/join_ten_fourteen.webp


BIN
room/src/main/res/mipmap-xxhdpi/join_ten_logo.webp