Browse Source

测试1.1.9

honghengqiang 1 year ago
parent
commit
d6a2c802dc

+ 1 - 0
baseswago/src/main/java/com/swago/baseswago/model/RedEnvelope.kt

@@ -23,6 +23,7 @@ class RedEnvelope :IRoomChat{
     @JvmField
     val senderName: String = ""//发红包用户昵称
     val userId: String = ""//发红包的用户id
+    var bigNotice:Int = 0
 
     override fun getSenderName(): String {
         return senderName

+ 2 - 1
baseswago/src/main/java/com/swago/baseswago/model/live/RedReceiveListModel.kt

@@ -9,5 +9,6 @@ data class RedReceiveModel(
     val package_coins: String,
     val user_head_img_url: String,
     val user_id: String,
-    val user_name: String
+    val user_name: String,
+    val max_user:Int
 )

+ 2 - 0
baseswago/src/main/res/values/strings.xml

@@ -252,5 +252,7 @@
     <string name="do_you_confirm_change_pwd">您确定要修改您的密码么?</string>
     <string name="red_bag_detail">红包详情</string>
     <string name="lucky_best">手气最佳</string>
+    <string name="red_bg_piao_tiao">%s发出了一个红包,30s后开抢,请做好准备!</string>
+    <string name="red_bg_piao_tiao_big">%s在%s发出了一个红包,30s后开抢,请做好准备!</string>
 
 </resources>

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

@@ -70,6 +70,7 @@ import com.swago.room.piaotiao.WaftManager
 import com.swago.room.pk.IPKListener
 import com.swago.room.pk.PKStateManager
 import com.swago.room.pk.PkVm
+import com.swago.room.user.UserRoomActivity
 import com.swago.room.vm.MsgVm
 import com.swago.room.vm.RoomOtherVm
 import com.swago.room.vm.RoomVm
@@ -184,7 +185,12 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
         msgVm.joinRoomManager.initViewStub(binding.joinRoomViewStub, activity)
         //
         binding.danMuView.setActivity(activity)
-
+        binding.hongbaoPiaotiao.setActivity(activity)
+        binding.hongbaoPiaotiao.goToTargetRoom = {
+            if (SwagoRoomManager.roleType == RoleType.user){
+                goToTargetRoom(it)
+            }
+        }
         val layoutManager = LinearLayoutManager(context)
         layoutManager.stackFromEnd = true
         binding.rv.layoutManager = layoutManager
@@ -447,6 +453,10 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
             binding.danMuView.addQueue(it)
         }
 
+        msgVm.addHongbaoPiaotiao = {
+            binding.hongbaoPiaotiao.addQueue(it)
+        }
+
         msgVm.addAudioGiftAnimFun = { data ->
             if (allPositionXYList.size > 0) {
                 data.receivers.forEach {
@@ -846,6 +856,13 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
     fun setAudioRvState(isVisible: Boolean) {
         binding.rvAudio.visibility = if (isVisible) View.VISIBLE else View.GONE
     }
+    fun goToTargetRoom(it: String) {
+        activity?.let { activity ->
+            if (activity is UserRoomActivity) {
+                activity.gotoTargetRoom(it)
+            }
+        }
+    }
 
     inner class GridItemDecoration : RecyclerView.ItemDecoration() {
         override fun getItemOffsets(

+ 1 - 0
room/src/main/java/com/swago/room/hongbao/RedReceivedAdapter.kt

@@ -16,6 +16,7 @@ class RedReceivedAdapter :  BaseQuickAdapter<RedReceiveModel, BaseViewHolder>(R.
                 setText(R.id.tvName,it.user_name)
                 setText(R.id.tvTime,it.created_at)
                 setText(R.id.tvCoin,it.package_coins)
+                setVisible(R.id.tvLucky,it.max_user==1)
             }
         }
     }

+ 142 - 0
room/src/main/java/com/swago/room/piaotiao/HongbaoPiaoTiaoView.kt

@@ -0,0 +1,142 @@
+package com.swago.room.piaotiao
+
+import android.animation.Animator
+import android.animation.AnimatorSet
+import android.animation.ObjectAnimator
+import android.app.Activity
+import android.content.Context
+import android.text.Html
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.view.View
+import androidx.constraintlayout.widget.ConstraintLayout
+import androidx.fragment.app.FragmentActivity
+import com.swago.baseswago.baseroom.IRoomActiveListener
+import com.swago.baseswago.baseroom.IRoomInfo
+import com.swago.baseswago.baseroom.SwagoRoomManager
+import com.swago.baseswago.model.RedEnvelope
+import com.swago.baseswago.util.AppContext
+import com.swago.baseswago.util.DpPxUtil
+import com.swago.baseswago.util.NoDoubleClickListener
+import com.swago.room.R
+import com.swago.room.databinding.ViewHongBaoBinding
+import com.swago.room.databinding.ViewWaftBinding
+import java.util.concurrent.ConcurrentLinkedQueue
+
+//红包飘条
+class HongbaoPiaoTiaoView : ConstraintLayout, IRoomActiveListener {
+
+    private var binding : ViewHongBaoBinding? = null
+    private var isBusy = false
+    private var animatorSet: AnimatorSet? = null
+
+    private var queue = ConcurrentLinkedQueue<RedEnvelope>()
+
+    private var mActivity: Activity? = null
+
+    var goToTargetRoom:((anchorId:String)->Unit)? = null
+
+    constructor(context: Context) : this(context, null)
+    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
+    constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
+        context,
+        attrs,
+        defStyle
+    ) {
+        initView(context)
+    }
+
+    private fun initView(context: Context) {
+        SwagoRoomManager.addListener(this)
+        binding = ViewHongBaoBinding.inflate(LayoutInflater.from(context), this, true)
+    }
+
+    fun addQueue(redEnvelope: RedEnvelope){
+        queue.add(redEnvelope)
+        if (!isBusy){
+            startRedEnvelop(redEnvelope)
+        }
+    }
+
+    fun setActivity(activity: FragmentActivity?){
+        this.mActivity = activity
+    }
+
+
+    private fun startRedEnvelop(redEnvelope: RedEnvelope){
+        binding?.apply {
+            isBusy = true
+            visibility = View.VISIBLE
+            val sendName = "<font color='#FFDB43'>${redEnvelope.senderName}</font>"
+            if (redEnvelope.bigNotice == 1){
+                binding?.ivJump?.visibility = View.VISIBLE
+                binding?.marqueeTextView?.text = Html.fromHtml(AppContext.getContext().resources.getString(R.string.red_bg_piao_tiao_big).format(sendName,redEnvelope.anchorName))
+                binding?.ll?.setBackgroundResource(R.mipmap.bg_red_notice)
+                binding?.ivJump?.setOnClickListener(object:NoDoubleClickListener(){
+                    override fun onClick() {
+                        goToTargetRoom?.invoke(redEnvelope.anchorId)
+                    }
+                })
+            }else{
+                binding?.ivJump?.visibility = View.GONE
+                binding?.marqueeTextView?.text = Html.fromHtml(AppContext.getContext().resources.getString(R.string.red_bg_piao_tiao).format(sendName))
+                binding?.ll?.setBackgroundResource(R.mipmap.bg_red_notice)
+            }
+            val objectAnimator = ObjectAnimator.ofFloat(this@HongbaoPiaoTiaoView,"translationX",(DpPxUtil.getScreenWidth()+width).toFloat(),0f)
+            objectAnimator.duration = 1000
+            val alphaAnimator = ObjectAnimator.ofFloat(this@HongbaoPiaoTiaoView,"alpha",1f,1f)
+            alphaAnimator.duration = 5000
+            animatorSet = AnimatorSet()
+            animatorSet?.play(alphaAnimator)?.after(objectAnimator)
+            animatorSet?.start()
+            animatorSet?.addListener(object : Animator.AnimatorListener {
+                override fun onAnimationStart(animation: Animator) {}
+                override fun onAnimationEnd(animation: Animator) {
+                    visibility = View.GONE
+                    isBusy = false
+                    queue.poll()
+                    queue.peek()?.let {
+                        startRedEnvelop(it)
+                    }
+                }
+
+                override fun onAnimationCancel(animation: Animator) {}
+                override fun onAnimationRepeat(animation: Animator) {}
+            })
+            binding?.marqueeTextView?.post {
+                binding?.marqueeTextView?.startScroll()
+            }
+        }
+    }
+
+    override fun changeRoom(iRoomInfo: IRoomInfo) {
+    }
+
+    override fun leaveRoom(iRoomInfo: IRoomInfo) {
+        clearAnim()
+    }
+
+    override fun joinedRoom(iRoomInfo: IRoomInfo) {
+    }
+
+    override fun endRoom(iRoomInfo: IRoomInfo?) {
+        clearAnim()
+    }
+
+    override fun closeRoomed() {
+        mActivity = null
+        clearAnim()
+        SwagoRoomManager.removeListener(this)
+    }
+
+    private fun clearAnim(){
+        queue.clear()
+        animatorSet?.let {
+            if(it.isRunning){
+                it.cancel()
+            }
+            isBusy = false
+        }
+    }
+
+}

+ 2 - 5
room/src/main/java/com/swago/room/user/UserRoomFragment.kt

@@ -141,11 +141,7 @@ class UserRoomFragment : BaseComFragment<FragmentBaseComBinding>() {
             binding.ivRedEnvelopeBroadcastView.openRedEnvelopeBroadcastDialog = {
                 RedEnvelopBroadcastDialog.newInstance(it.senderName,it.senderAvatar,it.anchorId,it.anchorName).apply {
                     this.gotoTargetRoom = {
-                        activity?.let {  activity ->
-                            if (activity is UserRoomActivity){
-                                activity.gotoTargetRoom(it)
-                            }
-                        }
+                        goToTargetRoom(it)
                     }
                 }.show(childFragmentManager,"RedEnvelopBroadcastDialog")
             }
@@ -210,6 +206,7 @@ class UserRoomFragment : BaseComFragment<FragmentBaseComBinding>() {
 
     }
 
+
     private fun openLianMaiListDialog() {
         UserLianMaiDialog.newInstance().show(childFragmentManager,"UserLianMaiDialog")
     }

+ 9 - 0
room/src/main/java/com/swago/room/vm/MsgVm.kt

@@ -122,6 +122,11 @@ class MsgVm(application: Application) : AbsMsgVm(application) {
      */
     var addDanMuFun:((danMuBean:DanMuBean)->Unit)? = null
 
+    /**
+     * 红包飘条
+     */
+    var addHongbaoPiaotiao:((redEnvelop:RedEnvelope)->Unit)? = null
+
     val joinRoomManager by lazy {
         JoinRoomManager()
     }
@@ -285,6 +290,8 @@ class MsgVm(application: Application) : AbsMsgVm(application) {
                     if (it.roomId == iRoomInfo.getRoomId()) {
                         newRedEnvelopeCome?.invoke(it)
                         newChatMsgFun?.invoke(it)
+                        it.bigNotice = 0
+                        addHongbaoPiaotiao?.invoke(it)
                     }
                 }
             }
@@ -297,6 +304,8 @@ class MsgVm(application: Application) : AbsMsgVm(application) {
                     if (isReady && it.roomId != iRoomInfo.getRoomId() && SwagoRoomManager.roleType == RoleType.user) {
                         //其他直播间用户收到这个全局红包的通知触发弹窗
                         openRedEnvelopPortal?.invoke(it)
+                        it.bigNotice = 1
+                        addHongbaoPiaotiao?.invoke(it)
                     }
                 }
             }

+ 9 - 0
room/src/main/res/layout/fragment_base_com.xml

@@ -186,6 +186,15 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>
 
+    <com.swago.room.piaotiao.HongbaoPiaoTiaoView
+        android:id="@+id/hongbaoPiaotiao"
+        android:layout_marginTop="165dp"
+        android:visibility="gone"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"/>
+
     <com.swago.room.audio.widget.AudioContainGiftView
         android:id="@+id/audioAllGiftView"
         android:layout_width="match_parent"

+ 32 - 0
room/src/main/res/layout/view_hong_bao.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="350dp"
+    android:layout_height="wrap_content"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/ll"
+    android:layout_gravity="center_horizontal"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:orientation="horizontal"
+    android:gravity="center_vertical"
+    android:background="@mipmap/bg_red_notice">
+
+    <com.swago.room.widget.MarqueeTextView
+        android:id="@+id/marqueeTextView"
+        android:layout_marginStart="35dp"
+        android:layout_width="290dp"
+        android:layout_height="wrap_content"
+        android:textSize="16dp"
+        tools:text="ddddd"
+        android:layout_gravity="center"
+        android:textColor="@color/white"
+        app:scroll_first_delay="1000"
+        app:scroll_interval="6000"
+        app:scroll_mode="mode_forever"/>
+
+    <ImageView
+        android:id="@+id/ivJump"
+        android:visibility="gone"
+        android:src="@mipmap/ic_jump_go"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"/>
+</LinearLayout>

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


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