|
@@ -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
|