فهرست منبع

进房交互完善

DoggyZhang 3 هفته پیش
والد
کامیت
e8605a9bee

+ 8 - 3
module/room/src/main/java/com/adealink/weparty/room/chat/ChatInputDialog.kt

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
 import android.text.Editable
 import android.text.TextWatcher
 import android.view.KeyEvent
+import android.view.MotionEvent
 import android.view.inputmethod.EditorInfo
 import android.widget.TextView
 import android.widget.TextView.OnEditorActionListener
@@ -70,8 +71,13 @@ class ChatInputDialog : KeyboardBottomDialogFragment(R.layout.dialog_chat_messag
         binding.vInputBar.etInputMessage.setSelection(
             binding.vInputBar.etInputMessage.getText()?.length ?: 0
         )
-
         binding.vInputBar.etInputMessage.isClickable = true
+        binding.vInputBar.etInputMessage.setOnTouchListener { _, event ->
+            if (event.action == MotionEvent.ACTION_DOWN) {
+                inputStateViewModel.execute(InputAction.CLICK_INPUT)
+            }
+            false
+        }
         binding.vInputBar.etInputMessage.setOnEditorActionListener(object : OnEditorActionListener {
             override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent?): Boolean {
                 if (actionId == EditorInfo.IME_ACTION_SEND
@@ -208,7 +214,6 @@ class ChatInputDialog : KeyboardBottomDialogFragment(R.layout.dialog_chat_messag
         if (!isTextSendEnable) {
             return
         }
-        //inputStateViewModel.sendMessage(ChatMessageBuilder.buildTextMessage(inputBar.etInputMessage.text?.toString()))
         val inputText = binding.vInputBar.etInputMessage.text?.toString()
         if (inputText.isNullOrEmpty()) {
             return
@@ -220,7 +225,7 @@ class ChatInputDialog : KeyboardBottomDialogFragment(R.layout.dialog_chat_messag
                 }
 
                 is Rlt.Success<*> -> {
-                    binding.vInputBar.etInputMessage.setText(null)
+                    dismiss()
                 }
             }
         }

+ 35 - 6
module/room/src/main/java/com/adealink/weparty/room/chatroom/page/dispatchcenter/DispatchCenterRoomInfoFragment.kt

@@ -1,27 +1,56 @@
 package com.adealink.weparty.room.chatroom.page.dispatchcenter
 
+import android.annotation.SuppressLint
 import com.adealink.frame.mvvm.view.viewBinding
 import com.adealink.weparty.commonui.BaseFragment
-import com.adealink.weparty.module.profile.ProfileModule
+import com.adealink.weparty.commonui.ext.gone
+import com.adealink.weparty.commonui.ext.show
 import com.adealink.weparty.room.R
 import com.adealink.weparty.room.databinding.FragmentDispatchCenterRoomInfoBinding
 import com.adealink.weparty.room.sdk.service.roomService
+import io.trtc.tuikit.atomicxcore.api.live.LiveInfo
+import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.launch
 
 class DispatchCenterRoomInfoFragment : BaseFragment(R.layout.fragment_dispatch_center_room_info) {
 
     private val binding by viewBinding(FragmentDispatchCenterRoomInfoBinding::bind)
 
+    private var subscribeStateJob: Job? = null
+
     override fun initViews() {
-        // TODO: zhangfei
-        val userInfo = ProfileModule.getMyUserInfo()
-        binding.roomCover.setImageUrl(userInfo?.avatar)
-        binding.roomName.text = userInfo?.nickName
-        binding.roomId.text = "ID ${roomService.joinController.getJoinedRoomId()}"
+        updateRoomInfo(roomService.joinController.joinedRoomInfo)
     }
 
     override fun observeViewModel() {
         super.observeViewModel()
+        subscribeStateJob = CoroutineScope(Dispatchers.Main).launch {
+            LiveListStore.shared().liveState.currentLive.collect { liveInfo ->
+                if (liveInfo.liveID == roomService.joinController.getJoinedRoomId()) {
+                    updateRoomInfo(liveInfo)
+                }
+            }
+        }
+    }
+
+    @SuppressLint("SetTextI18n")
+    private fun updateRoomInfo(liveInfo: LiveInfo?) {
+        binding.roomCover.setImageUrl(liveInfo?.coverURL)
+        binding.roomName.text = liveInfo?.liveName
+        liveInfo?.liveID?.let { liveID ->
+            binding.roomId.show()
+            binding.roomId.text = "ID $liveID"
+        } ?: let {
+            binding.roomId.gone()
+        }
     }
 
+    override fun onDestroyView() {
+        super.onDestroyView()
+        subscribeStateJob?.cancel()
+    }
 
 }

+ 5 - 1
module/room/src/main/java/com/adealink/weparty/room/sdk/controller/impl/MessageController.kt

@@ -12,6 +12,7 @@ import com.adealink.weparty.room.sdk.listener.IMessageListener
 import io.trtc.tuikit.atomicxcore.api.CompletionHandler
 import io.trtc.tuikit.atomicxcore.api.barrage.Barrage
 import io.trtc.tuikit.atomicxcore.api.barrage.BarrageStore
+import kotlinx.coroutines.Job
 import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.StateFlow
 import kotlinx.coroutines.flow.asStateFlow
@@ -25,6 +26,8 @@ class MessageController(override val ctx: IRoomContext, serialHandler: Handler)
 
     private var barrageStore: BarrageStore? = null
 
+    private var messageListJob: Job? = null
+
     override fun onRoomIn(flowStateInfo: FlowStateInfo) {
         super.onRoomIn(flowStateInfo)
         barrageStore = BarrageStore.create(flowStateInfo.roomId)
@@ -33,6 +36,7 @@ class MessageController(override val ctx: IRoomContext, serialHandler: Handler)
 
     override fun onRoomLeaved(flowStateInfo: FlowStateInfo) {
         super.onRoomLeaved(flowStateInfo)
+        messageListJob?.cancel()
     }
 
     // 对外暴露【全量】消息列表的Flow,方便UI层订阅
@@ -40,7 +44,7 @@ class MessageController(override val ctx: IRoomContext, serialHandler: Handler)
     override val messagesFlow: StateFlow<List<Barrage>> = _messagesFlow.asStateFlow()
 
     private fun subscribeToBarrageUpdates() {
-        launch {
+        messageListJob = launch {
             barrageStore?.barrageState?.messageList?.collect { messageList ->
                 // 当 messageList 更新时,通过 Flow 将新列表传递给UI层
                 // 关键点:这里接收到的是包含所有历史消息的【完整列表】

+ 4 - 9
module/room/src/main/java/com/adealink/weparty/room/sdk/controller/impl/SeatController.kt

@@ -23,13 +23,10 @@ import com.adealink.weparty.room.sdk.listener.IDeviceListener
 import com.adealink.weparty.room.sdk.listener.ISeatListener
 import com.adealink.weparty.room.sdk.service.roomService
 import io.trtc.tuikit.atomicxcore.api.CompletionHandler
-import io.trtc.tuikit.atomicxcore.api.device.DeviceStore
 import io.trtc.tuikit.atomicxcore.api.live.DeviceControlPolicy
-import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
 import io.trtc.tuikit.atomicxcore.api.live.LiveSeatStore
 import io.trtc.tuikit.atomicxcore.api.live.SeatInfo
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.Job
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
 
@@ -40,12 +37,9 @@ class SeatController(override val ctx: IRoomContext, serialHandler: Handler) :
     IMediaRtcListener {
 
     override var selfMicSeatInfo: SeatInfo? = null
-
-    private var liveListStore: LiveListStore = LiveListStore.shared()
-    private var deviceStore: DeviceStore = DeviceStore.shared()
-
     private var liveSeatRoomId: String? = null
     private var liveSeatStore: LiveSeatStore? = null
+    private var liveSeatListJob: Job? = null
 
     private var micSeats: MutableMap<Int, SeatInfo> = hashMapOf() //key:mic index
 
@@ -66,11 +60,12 @@ class SeatController(override val ctx: IRoomContext, serialHandler: Handler) :
             //notifySelfMicSeatChanged(null)
         }
         //clearMicSeatSpeaking()
+        liveSeatListJob?.cancel()
     }
 
     private fun observeSeatList() {
         // 监听 seatList 变化,并更新您的麦位 UI
-        CoroutineScope(Dispatchers.Main).launch {
+        liveSeatListJob = launch {
             liveSeatStore?.liveSeatState?.seatList?.collect { seatInfoList ->
                 // 在这里根据 seatInfoList 渲染您的麦位 UI
                 // 例如:updateMicSeatView(seatInfoList)

+ 1 - 0
module/room/src/main/res/layout/fragment_dispatch_center_room_info.xml

@@ -39,6 +39,7 @@
             android:layout_marginEnd="8dp"
             android:ellipsize="marquee"
             android:fontFamily="@font/poppins_semibold"
+            android:includeFontPadding="false"
             android:marqueeRepeatLimit="marquee_forever"
             android:singleLine="true"
             android:textColor="@color/white"