Bläddra i källkod

语音房给观众送礼

admin 1 år sedan
förälder
incheckning
a292cb6f73

+ 4 - 4
baseswago/src/main/java/com/swago/baseswago/util/DpPxUtil.kt

@@ -12,7 +12,7 @@ object DpPxUtil {
      */
     fun dip2px(dipValue: Float): Int {
         val scale =
-            Resources.getSystem().displayMetrics.density
+            AppContext.getContext().resources.displayMetrics.density
         return (dipValue * scale + 0.5f).toInt()
     }
 
@@ -21,17 +21,17 @@ object DpPxUtil {
      */
     fun px2dip(pxValue: Float): Int {
         val scale =
-            Resources.getSystem().displayMetrics.density
+            AppContext.getContext().resources.displayMetrics.density
         return (pxValue / scale + 0.5f).toInt()
     }
 
     fun getScreenWidth():Int{
-        val display = Resources.getSystem().displayMetrics
+        val display = AppContext.getContext().resources.displayMetrics
         return display?.widthPixels ?: 0
     }
 
     fun getScreenHeight():Int{
-        val display = Resources.getSystem().displayMetrics
+        val display = AppContext.getContext().resources.displayMetrics
         return display?.heightPixels ?: 0
     }
 }

+ 88 - 17
room/src/main/java/com/swago/room/audio/widget/AudioContainGiftView.kt

@@ -10,6 +10,7 @@ import com.swago.baseswago.baseroom.IRoomActiveListener
 import com.swago.baseswago.baseroom.IRoomInfo
 import com.swago.baseswago.baseroom.SwagoRoomManager
 import com.swago.baseswago.model.live.audio.AudioSendGiftModel
+import com.swago.baseswago.util.DpPxUtil
 import com.swago.room.R
 import com.swago.room.databinding.ViewAudioContainGiftBinding
 
@@ -73,42 +74,42 @@ class AudioContainGiftView : ConstraintLayout, IRoomActiveListener {
                 }
             }
 
-            audioSendGiftModel.receivers.forEachIndexed {position, positionBean ->
-                //创建从屏幕中心弹出的动画view
-                allAudioGiftViewList[position].setViewData(audioSendGiftModel.giftIcon, audioSendGiftModel.giftNum)
-                clMultiAudio.addView(allAudioGiftViewList[position])
+            //如果receivers的size为0  那么就是送给用户的
+            if (audioSendGiftModel.receivers.isEmpty()){
+                allAudioGiftViewList[0].setViewData(audioSendGiftModel.giftIcon, audioSendGiftModel.giftNum)
+                clMultiAudio.addView(allAudioGiftViewList[0])
 
                 //从中间缩放出来
-                val alphaAnim = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "alpha", 1f, 1f)
-                val scaleX = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "scaleX", 0f, 1f)
-                val scaleY = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "scaleY", 0f, 1f)
+                val alphaAnim = ObjectAnimator.ofFloat(allAudioGiftViewList[0], "alpha", 1f, 1f)
+                val scaleX = ObjectAnimator.ofFloat(allAudioGiftViewList[0], "scaleX", 0f, 1f)
+                val scaleY = ObjectAnimator.ofFloat(allAudioGiftViewList[0], "scaleY", 0f, 1f)
                 val scaleFromCenter = AnimatorSet()
                 scaleFromCenter.playTogether(scaleX,scaleY,alphaAnim)
-                scaleFromCenter.setTarget(allAudioGiftViewList[position])
+                scaleFromCenter.setTarget(allAudioGiftViewList[0])
                 scaleX.duration = 300
                 scaleY.duration = 300
 
                 //从中间向其他地方位移缩放
-                val moveX = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"translationX", positionBean.dx)
-                val moveY = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"translationY", positionBean.dy)
-                val scaleXX = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"scaleX",1f,0.2f)
-                val scaleYY = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"scaleY",1f,0.2f)
+                val moveX = ObjectAnimator.ofFloat(allAudioGiftViewList[0],"translationX", DpPxUtil.getScreenWidth()/2f - DpPxUtil.dip2px(100f))
+                val moveY = ObjectAnimator.ofFloat(allAudioGiftViewList[0],"translationY", -DpPxUtil.getScreenHeight()/2f + DpPxUtil.dip2px(40f))
+                val scaleXX = ObjectAnimator.ofFloat(allAudioGiftViewList[0],"scaleX",1f,0.2f)
+                val scaleYY = ObjectAnimator.ofFloat(allAudioGiftViewList[0],"scaleY",1f,0.2f)
                 val moveAndScale = AnimatorSet()
                 moveAndScale.playTogether(moveX,moveY,scaleXX,scaleYY)
                 moveAndScale.duration = 700
 
-                val alphaAnimX = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "alpha", 1f, 0f)
+                val alphaAnimX = ObjectAnimator.ofFloat(allAudioGiftViewList[0], "alpha", 1f, 0f)
                 alphaAnimX.duration = 200
 
                 val moveAnimatorPlus = AnimatorSet()
                 moveAnimatorPlus.play(alphaAnimX).after(moveAndScale)
 
                 //在头像上方消失
-                val alphaAnimEnd = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"alpha",1f,0f)
+                val alphaAnimEnd = ObjectAnimator.ofFloat(allAudioGiftViewList[0],"alpha",1f,0f)
                 alphaAnimEnd.duration = 800
                 //向头像上方移动
-                val upYAnima = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"translationY",positionBean.offSetY)
-                val alphaAnimUp = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "alpha", 0f, 1f)
+                val upYAnima = ObjectAnimator.ofFloat(allAudioGiftViewList[0],"translationY",-DpPxUtil.getScreenHeight()/2f + DpPxUtil.dip2px(40f))
+                val alphaAnimUp = ObjectAnimator.ofFloat(allAudioGiftViewList[0], "alpha", 1f, 1f)
                 val upAnimatorSet = AnimatorSet()
                 upAnimatorSet.playTogether(upYAnima,alphaAnimUp)
                 upAnimatorSet.duration = 200
@@ -122,7 +123,7 @@ class AudioContainGiftView : ConstraintLayout, IRoomActiveListener {
                 animatorSet.play(upAnimatorSet)
                     .after(animationScaleAndMoveSet)
                     .before(alphaAnimEnd)
-                animatorSet.setTarget(allAudioGiftViewList[position])
+                animatorSet.setTarget(allAudioGiftViewList[0])
                 allAnimationSetList.add(animatorSet)
 
                 animatorSet.addListener(object: Animator.AnimatorListener{
@@ -141,6 +142,76 @@ class AudioContainGiftView : ConstraintLayout, IRoomActiveListener {
                     override fun onAnimationRepeat(animation: Animator?) {}
 
                 })
+            }else{
+                audioSendGiftModel.receivers.forEachIndexed {position, positionBean ->
+                    //创建从屏幕中心弹出的动画view
+                    allAudioGiftViewList[position].setViewData(audioSendGiftModel.giftIcon, audioSendGiftModel.giftNum)
+                    clMultiAudio.addView(allAudioGiftViewList[position])
+
+                    //从中间缩放出来
+                    val alphaAnim = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "alpha", 1f, 1f)
+                    val scaleX = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "scaleX", 0f, 1f)
+                    val scaleY = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "scaleY", 0f, 1f)
+                    val scaleFromCenter = AnimatorSet()
+                    scaleFromCenter.playTogether(scaleX,scaleY,alphaAnim)
+                    scaleFromCenter.setTarget(allAudioGiftViewList[position])
+                    scaleX.duration = 300
+                    scaleY.duration = 300
+
+                    //从中间向其他地方位移缩放
+                    val moveX = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"translationX", positionBean.dx)
+                    val moveY = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"translationY", positionBean.dy)
+                    val scaleXX = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"scaleX",1f,0.2f)
+                    val scaleYY = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"scaleY",1f,0.2f)
+                    val moveAndScale = AnimatorSet()
+                    moveAndScale.playTogether(moveX,moveY,scaleXX,scaleYY)
+                    moveAndScale.duration = 700
+
+                    val alphaAnimX = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "alpha", 1f, 0f)
+                    alphaAnimX.duration = 200
+
+                    val moveAnimatorPlus = AnimatorSet()
+                    moveAnimatorPlus.play(alphaAnimX).after(moveAndScale)
+
+                    //在头像上方消失
+                    val alphaAnimEnd = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"alpha",1f,0f)
+                    alphaAnimEnd.duration = 800
+                    //向头像上方移动
+                    val upYAnima = ObjectAnimator.ofFloat(allAudioGiftViewList[position],"translationY",positionBean.offSetY)
+                    val alphaAnimUp = ObjectAnimator.ofFloat(allAudioGiftViewList[position], "alpha", 0f, 1f)
+                    val upAnimatorSet = AnimatorSet()
+                    upAnimatorSet.playTogether(upYAnima,alphaAnimUp)
+                    upAnimatorSet.duration = 200
+
+                    val animationScaleAndMoveSet = AnimatorSet()
+                    animationScaleAndMoveSet.play(moveAnimatorPlus)
+                        .after(scaleFromCenter)
+                        .after(2300)
+
+                    val animatorSet = AnimatorSet()
+                    animatorSet.play(upAnimatorSet)
+                        .after(animationScaleAndMoveSet)
+                        .before(alphaAnimEnd)
+                    animatorSet.setTarget(allAudioGiftViewList[position])
+                    allAnimationSetList.add(animatorSet)
+
+                    animatorSet.addListener(object: Animator.AnimatorListener{
+                        override fun onAnimationStart(animation: Animator?) {
+                        }
+
+                        override fun onAnimationEnd(animation: Animator?) {
+                            currentModel = null
+                            isBusy = false
+                        }
+
+                        override fun onAnimationCancel(animation: Animator?) {
+
+                        }
+
+                        override fun onAnimationRepeat(animation: Animator?) {}
+
+                    })
+                }
             }
             allAnimationSetList.forEach {
                 it.start()

+ 40 - 18
room/src/main/java/com/swago/room/gift/GiftDialog.kt

@@ -110,6 +110,8 @@ class GiftDialog : BaseXDFragment<DialogGiftBinding>() {
     override fun initOther() {
         arguments?.let {
             payVm.getCoins()
+            receiveId = it.getString("receiveId", "")
+            receiveName = it.getString("receiveName", "")
             SwagoRoomManager.iRoomInfo?.let { iRoomInfo ->
                 if (iRoomInfo.getRoomType() == 1) {
                     binding.tvSender.visibility = View.VISIBLE
@@ -119,7 +121,6 @@ class GiftDialog : BaseXDFragment<DialogGiftBinding>() {
                 } else if (iRoomInfo.getRoomType() == 2) {
                     //获取语音房麦位用户列表
                     binding.tvSender.visibility = View.GONE
-                    binding.rvAudioUser.visibility = View.VISIBLE
                     binding.rvAudioUser.layoutManager = LinearLayoutManager(activity,RecyclerView.HORIZONTAL,false)
                     binding.rvAudioUser.adapter = adapter
                     adapter.setOnItemClickListener { _, view, position ->
@@ -135,9 +136,6 @@ class GiftDialog : BaseXDFragment<DialogGiftBinding>() {
                     json = SpUtil.readString("audioGiftList")
                 }
             }
-            receiveId = it.getString("receiveId", "")
-            receiveName = it.getString("receiveName", "")
-
             if (json.isNullOrEmpty()) {
 
             } else {
@@ -549,20 +547,40 @@ class GiftDialog : BaseXDFragment<DialogGiftBinding>() {
                 }
             } else if (iRoomInfo.getRoomType() == 2) {
                 //语音房送礼
-                if (selectedUserList.isNotEmpty()) {
-                    giftVm.sendAudioGift(
-                        iRoomInfo.getRoomId(),
-                        giftModel.id,
-                        giftBatch,
-                        selectedUserList,
-                        giftNum
-                    )
+                if (binding.rvAudioUser.visibility == View.VISIBLE){
+                    if (selectedUserList.isNotEmpty()) {
+                        giftVm.sendAudioGift(
+                            iRoomInfo.getRoomId(),
+                            giftModel.id,
+                            giftBatch,
+                            selectedUserList,
+                            giftNum
+                        )
+                    }else{
+                        Toast.makeText(
+                            AppContext.getContext(),
+                            AppContext.getContext().resources.getString(R.string.no_send_people),
+                            Toast.LENGTH_SHORT
+                        ).show()
+                    }
                 }else{
-                    Toast.makeText(
-                        AppContext.getContext(),
-                        AppContext.getContext().resources.getString(R.string.no_send_people),
-                        Toast.LENGTH_SHORT
-                    ).show()
+                    UserInfo.getUserInfo()?.let {
+                        if (it.id != receiveId && receiveId.isNotEmpty()){
+                            giftVm.sendAudioGift(
+                                iRoomInfo.getRoomId(),
+                                giftModel.id,
+                                giftBatch,
+                                listOf(receiveId),
+                                giftNum
+                            )
+                        }else{
+                            Toast.makeText(
+                                AppContext.getContext(),
+                                AppContext.getContext().resources.getString(R.string.no_send_people),
+                                Toast.LENGTH_SHORT
+                            ).show()
+                        }
+                    }
                 }
             }
         }
@@ -669,7 +687,11 @@ class GiftDialog : BaseXDFragment<DialogGiftBinding>() {
         }
 
         giftVm.maiUserListLiveData.observe(this) { data ->
-            if(data.isNotEmpty()){
+            //如果麦位列表上没有数据 那么语音房的送礼弹窗肯定是送给用户的
+            if(data.isEmpty()){
+               binding.rvAudioUser.visibility = View.GONE
+            }else{
+                binding.rvAudioUser.visibility = View.VISIBLE
                 data[0].selected = true
                 selectedUserList.add(data[0].user_id)
             }