1:完成才艺展示功能
This commit is contained in:
@@ -3116,6 +3116,12 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
|
||||
|
||||
}
|
||||
|
||||
fun dialogMessage(event: RoomInputEvent){
|
||||
if (publicScreenFragment != null) {
|
||||
publicScreenFragment!!.fasong(event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun countDownTimer() {
|
||||
releaseCountDownTimer()
|
||||
mCountDownTimer = object : CountDownTimer(3 * 1000L, 1000L) {
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.xscm.modulemain.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.xscm.modulemain.R
|
||||
|
||||
/**
|
||||
* 项目名称:羽声语音
|
||||
* 时间:2025/11/28 10:39
|
||||
* 用途:房间人才列表适配器,支持单选功能
|
||||
*/
|
||||
class RoomTalentAdapter(
|
||||
private val dataList: List<String>,
|
||||
private val onItemSelectedListener: (String, Int) -> Unit
|
||||
) : RecyclerView.Adapter<RoomTalentAdapter.ViewHolder>() {
|
||||
|
||||
private var selectedPosition = -1 // 默认没有选中项
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.item_room_talent, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = dataList[position]
|
||||
holder.bind(item, position)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = dataList.size
|
||||
|
||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
private val textView: TextView = itemView.findViewById(R.id.tv_talent)
|
||||
|
||||
fun bind(item: String, position: Int) {
|
||||
textView.text = item
|
||||
|
||||
// 设置选中状态
|
||||
if (position == selectedPosition) {
|
||||
textView.setBackgroundResource(R.drawable.bg_item_selected) // 选中背景
|
||||
textView.setTextColor(android.graphics.Color.parseColor("#3ABC6D"))
|
||||
} else {
|
||||
textView.setBackgroundResource(R.drawable.bg_item_normal) // 默认背景
|
||||
textView.setTextColor(android.graphics.Color.parseColor("#333333"))
|
||||
|
||||
}
|
||||
|
||||
// 设置点击事件
|
||||
itemView.setOnClickListener {
|
||||
// 如果点击的是已选中的项,不做处理
|
||||
if (position == selectedPosition) return@setOnClickListener
|
||||
|
||||
// 更新选中位置
|
||||
val previousPosition = selectedPosition
|
||||
selectedPosition = position
|
||||
|
||||
// 通知之前选中的项更新背景
|
||||
if (previousPosition != -1) {
|
||||
notifyItemChanged(previousPosition)
|
||||
}
|
||||
|
||||
// 通知当前选中的项更新背景
|
||||
notifyItemChanged(position)
|
||||
|
||||
// 回调选中的值和位置
|
||||
onItemSelectedListener(item, position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置选中的位置
|
||||
*/
|
||||
fun setSelectedPosition(position: Int) {
|
||||
if (position in 0 until itemCount && position != selectedPosition) {
|
||||
val previousPosition = selectedPosition
|
||||
selectedPosition = position
|
||||
|
||||
if (previousPosition != -1) {
|
||||
notifyItemChanged(previousPosition)
|
||||
}
|
||||
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前选中的位置
|
||||
*/
|
||||
fun getSelectedPosition(): Int = selectedPosition
|
||||
|
||||
/**
|
||||
* 获取当前选中的值
|
||||
*/
|
||||
fun getSelectedValue(): String? {
|
||||
return if (selectedPosition in 0 until itemCount) {
|
||||
dataList[selectedPosition]
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.xscm.modulemain.dialog
|
||||
|
||||
import android.content.Context
|
||||
import android.view.Gravity
|
||||
import android.view.ViewGroup
|
||||
import com.blankj.utilcode.util.ActivityUtils
|
||||
import com.blankj.utilcode.util.GsonUtils
|
||||
import com.blankj.utilcode.util.LogUtils
|
||||
import com.blankj.utilcode.util.ScreenUtils
|
||||
import com.hjq.toast.ToastUtils
|
||||
import com.xscm.modulemain.R
|
||||
import com.xscm.modulemain.activity.room.activity.RoomActivity
|
||||
import com.xscm.modulemain.adapter.RoomTalentAdapter
|
||||
import com.xscm.modulemain.databinding.DialogRoomTalentBinding
|
||||
import com.xscm.moduleutil.bean.RoomInputEvent
|
||||
import com.xscm.moduleutil.bean.RoomMessageEvent
|
||||
import com.xscm.moduleutil.bean.RoomMessageEvent.T
|
||||
import com.xscm.moduleutil.http.BaseObserver
|
||||
import com.xscm.moduleutil.http.RetrofitClient
|
||||
import com.xscm.moduleutil.listener.MessageListenerSingleton
|
||||
import com.xscm.moduleutil.utils.SpUtil
|
||||
import com.xscm.moduleutil.widget.dialog.BaseDialog
|
||||
import com.xscm.moduleutil.widget.floatingView.IFloatingView
|
||||
import io.reactivex.disposables.Disposable
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
/**
|
||||
* 项目名称:羽声语音
|
||||
* 时间:2025/11/28 9:25
|
||||
* 用途:签约房中的展示才艺
|
||||
*/
|
||||
class RoomTalentDialog(context: Context, val roomId: String) :
|
||||
BaseDialog<DialogRoomTalentBinding>(context, com.xscm.moduleutil.R.style.BaseDialogStyleH) {
|
||||
|
||||
var adapter: RoomTalentAdapter? = null
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.dialog_room_talent
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
setupWindow()
|
||||
mBinding.tvQx.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
mBinding.tvQd.setOnClickListener {
|
||||
if (adapter?.getSelectedValue()?.isEmpty() == true) {
|
||||
ToastUtils.show("请选择才艺")
|
||||
} else {
|
||||
var messageEvent =
|
||||
RoomInputEvent(SpUtil.getUserInfo().nickname + "选择了" + adapter?.getSelectedValue() + "才艺")
|
||||
(ActivityUtils.getTopActivity() as? RoomActivity)?.let { roomActivity ->
|
||||
roomActivity.dialogMessage(messageEvent)
|
||||
}
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun initData() {
|
||||
RetrofitClient.getInstance().skillList(object : BaseObserver<MutableList<String>>() {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
}
|
||||
|
||||
override fun onNext(t: MutableList<String>) {
|
||||
if (t.isNotEmpty()) {
|
||||
|
||||
t.addAll(t)
|
||||
t.addAll(t)
|
||||
t.addAll(t)
|
||||
adapter = RoomTalentAdapter(t) { selectedValue, position ->
|
||||
// 处理选中事件
|
||||
LogUtils.e("选中了: $selectedValue, 位置: $position")
|
||||
}
|
||||
|
||||
// 设置GridLayoutManager,每行显示4个item
|
||||
val layoutManager =
|
||||
androidx.recyclerview.widget.GridLayoutManager(context, 4)
|
||||
mBinding.recycleView.layoutManager = layoutManager
|
||||
mBinding.recycleView.adapter = adapter
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
private fun setupWindow() {
|
||||
val window = window ?: return
|
||||
window.setGravity(Gravity.BOTTOM)
|
||||
window.setLayout(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
(ScreenUtils.getAppScreenHeight() * 348f / 812).toInt()
|
||||
)
|
||||
window.setBackgroundDrawableResource(android.R.color.transparent)
|
||||
|
||||
val params = window.attributes
|
||||
params.windowAnimations = com.xscm.moduleutil.R.style.BaseDialogStyleH
|
||||
window.attributes = params
|
||||
}
|
||||
}
|
||||
9
MainModule/src/main/res/drawable/bg_item_normal.xml
Normal file
9
MainModule/src/main/res/drawable/bg_item_normal.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@android:color/white" />
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="#E0E0E0" />
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
||||
18
MainModule/src/main/res/drawable/bg_item_selected.xml
Normal file
18
MainModule/src/main/res/drawable/bg_item_selected.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<!-- <solid android:color="#E3F2FD" />-->
|
||||
|
||||
<gradient
|
||||
android:angle="90"
|
||||
android:endColor="#FBFBFF"
|
||||
android:startColor="#EBFFED"
|
||||
android:type="linear"
|
||||
android:useLevel="true" />
|
||||
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="#56E449" />
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
||||
|
||||
82
MainModule/src/main/res/layout/dialog_room_talent.xml
Normal file
82
MainModule/src/main/res/layout/dialog_room_talent.xml
Normal file
@@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_r14_1b1926"
|
||||
android:backgroundTint="@color/white"
|
||||
android:paddingHorizontal="@dimen/dp_16">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_13"
|
||||
android:paddingVertical="@dimen/dp_5"
|
||||
android:text="展示才艺"
|
||||
android:textColor="@color/color_FF333333"
|
||||
android:textSize="@dimen/sp_16"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycle_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="8dp"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
app:spanCount="4"
|
||||
app:layout_constraintBottom_toTopOf="@+id/ll_but"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_title"
|
||||
tools:itemCount="8"
|
||||
tools:listitem="@layout/item_room_talent"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_but"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_42"
|
||||
android:layout_marginBottom="@dimen/dp_14"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="@dimen/dp_18"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_qx"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/bg_r53_0dffb9"
|
||||
android:backgroundTint="@color/color_FF333333"
|
||||
android:gravity="center"
|
||||
android:text="取消"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/sp_14" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_qd"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="@dimen/sp_16"
|
||||
android:layout_weight="2"
|
||||
android:background="@drawable/bg_r53_0dffb9"
|
||||
android:gravity="center"
|
||||
android:text="确定"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/sp_14" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
21
MainModule/src/main/res/layout/item_room_talent.xml
Normal file
21
MainModule/src/main/res/layout/item_room_talent.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_marginHorizontal="@dimen/dp_6"
|
||||
android:layout_marginVertical="@dimen/dp_6">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_talent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="talent"
|
||||
android:padding="@dimen/dp_10"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textSize="@dimen/sp_14"
|
||||
android:background="@drawable/bg_item_normal"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user