DoggyZhang 1 hete
szülő
commit
c79406738c

+ 28 - 13
module/profile/src/main/java/com/adealink/weparty/profile/comp/ProfileRoomStatusComp.kt

@@ -3,17 +3,17 @@ package com.adealink.weparty.profile.comp
 import android.graphics.Outline
 import android.view.View
 import android.view.ViewOutlineProvider
-import androidx.constraintlayout.widget.ConstraintLayout
-import androidx.core.view.updateLayoutParams
 import androidx.lifecycle.LifecycleOwner
-import com.adealink.frame.aab.util.getCompatDimension
+import com.adealink.frame.mvvm.viewmodel.viewModels
 import com.adealink.frame.util.onClick
-import com.adealink.weparty.R
 import com.adealink.weparty.commonui.BaseActivity
+import com.adealink.weparty.commonui.ext.gone
 import com.adealink.weparty.commonui.ext.show
 import com.adealink.weparty.module.room.RoomModule
+import com.adealink.weparty.module.room.data.RoomInfo
 import com.adealink.weparty.profile.databinding.LayoutUserProfileHeaderBinding
 import com.adealink.weparty.profile.databinding.LayoutUserProfileRoomOnlineBinding
+import com.adealink.weparty.profile.viewmodel.ProfileRoomViewModel
 
 class ProfileRoomStatusComp(
     lifecycleOwner: LifecycleOwner,
@@ -22,11 +22,11 @@ class ProfileRoomStatusComp(
     private val binding: LayoutUserProfileRoomOnlineBinding,
 ) : BaseProfileViewComp(lifecycleOwner, userUid) {
 
+    private val roomViewModel by viewModels<ProfileRoomViewModel>()
+
     override fun initView() {
         initBlur()
-
-        // TODO: zhangfei
-        binding.root.show()
+        binding.root.gone()
         binding.root.onClick {
             val act = (activity as? BaseActivity) ?: return@onClick
             RoomModule.createRoom(act)
@@ -42,10 +42,6 @@ class ProfileRoomStatusComp(
                 outline.alpha = 1f
             }
         }
-//        val radius = 25f
-//        val minBlurRadius = 4f
-//        val step = 4f
-        //set background, if your root layout doesn't have one
         val windowBackground = activity?.window?.decorView?.background
         headerBinding.vRoomOnlineBlurBar.setupWith(headerBinding.ivBgBlurTarget)
             .setFrameClearDrawable(windowBackground)
@@ -53,9 +49,28 @@ class ProfileRoomStatusComp(
     }
 
     override fun observeViewModel() {
-        profileViewModel.userInfoLD.observe(viewLifecycleOwner) {
-            updateUI(it)
+        roomViewModel.userRoomInfoLD.observe(viewLifecycleOwner) {
+            if (it.first == userUid) {
+                val roomInfo = it.second
+                updateRoomInfo(roomInfo)
+            } else {
+                updateRoomInfo(null)
+            }
+        }
+    }
+
+    private fun updateRoomInfo(roomInfo: RoomInfo?) {
+        if (roomInfo == null || roomInfo.roomId.isNullOrEmpty()) {
+            binding.root.gone()
+            return
         }
+        binding.root.show()
+        binding.ivCover.setImageUrl(roomInfo.roomCover)
+    }
+
+    override fun loadData() {
+        super.loadData()
+        roomViewModel.getUserRoomStatus(userUid)
     }
 
 

+ 9 - 0
module/profile/src/main/java/com/adealink/weparty/profile/data/ProfileData.kt

@@ -2,6 +2,7 @@ package com.adealink.weparty.profile.data
 
 import com.adealink.weparty.module.profile.data.UserInfo
 import com.adealink.weparty.module.profile.data.UserNote
+import com.adealink.weparty.module.room.data.RoomInfo
 import com.google.gson.annotations.SerializedName
 
 data class GetUserinfoReq(
@@ -60,4 +61,12 @@ data class GetUserNoteReq(
 
 data class GetUserNoteRes(
     @SerializedName("list") val list: List<UserNote>
+)
+
+data class GetUserLiveRoomReq(
+    @SerializedName("id") val uid: String
+)
+
+data class GetUserLiveRoomRes(
+    @SerializedName("room") val roomInfo: RoomInfo
 )

+ 5 - 0
module/profile/src/main/java/com/adealink/weparty/profile/datasource/remote/ProfileHttpService.kt

@@ -4,6 +4,8 @@ import com.adealink.frame.base.Rlt
 import com.adealink.frame.network.data.Res
 import com.adealink.weparty.module.profile.data.MyUserInfoData
 import com.adealink.weparty.profile.data.GetUserInfosRes
+import com.adealink.weparty.profile.data.GetUserLiveRoomReq
+import com.adealink.weparty.profile.data.GetUserLiveRoomRes
 import com.adealink.weparty.profile.data.GetUserNoteReq
 import com.adealink.weparty.profile.data.GetUserNoteRes
 import com.adealink.weparty.profile.data.GetUserinfoReq
@@ -59,4 +61,7 @@ interface ProfileHttpService {
 
     @POST("im/get/usernameNotes")
     suspend fun getUserNoteBy(@Body req: GetUserNoteReq): Rlt<Res<GetUserNoteRes>>
+
+    @POST("im/get/usernameNotes")
+    suspend fun getLiveRoomInfo(@Body req: GetUserLiveRoomReq): Rlt<Res<GetUserLiveRoomRes>>
 }

+ 34 - 0
module/profile/src/main/java/com/adealink/weparty/profile/viewmodel/ProfileRoomViewModel.kt

@@ -0,0 +1,34 @@
+package com.adealink.weparty.profile.viewmodel
+
+import androidx.lifecycle.MutableLiveData
+import com.adealink.frame.base.Rlt
+import com.adealink.frame.mvvm.viewmodel.BaseViewModel
+import com.adealink.weparty.App
+import com.adealink.weparty.module.room.data.RoomInfo
+import com.adealink.weparty.profile.data.GetUserLiveRoomReq
+import com.adealink.weparty.profile.datasource.remote.ProfileHttpService
+import kotlinx.coroutines.launch
+
+class ProfileRoomViewModel : BaseViewModel() {
+
+    private val profileHttpService by lazy {
+        App.instance.networkService.getHttpService(ProfileHttpService::class.java)
+    }
+
+    val userRoomInfoLD = MutableLiveData<Pair<String, RoomInfo?>>()
+    fun getUserRoomStatus(uid: String) {
+        viewModelScope.launch {
+            val rlt = profileHttpService.getLiveRoomInfo(GetUserLiveRoomReq(uid))
+            when (rlt) {
+                is Rlt.Failed -> {
+
+                }
+
+                is Rlt.Success -> {
+                    userRoomInfoLD.send(Pair(uid, rlt.data.data?.roomInfo))
+                }
+            }
+        }
+    }
+
+}

+ 1 - 1
module/profile/src/main/res/layout/layout_user_profile_room_online.xml

@@ -7,7 +7,7 @@
     tools:background="@drawable/profile_room_online_bg">
 
     <com.adealink.weparty.commonui.imageview.AvatarView
-        android:id="@+id/iv_avatar"
+        android:id="@+id/iv_cover"
         android:layout_width="36dp"
         android:layout_height="36dp"
         android:layout_marginTop="16dp"

+ 1 - 1
module/room/src/main/java/com/adealink/weparty/room/chat/viewmodel/ChatMessageViewModel.kt

@@ -42,7 +42,7 @@ class ChatMessageViewModel : BaseViewModel(), IChatMessageViewModel, IMessageLis
     }
 
 
-    fun onBarrageListChanged(barrages: List<Barrage>) {
+    private suspend fun onBarrageListChanged(barrages: List<Barrage>) {
         messagesLD.send(
             barrages.toMessages(true)
         )

+ 2 - 0
module/room/src/main/java/com/adealink/weparty/room/sdk/controller/IMessageController.kt

@@ -9,6 +9,8 @@ interface IMessageController<L : IMessageListener> : IController<L> {
 
     val messagesFlow: StateFlow<List<Barrage>>
 
+    val notificationFlow: StateFlow<List<Barrage>>
+
     suspend fun sendTextMessage(text: String): Rlt<Any>
 
 }

+ 7 - 4
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 io.trtc.tuikit.atomicxcore.api.barrage.BarrageType
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.StateFlow
@@ -43,12 +44,14 @@ class MessageController(override val ctx: IRoomContext, serialHandler: Handler)
     private val _messagesFlow = MutableStateFlow<List<Barrage>>(emptyList())
     override val messagesFlow: StateFlow<List<Barrage>> = _messagesFlow.asStateFlow()
 
+    private val _notificationFlow = MutableStateFlow<List<Barrage>>(emptyList())
+    override val notificationFlow: StateFlow<List<Barrage>> = _notificationFlow.asStateFlow()
+
     private fun subscribeToBarrageUpdates() {
         messageListJob = launch {
-            barrageStore?.barrageState?.messageList?.collect { messageList ->
-                // 当 messageList 更新时,通过 Flow 将新列表传递给UI层
-                // 关键点:这里接收到的是包含所有历史消息的【完整列表】
-                _messagesFlow.value = messageList
+            barrageStore?.barrageState?.messageList?.collect { allMessages ->
+//                allMessages.first().sequence
+                _messagesFlow.value = allMessages.filter { it.messageType == BarrageType.TEXT }
             }
         }
     }