feat:普通房开放跨房PK入口
feat:PK入口迁移到玩法弹窗(待完善,目前注释了关键代码:下个版本的需求)
This commit is contained in:
@@ -4,14 +4,20 @@ import android.widget.ImageView
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter
|
||||
import com.chad.library.adapter.base.BaseViewHolder
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.avroom.bean.RoomGameplayItem
|
||||
import com.chwl.app.ui.utils.load
|
||||
import com.chwl.core.room.bean.RoomIcon
|
||||
|
||||
class RoomGameplayAdapter :
|
||||
BaseQuickAdapter<RoomIcon, BaseViewHolder>(R.layout.room_gameplay_item2) {
|
||||
override fun convert(helper: BaseViewHolder, item: RoomIcon?) {
|
||||
helper.setText(R.id.tv_name, item?.name)
|
||||
BaseQuickAdapter<RoomGameplayItem, BaseViewHolder>(R.layout.room_gameplay_item2) {
|
||||
override fun convert(helper: BaseViewHolder, item: RoomGameplayItem?) {
|
||||
helper.setText(R.id.tv_name, item?.getName())
|
||||
val iconView = helper.getView<ImageView>(R.id.iv_icon)
|
||||
iconView.load(item?.icon)
|
||||
val iconRes = item?.getIconRes()
|
||||
if (iconRes != null) {
|
||||
iconView.setImageResource(iconRes)
|
||||
} else {
|
||||
val iconUrl = item?.getIconUrl()
|
||||
iconView.load(iconUrl ?: "")
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package com.chwl.app.avroom.bean
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.chwl.app.avroom.dialog.RoomGameplayDialog
|
||||
import com.chwl.core.room.bean.RoomIcon
|
||||
import java.io.Serializable
|
||||
|
||||
@Keep
|
||||
interface RoomGameplayItem : Serializable {
|
||||
|
||||
fun getName(): String?
|
||||
|
||||
fun getIconUrl(): String?
|
||||
|
||||
fun getIconRes(): Int?
|
||||
|
||||
fun onItemClick(dialog: RoomGameplayDialog)
|
||||
|
||||
@Keep
|
||||
class RoomIconItem(
|
||||
private val roomIcon: RoomIcon,
|
||||
private val onClick: (RoomGameplayDialog, RoomIcon) -> Unit
|
||||
) : RoomGameplayItem {
|
||||
override fun getName(): String? {
|
||||
return roomIcon.name
|
||||
}
|
||||
|
||||
override fun getIconUrl(): String? {
|
||||
return roomIcon.icon
|
||||
}
|
||||
|
||||
override fun getIconRes(): Int? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onItemClick(dialog: RoomGameplayDialog) {
|
||||
onClick.invoke(dialog, roomIcon)
|
||||
}
|
||||
}
|
||||
|
||||
@Keep
|
||||
class CustomItem(
|
||||
private val name: String,
|
||||
private val iconRes: Int,
|
||||
private val onClick: (RoomGameplayDialog, CustomItem) -> Unit
|
||||
) : RoomGameplayItem {
|
||||
override fun getName(): String {
|
||||
return name
|
||||
}
|
||||
|
||||
override fun getIconUrl(): String? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getIconRes(): Int {
|
||||
return iconRes
|
||||
}
|
||||
|
||||
override fun onItemClick(dialog: RoomGameplayDialog) {
|
||||
onClick.invoke(dialog, this)
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,17 +11,27 @@ import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.avroom.activity.CreatePKActivity
|
||||
import com.chwl.app.avroom.adapter.RoomGameplayAdapter
|
||||
import com.chwl.app.avroom.anotherroompk.RoomPKCreateActivity
|
||||
import com.chwl.app.avroom.bean.RoomGameplayItem
|
||||
import com.chwl.app.avroom.singleroompk.SingleRoomPKCreateActivity
|
||||
import com.chwl.app.databinding.RoomGameplayDialogBinding
|
||||
import com.chwl.app.treasure_box.widget.GoldBoxHelper
|
||||
import com.chwl.app.ui.webview.CommonWebViewActivity
|
||||
import com.chwl.app.ui.webview.room_banner.RoomWebDialogActivity
|
||||
import com.chwl.app.utils.CommonJumpHelper
|
||||
import com.chwl.core.auth.AuthModel
|
||||
import com.chwl.core.manager.AvRoomDataManager
|
||||
import com.chwl.core.room.anotherroompk.SingleRoomPKModel
|
||||
import com.chwl.core.room.bean.RoomIcon
|
||||
import com.chwl.core.room.core.RoomDataService
|
||||
import com.chwl.core.room.game.bean.BaiShunGameConfig
|
||||
import com.chwl.core.room.model.AvRoomModel
|
||||
import com.chwl.core.super_admin.util.SuperAdminUtil
|
||||
import com.chwl.core.support.room.AudioRoomContext
|
||||
import com.chwl.core.utils.CurrentTimeUtils
|
||||
import com.chwl.library.utils.ResUtil
|
||||
import com.chwl.library.utils.SingleToastUtil
|
||||
import com.example.lib_utils.ktx.asLifecycle
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
@@ -64,8 +74,7 @@ class RoomGameplayDialog :
|
||||
|
||||
private fun initView() {
|
||||
adapter.setOnItemClickListener { _, view, position ->
|
||||
val item = adapter.getItem(position) as RoomIcon
|
||||
jump(item)
|
||||
adapter.getItem(position)?.onItemClick(this)
|
||||
}
|
||||
binding?.recyclerView?.adapter = adapter
|
||||
}
|
||||
@@ -88,30 +97,49 @@ class RoomGameplayDialog :
|
||||
|
||||
private fun requestData() {
|
||||
val dataService =
|
||||
AudioRoomContext.get()?.findAbility<RoomDataService>(RoomDataService::class.java.simpleName)
|
||||
AudioRoomContext.get()
|
||||
?.findAbility<RoomDataService>(RoomDataService::class.java.simpleName)
|
||||
val cacheKey = "gameplay_list#${parentFragment.hashCode()}"
|
||||
val list = dataService?.getData(cacheKey) as? List<RoomIcon>
|
||||
if (!list.isNullOrEmpty()) {
|
||||
loadData(list)
|
||||
loadSuccess(list)
|
||||
return
|
||||
}
|
||||
val disposable = AvRoomModel.get().roomGamePlayList
|
||||
.doOnError {
|
||||
SingleToastUtil.showToast(it.message)
|
||||
switchStatus(-2)
|
||||
loadFail(it)
|
||||
}
|
||||
.subscribe { it: List<RoomIcon> ->
|
||||
dataService?.putData(cacheKey, it)
|
||||
loadData(it)
|
||||
loadSuccess(it)
|
||||
}
|
||||
getCompositeDisposable().add(disposable)
|
||||
}
|
||||
|
||||
private fun loadData(list: List<RoomIcon>?) {
|
||||
if (list.isNullOrEmpty()) {
|
||||
private fun loadSuccess(list: List<RoomIcon>?) {
|
||||
val finalList = getLocalList()
|
||||
list?.let {
|
||||
finalList.addAll(list.map {
|
||||
RoomGameplayItem.RoomIconItem(it) { dialog, item ->
|
||||
jump(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
if (finalList.isEmpty()) {
|
||||
switchStatus(-1)
|
||||
} else {
|
||||
adapter.setNewData(list)
|
||||
adapter.setNewData(finalList)
|
||||
switchStatus(1)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadFail(throwable: Throwable) {
|
||||
SingleToastUtil.showToast(throwable.message)
|
||||
val finalList = getLocalList()
|
||||
if (finalList.isEmpty()) {
|
||||
switchStatus(-2)
|
||||
} else {
|
||||
adapter.setNewData(finalList)
|
||||
switchStatus(1)
|
||||
}
|
||||
}
|
||||
@@ -214,6 +242,157 @@ class RoomGameplayDialog :
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLocalList(): MutableList<RoomGameplayItem> {
|
||||
val list = ArrayList<RoomGameplayItem>()
|
||||
// getPkItem()?.let {
|
||||
// list.add(it)
|
||||
// }
|
||||
// getRoomPkItem()?.let {
|
||||
// list.add(it)
|
||||
// }
|
||||
// getSingleRoomPkItem()?.let {
|
||||
// list.add(it)
|
||||
// }
|
||||
return list
|
||||
}
|
||||
|
||||
private fun getPkItem(): RoomGameplayItem? {
|
||||
val context = context ?: return null
|
||||
if (SuperAdminUtil.isSuperAdmin()) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenGame) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isSingleRoom) {
|
||||
return null
|
||||
}
|
||||
val roomInfo = AvRoomDataManager.get().mCurrentRoomInfo
|
||||
if (roomInfo == null) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isManager && !AvRoomDataManager.get().isCpRoom) {
|
||||
val str =
|
||||
if (AvRoomDataManager.get().isOpenPKMode) context.resources.getString(R.string.room_was_in_PK) else context.resources.getString(
|
||||
R.string.room_PK_mode
|
||||
)
|
||||
val icon =
|
||||
if (AvRoomDataManager.get().isOpenPKMode) R.drawable.ic_room_opt_op_pk else R.drawable.ic_room_opt_in_pk
|
||||
return RoomGameplayItem.CustomItem(str, icon) { dialog, item ->
|
||||
if (AvRoomDataManager.get().isDatingMode) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_01))
|
||||
return@CustomItem
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenAnotherPKMode) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_02))
|
||||
return@CustomItem
|
||||
}
|
||||
dialog.dismissAllowingStateLoss()
|
||||
CreatePKActivity.start(context)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun getRoomPkItem(): RoomGameplayItem? {
|
||||
val context = context ?: return null
|
||||
if (SuperAdminUtil.isSuperAdmin()) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenGame) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isSingleRoom) {
|
||||
return null
|
||||
}
|
||||
val roomInfo = AvRoomDataManager.get().mCurrentRoomInfo
|
||||
if (roomInfo == null) {
|
||||
return null
|
||||
}
|
||||
if ((AvRoomDataManager.get().isRoomOwner || AvRoomDataManager.get().isSuperAdmin) &&
|
||||
!AvRoomDataManager.get().isCpRoom
|
||||
) {
|
||||
val str =
|
||||
if (AvRoomDataManager.get().isOpenAnotherPKMode) ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_03) else ResUtil.getString(
|
||||
R.string.avroom_dialog_roomoperationdialog_04
|
||||
)
|
||||
val icon =
|
||||
if (AvRoomDataManager.get().isOpenAnotherPKMode) R.drawable.ic_room_opt_another_pk_in else R.drawable.ic_room_opt_another_pk_open
|
||||
return RoomGameplayItem.CustomItem(str, icon) { dialog, item ->
|
||||
if (AvRoomDataManager.get().isDatingMode) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_05))
|
||||
return@CustomItem
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenPKMode) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_06))
|
||||
return@CustomItem
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenAnotherPKMode) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_07))
|
||||
return@CustomItem
|
||||
}
|
||||
dismissAllowingStateLoss()
|
||||
RoomPKCreateActivity.start(context)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun getSingleRoomPkItem(): RoomGameplayItem? {
|
||||
val context = context ?: return null
|
||||
if (SuperAdminUtil.isSuperAdmin()) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenGame) {
|
||||
return null
|
||||
}
|
||||
if (!AvRoomDataManager.get().isSingleRoom) {
|
||||
return null
|
||||
}
|
||||
val pkBean = AvRoomDataManager.get().roomPkLiveData.value
|
||||
if (AvRoomDataManager.get().isRoomOwner && !AvRoomDataManager.get().isCpRoom) {
|
||||
var str =
|
||||
if (AvRoomDataManager.get().isOpenAnotherPKMode) ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_08) else ResUtil.getString(
|
||||
R.string.avroom_dialog_roomoperationdialog_09
|
||||
)
|
||||
if (pkBean != null) {
|
||||
if (pkBean.pkState == 2 &&
|
||||
(pkBean.winUid == 0L || pkBean.winUid == AuthModel.get().currentUid || pkBean.penaltyEndTime < CurrentTimeUtils.getCurrentTime())
|
||||
) {
|
||||
str = ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_010)
|
||||
}
|
||||
}
|
||||
val icon =
|
||||
if (AvRoomDataManager.get().isOpenAnotherPKMode) R.drawable.ic_room_opt_single_pk_open else R.drawable.ic_room_opt_single_pk_in
|
||||
val finalStr = str
|
||||
return RoomGameplayItem.CustomItem(str, icon) { dialog, item ->
|
||||
if (pkBean != null && ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_011) == finalStr) {
|
||||
SingleRoomPKModel.endSingleRoomPk(pkBean.roundId)
|
||||
.doOnSuccess { s: String? ->
|
||||
SingleToastUtil.showToast(
|
||||
ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_012)
|
||||
)
|
||||
}
|
||||
.doOnError { throwable: Throwable ->
|
||||
SingleToastUtil.showToast(
|
||||
throwable.message
|
||||
)
|
||||
}
|
||||
.subscribe()
|
||||
dismissAllowingStateLoss()
|
||||
return@CustomItem
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenAnotherPKMode) {
|
||||
SingleToastUtil.showToast(ResUtil.getString(R.string.avroom_dialog_roomoperationdialog_013))
|
||||
return@CustomItem
|
||||
}
|
||||
dismissAllowingStateLoss()
|
||||
SingleRoomPKCreateActivity.start(context)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
interface GameplayDialogListener {
|
||||
fun onShowBaiShunGame(url: String, config: BaiShunGameConfig)
|
||||
}
|
||||
|
@@ -191,7 +191,7 @@ public class RoomOperationDialog extends BottomSheetDialog {
|
||||
return;
|
||||
}
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (roomInfo == null || roomInfo.getIsPermitRoom() != 1) {
|
||||
if (roomInfo == null) {
|
||||
return;
|
||||
}
|
||||
if ((AvRoomDataManager.get().isRoomOwner() || AvRoomDataManager.get().isSuperAdmin()) &&
|
||||
|
@@ -2,7 +2,6 @@ package com.chwl.core.room.bean
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.chwl.core.bean.IRouterData
|
||||
import com.chwl.core.room.game.bean.BaiShunGameConfig
|
||||
|
||||
/**
|
||||
* Created by Max on 2024/2/20 11:49
|
||||
|
Reference in New Issue
Block a user