|
|
@@ -1,5 +1,6 @@
|
|
|
package com.adealink.weparty.room.gift
|
|
|
|
|
|
+import androidx.fragment.app.viewModels
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
@@ -16,6 +17,7 @@ import com.adealink.weparty.commonui.ext.show
|
|
|
import com.adealink.weparty.commonui.recycleview.adapter.MultiTypeListAdapter
|
|
|
import com.adealink.weparty.commonui.recycleview.diffutil.BaseListDiffUtil
|
|
|
import com.adealink.weparty.commonui.recycleview.itemdecoration.GridSpacingItemDecoration
|
|
|
+import com.adealink.weparty.commonui.recycleview.itemdecoration.HorizontalItemDecoration
|
|
|
import com.adealink.weparty.commonui.toast.util.showFailedToast
|
|
|
import com.adealink.weparty.commonui.toast.util.showToast
|
|
|
import com.adealink.weparty.commonui.widget.BottomDialogFragment
|
|
|
@@ -35,10 +37,9 @@ import com.adealink.weparty.room.gift.adapter.RoomGiftItemViewBinder
|
|
|
import com.adealink.weparty.room.gift.adapter.RoomGiftTargetUserItemViewBinder
|
|
|
import com.adealink.weparty.room.gift.adapter.RoomGiftUserItemViewBinder
|
|
|
import com.adealink.weparty.room.gift.data.RoomGiftItemData
|
|
|
-import com.adealink.weparty.room.gift.data.RoomGiftTargetUserItemData
|
|
|
import com.adealink.weparty.room.gift.data.RoomGiftUserItemData
|
|
|
import com.adealink.weparty.room.gift.dialog.DiamondRechargeDialog
|
|
|
-import com.adealink.weparty.room.micseat.dispatcenter.getMicIndexName
|
|
|
+import com.adealink.weparty.room.gift.viewmodel.RoomGiftPanelViewModel
|
|
|
import com.adealink.weparty.room.sdk.service.roomService
|
|
|
import com.adealink.weparty.util.formatNumberStr
|
|
|
import kotlinx.coroutines.launch
|
|
|
@@ -47,6 +48,8 @@ class RoomGiftPanelDialog : BottomDialogFragment(R.layout.dialog_room_gift_panel
|
|
|
|
|
|
private val binding by viewBinding(DialogRoomGiftPanelBinding::bind)
|
|
|
private val roomGiftViewModel by fastLazy { GiftModule.getGiftViewModel(requireActivity()) }
|
|
|
+
|
|
|
+ private val giftPanelViewModel by viewModels<RoomGiftPanelViewModel>()
|
|
|
private val walletViewModel by fastLazy { WalletModule.getWalletViewModel(requireActivity()) }
|
|
|
private val userAdapter by fastLazy { MultiTypeListAdapter(BaseListDiffUtil()) }
|
|
|
private var userItemList = mutableListOf<RoomGiftUserItemData>()
|
|
|
@@ -77,25 +80,34 @@ class RoomGiftPanelDialog : BottomDialogFragment(R.layout.dialog_room_gift_panel
|
|
|
if (sendOnlyOne()) {
|
|
|
return@RoomGiftUserItemViewBinder
|
|
|
}
|
|
|
- userItemList.forEach {
|
|
|
+ userAdapter.notifyItemChanged<RoomGiftUserItemData> {
|
|
|
if (it.userInfo?.uid == clickedItem.userInfo?.uid) {
|
|
|
it.isSelected = !it.isSelected
|
|
|
+ true
|
|
|
+ } else {
|
|
|
+ false
|
|
|
}
|
|
|
}
|
|
|
- userAdapter.submitList(userItemList)
|
|
|
updateBottomPanel()
|
|
|
})
|
|
|
binding.rvUsers.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
|
|
|
+ binding.rvUsers.addItemDecoration(HorizontalItemDecoration(6.dp(), 0, 0))
|
|
|
binding.rvUsers.adapter = userAdapter
|
|
|
//礼物
|
|
|
giftAdapter.register(RoomGiftItemViewBinder { clickedItem ->
|
|
|
- giftItemList.forEach { itemData ->
|
|
|
- itemData.isSelected = itemData.giftInfo.id == clickedItem.giftInfo.id
|
|
|
- if (itemData.isSelected) {
|
|
|
- this@RoomGiftPanelDialog.selectGift = itemData.giftInfo
|
|
|
+ giftAdapter.notifyItemChanged<RoomGiftItemData> {
|
|
|
+ val oldSelected = it.isSelected
|
|
|
+ val nextSelected = it.giftInfo.id == clickedItem.giftInfo.id
|
|
|
+ if (nextSelected) {
|
|
|
+ this@RoomGiftPanelDialog.selectGift = it.giftInfo
|
|
|
+ }
|
|
|
+ if (oldSelected == nextSelected) {
|
|
|
+ false
|
|
|
+ } else {
|
|
|
+ it.isSelected = nextSelected
|
|
|
+ true
|
|
|
}
|
|
|
}
|
|
|
- giftAdapter.submitList(giftItemList)
|
|
|
binding.vNumber.setNumber(1)
|
|
|
updateBottomPanel()
|
|
|
})
|
|
|
@@ -166,29 +178,23 @@ class RoomGiftPanelDialog : BottomDialogFragment(R.layout.dialog_room_gift_panel
|
|
|
walletViewModel?.diamondLD?.observe(viewLifecycleOwner) {
|
|
|
binding.tvBalance.text = formatNumberStr(it)
|
|
|
}
|
|
|
- val tagetUid = targetUid
|
|
|
- if (tagetUid.isNullOrEmpty()) {
|
|
|
- lifecycleScope.launch {
|
|
|
- roomService.seatController.micSeatsFlow.collect { seatInfos ->
|
|
|
- val seatInfoList = seatInfos.entries.filter {
|
|
|
- !it.value.isSeatEmpty() && it.value.userInfo.userID != ProfileModule.getMyUid()
|
|
|
- }.sortedBy { it.key }
|
|
|
- val itemList = seatInfoList.map { seatInfo ->
|
|
|
- RoomGiftUserItemData(
|
|
|
- ProfileModule.getCacheUserInfo(seatInfo.value.userInfo.userID),
|
|
|
- getMicIndexName(seatInfo.key),
|
|
|
- isSelected = userItemList.find { it.userInfo?.uid == seatInfo.value.userInfo.userID }?.isSelected ?: false
|
|
|
- )
|
|
|
- }
|
|
|
- userItemList.clear()
|
|
|
- userItemList.addAll(itemList)
|
|
|
- userAdapter.submitList(userItemList)
|
|
|
+
|
|
|
+ giftPanelViewModel.userInfoListLD.observe(viewLifecycleOwner) { itemLIst ->
|
|
|
+ if (sendOnlyOne()) {
|
|
|
+ val userItem = itemLIst?.firstOrNull()
|
|
|
+ if (userItem == null) {
|
|
|
+ userAdapter.submitList(emptyList())
|
|
|
+ } else {
|
|
|
+ userAdapter.submitList(listOf(userItem))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ val itemList = itemLIst.mapNotNull { it as? RoomGiftUserItemData }.onEach { item ->
|
|
|
+ item.isSelected = userItemList.find { it.userInfo?.uid == item.userInfo?.uid }?.isSelected ?: false
|
|
|
}
|
|
|
+ userItemList.clear()
|
|
|
+ userItemList.addAll(itemList)
|
|
|
+ userAdapter.submitList(userItemList)
|
|
|
}
|
|
|
- } else {
|
|
|
- userAdapter.submitList(
|
|
|
- listOf(RoomGiftTargetUserItemData(ProfileModule.getCacheUserInfo(tagetUid)))
|
|
|
- )
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -200,6 +206,20 @@ class RoomGiftPanelDialog : BottomDialogFragment(R.layout.dialog_room_gift_panel
|
|
|
}
|
|
|
roomGiftViewModel?.getGifts(roomId)
|
|
|
walletViewModel?.refreshWalletData()
|
|
|
+
|
|
|
+ val tagetUid = targetUid
|
|
|
+ if (tagetUid.isNullOrEmpty()) {
|
|
|
+ lifecycleScope.launch {
|
|
|
+ roomService.seatController.micSeatsFlow.collect { seatInfos ->
|
|
|
+ val seatInfoList = seatInfos.entries.filter {
|
|
|
+ !it.value.isSeatEmpty() && it.value.userInfo.userID != ProfileModule.getMyUid()
|
|
|
+ }.sortedBy { it.key }
|
|
|
+ giftPanelViewModel.updateSeatUser(seatInfoList)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ giftPanelViewModel.setTargetUser(tagetUid)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private fun updateBottomPanel() {
|
|
|
@@ -234,6 +254,7 @@ class RoomGiftPanelDialog : BottomDialogFragment(R.layout.dialog_room_gift_panel
|
|
|
CommonDialog.Builder()
|
|
|
.title(getCompatString(R.string.room_send_gift_balance_not_enough))
|
|
|
.setShowDefaultCancel(true)
|
|
|
+ .showTopClosetButton(true)
|
|
|
.onPositive {
|
|
|
WalletModule.showRechargeDialog(childFragmentManager, Currency.DIAMOND)
|
|
|
}
|