语音社交源码群聊开发,需要实现礼物打赏功能

2023-10-15 10:30

本文主要是介绍语音社交源码群聊开发,需要实现礼物打赏功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

语音社交源码群聊打赏礼物的效果如图:

在这里插入图片描述

语音社交源码礼物和背包都是可以很多页的,可能这是唯一稍微麻烦一点的地方,直接贴全部详细代码。
1、首先写一个名为FragmentRoomDetailGift的DialogFragment,是整个的语音社交源码的弹框(包括礼物和背包模块,以及点击可以跳转到别的模块的小游戏“摇糖罐”),FragmentRoomDetailGift继承自我封装的抽象类BaseDialogFragment2。
2、语音社交源码礼物和背包的分页,思路是创建一个view的集合,每页设置8个礼物,下面会贴出礼物的页面GiftFragment.kt的代码。
3、关于语音社交源码送礼物走的接口就是看具体情况了,现在送礼物走的是接口,然后回调走的websocket,通知语音社交源码房间里的其他人进行下一步操作。其实最好的方案是进房间走一次接口,其他所有的操作都走websocket,关于websocket这个分类其他文章会写。

BaseDialogFragment2.kt的代码:

abstract class BaseDialogFragment2 : DialogFragment() {protected val TAG = javaClass.simpleNameprotected lateinit var mContext: Contextabstract val layoutRes: Intoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)mContext = activity as Context}override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {var rootView = inflater.inflate(layoutRes, null)mContext = activity as Contextreturn rootView}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {initView()super.onViewCreated(view, savedInstanceState)}private fun initView() {initAll()setListener()processLogic()}protected abstract fun initAll()protected abstract fun setListener()protected abstract fun processLogic()protected fun hideSoftKeyboard(view: View) {activity?.inputMethodManager?.hideSoftInputFromWindow(view.windowToken, 0)}protected fun showSoftKeyboard(view: View) {activity?.inputMethodManager?.showSoftInput(view, InputMethodManager.SHOW_FORCED)}
}


FragmentRoomDetailGift.kt的代码:

class FragmentRoomDetailGift : BaseDialogFragment2() {override val layoutRes: Intget() = R.layout.dialog_room_detail_gift//礼物和背包的fragment的集合var mFragments: Array<Fragment>? = null//礼物和背包的标题集合var title: Array<String>? = null//礼物和背包的pageadaptervar adapter: CustomFragmentPagerAdapter? = null//选择打赏对象的弹框var popGiftLeft: PopGiftLeft? = null//选择赠送多个礼物的弹框var popGiftRight: PopGiftRight? = null//一个礼物赠送多次的自定义弹框,这里的数据是本地的var beenRight = arrayListOf<GiftRightBean>()//麦上人员的信息/选择被打赏的人var beenResultLeft = mutableListOf<RoomDetailBean.HousePitBean>()//一次送出多个礼物的礼物数据var beanResultRight: GiftRightBean? = null//点击摇糖罐的接口的实现方法var mListener: OnFragmentInteractionListener? = null//语音直播间的idvar room_id = ""//语音直播间的环信idvar chatrooms = ""//送给某人的选中的user_idvar to_user_id = ""override fun onStart() {super.onStart()//弹框的样式和动画等的配置dialog.window.setBackgroundDrawable(ColorDrawable(getResources().getColor(R.color.transparent)))dialog.window.setGravity(Gravity.BOTTOM)dialog.window.setLayout(ScreenUtils.getScreenWidth(), (ScreenUtils.getScreenHeight() * 5.2 / 10).toInt())dialog.window.setWindowAnimations(R.style.ShowDialogBottom)}override fun onAttach(context: Context) {super.onAttach(context)if (context is OnFragmentInteractionListener) {mListener = context as OnFragmentInteractionListener} else {throw RuntimeException("$context must implement OnFragmentInteractionListener")}}override fun onDetach() {super.onDetach()mListener = null}override fun initAll() {
//        setStyle(DialogFragment.STYLE_NO_FRAME, R.style.custom_dialog1)//从直播间详情传递的麦上人员信息var list = arguments?.getSerializable("bean") as MutableList<RoomDetailBean.HousePitBean>beenResultLeft = list.filter { !it.user_id.isNullOrEmpty() } as MutableList<RoomDetailBean.HousePitBean>beenResultLeft?.forEach {it.isChecked = false}//房主在麦位,放在第一个显示var admin = beenResultLeft?.filter { it.pit_number == 9 }if (admin?.size != 0) {beenResultLeft?.removeAll(admin)beenResultLeft?.addAll(0, admin)}//不能打赏自己var me = beenResultLeft?.filter { it.user_id == MyApplication.getInstance().user.user_id }beenResultLeft?.removeAll(me)room_id = arguments?.getString("id") ?: ""chatrooms = arguments?.getString("chatrooms") ?: ""to_user_id = arguments?.getString("to_user_id") ?: ""beenResultLeft?.forEach {if (it.user_id == to_user_id) {it.isChecked = true}}refreshCheckedStatus(1)tv_money.text = MyApplication.getInstance().user.moneyif (MyApplication.getInstance().user.is_open_tangguo == 1) {//开启tv_sugar.visibility = View.VISIBLE} else {//关闭tv_sugar.visibility = View.GONE}title = arrayOf("礼物", "背包")mFragments = arrayOf(GiftFragment.newInstance(null), BagFragment.newInstance(null))adapter = CustomFragmentPagerAdapter(mFragments, childFragmentManager)svp.adapter = adapterctl.setViewPager(svp, title)svp.offscreenPageLimit = 2svp.setScroll(true)svp.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {override fun onPageScrollStateChanged(state: Int) {}override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {if (position == 1) {btn_all_bag.visibility = View.VISIBLE} else {btn_all_bag.visibility = View.GONE}}override fun onPageSelected(position: Int) {}})beenRight?.clear()beenRight?.also {it.add(GiftRightBean()?.also { it.name = "1";it.content = "一心一意" })it.add(GiftRightBean()?.also { it.name = "10";it.content = "十全十美" })it.add(GiftRightBean()?.also { it.name = "66";it.content = "一切顺利" })it.add(GiftRightBean()?.also { it.name = "99";it.content = "天长地久" })it.add(GiftRightBean()?.also { it.name = "188";it.content = "要抱抱" })it.add(GiftRightBean()?.also { it.name = "520";it.content = "我爱你" })it.add(GiftRightBean()?.also { it.name = "1314";it.content = "一生一世" })}}override fun setListener() {tv_sugar.setOnClickListener {dismiss()mListener?.onFragmentInteraction(1)}//打赏全麦btn_all_mics.setOnClickListener {if (beenResultLeft == null || beenResultLeft.size == 0) {ToastUtils.showShort("没有打赏对象")return@setOnClickListener}if (beenResultLeft.filter { it.isChecked }.size == beenResultLeft?.size) {beenResultLeft.forEach {it.isChecked = false}} else {beenResultLeft.forEach {it.isChecked = true}}refreshCheckedStatus(2)}//选择打赏对象tv_choose.setOnClickListener {if (beenResultLeft == null || beenResultLeft.size == 0) {ToastUtils.showShort("没有打赏对象")return@setOnClickListener}if (popGiftLeft == null) {popGiftLeft = PopGiftLeft(mContext, beenResultLeft) {beenResultLeft = itrefreshCheckedStatus(2)}}popGiftLeft?.setData(beenResultLeft)var windowPos = SizeUtils.calculatePopWindowPos2(tv_choose, popGiftLeft?.contentView)popGiftLeft?.showAtLocation(tv_choose, Gravity.TOP and Gravity.LEFT, windowPos[0], windowPos[1] - 200)}tv_count.setOnClickListener {if (popGiftRight == null) {popGiftRight = PopGiftRight(mContext, beenRight) {beanResultRight = ittv_count.text = beanResultRight?.name}}var windowPos = SizeUtils.calculatePopWindowPos3(tv_count, popGiftRight?.contentView)popGiftRight?.showAtLocation(tv_count, Gravity.TOP or Gravity.LEFT, windowPos[0], windowPos[1])}//跳转到充值tv_money.setOnClickListener {startActivityForResult<ChargeActivity>(1)}//确认打赏的按钮btn_pay.setOnClickListener {var giftBeen = listOf<GiftBean>()when (svp.currentItem) {0 -> {giftBeen = (mFragments!![0] as GiftFragment).allBeen.filter { it.isChecked }}1 -> {giftBeen = (mFragments!![1] as BagFragment).allBeen.filter { it.isChecked }}}if (giftBeen == null || giftBeen.size == 0) {ToastUtils.showShort("请选择礼物")return@setOnClickListener}var userBeen = beenResultLeft.filter { it.isChecked }if (userBeen == null || userBeen.size == 0) {ToastUtils.showShort("请选择打赏对象")return@setOnClickListener}var giftBean = giftBeen[0]var pits = ""var user_ids = ""var pit_names = ""userBeen.forEach {pits = pits + it.pit_number + ","user_ids = user_ids + it.user_id + ","pit_names = pit_names + it.nickname + ","}pits = pits.substring(0, pits.length - 1)user_ids = user_ids.substring(0, user_ids.length - 1)pit_names = pit_names.substring(0, pit_names.length - 1)giveGift(user_ids, giftBean, tv_count.text.toString(), room_id, pits, pit_names, 0, userBeen.size)}//背包礼物全部送出的按钮btn_all_bag.setOnClickListener {var giftBeen = listOf<GiftBean>()when (svp.currentItem) {1 -> {giftBeen = (mFragments!![1] as BagFragment).allBeen.filter { it.isChecked }}}if (giftBeen == null || giftBeen.size == 0) {ToastUtils.showShort("请选择礼物")return@setOnClickListener}var userBeen = beenResultLeft.filter { it.isChecked }if (userBeen == null || userBeen.size == 0) {ToastUtils.showShort("请选择打赏对象")return@setOnClickListener}if (userBeen.size > 1) {ToastUtils.showShort("只能送给一个打赏对象")return@setOnClickListener}var giftBean = giftBeen[0]var pits = ""var user_ids = ""var pit_names = ""userBeen.forEach {pits = pits + it.pit_number + ","user_ids = user_ids + it.user_id + ","pit_names = pit_names + it.nickname + ","}pits = pits.substring(0, pits.length - 1)user_ids = user_ids.substring(0, user_ids.length - 1)pit_names = pit_names.substring(0, pit_names.length - 1)AlertDialog.Builder(mContext).setMessage("确定要送出吗?").setPositiveButton("确定") { p0, p1 -> giveGift(user_ids, giftBean, giftBean.numbers, room_id, pits, pit_names, 1, 1) }.setNegativeButton("取消", null).show()}}override fun processLogic() {}interface OnFragmentInteractionListener {fun onFragmentInteraction(code: Int)}//赠送礼物接口fun giveGift(user_id: String, gift: GiftBean, number: String, id: String, pit: String, pit_names: String, send_all_status: Int, size: Int) {Net.post(mContext, UrlUtils().giveGift, mapOf("user_id" to user_id, "gift_id" to if (svp.currentItem == 0) gift.id else gift.gift_id, "number" to number, "id" to id, "pit" to pit, "type" to svp.currentItem + 1, "send_all_status" to send_all_status), object : Net.Callback(mContext, true) {override fun onSuccess(t: Any?) {getData()if (svp.currentItem == 1) {//从背包送的礼物(mFragments!![1] as BagFragment).refresh(gift.gift_id, number.toInt(), send_all_status, size)}pit_names?.split(",").forEach {val message = EMMessage.createTxtSendMessage("${MyApplication.getInstance().user.nickname}送给$it", chatrooms)message.from = MyApplication.getInstance().user.emchat_usernamemessage.chatType = EMMessage.ChatType.ChatRoommessage.setAttribute("action", 2)message.setAttribute("gift_id", if (svp.currentItem == 0) gift.id else gift.gift_id)message.setAttribute("gift_pic", gift.picture)message.setAttribute("gift_name", gift.name)message.setAttribute("gift_price", gift.price)message.setAttribute("gift_spectial", gift.special)message.setAttribute("gift_num", number)gift.pits = pitmessage.setAttribute("pits", gift.pits)message.setAttribute("user_id", MyApplication.getInstance().user.user_id)message.setAttribute("nickname", MyApplication.getInstance().user.nickname)message.setAttribute("avatar", MyApplication.getInstance().user.head_picture)message.setAttribute("rank_id", MyApplication.getInstance().user.rank_id)message.setAttribute("nobility_name", MyApplication.getInstance().user.nobility_name)message.setAttribute("role", MyApplication.getInstance().user.role)EMClient.getInstance().chatManager().sendMessage(message)}EventBusUtils.post(EventBusUtils.EventMessage(EVENT_MESSAGE_GIFT_SEND, gift))//自己展示动画val jsonObject = JSONObject()jsonObject.put("type", "giveGift")jsonObject.put("token", MyApplication.getInstance().token)jsonObject.put("room_id", room_id)jsonObject.put("user_id", user_id)jsonObject.put("gift_id", if (svp.currentItem == 0) gift.id else gift.gift_id)jsonObject.put("number", number)WebSocketUtils.getInstance().sendMessage(jsonObject.toString())val jsonObject1 = JSONObject()jsonObject1.put("type", "refresh2")jsonObject1.put("token", MyApplication.getInstance().token)jsonObject1.put("room_id", room_id)jsonObject1.put("user_id", user_id)jsonObject1.put("gift_id", if (svp.currentItem == 0) gift.id else gift.gift_id)jsonObject1.put("number", number)WebSocketUtils.getInstance().sendMessage(jsonObject1.toString())userMoney()//送完礼物之后,礼物框不消失// this@FragmentRoomDetailGift.dismiss()}override fun onError(apiException: Throwable?) {if (apiException is ApiException) {when (apiException.code) {2 -> {DialogMoneyCharge(mContext) {dismiss()mContext.startActivity<ChargeActivity>()}.show()}}}}override fun onMessage(status: Int, msg: String) {super.onMessage(status, msg)ToastUtils.showShort(msg)}})}//更新金币的数量fun userMoney() {Net.post(mContext, UrlUtils().userMoney, emptyMap(), object : Net.Callback() {override fun onSuccess(t: Any?) {var user = MyApplication.getInstance().useruser.money = t.toString()MyApplication.getInstance().user = user}override fun onError(apiException: Throwable?) {}})}//更新选中的打赏对象的状态fun refreshCheckedStatus(first: Int) {var list1 = beenResultLeft.filter { it.isChecked }if (first == 1 && list1.size == 0) {//点击进入默认选中房主,如果房主在麦位this.beenResultLeft.forEach {if (it?.pit_number == 9 && !TextUtils.isEmpty(it?.user_id)) {it?.isChecked = true}}}var list = beenResultLeft.filter { it.isChecked }when (list.size) {0 -> {tv_choose.text = "选择打赏对象"btn_all_mics.setBackgroundResource(R.drawable.bg_r99_trans_colormain)btn_all_mics.setTextColor(mContext.resources.getColor(R.color.color_main))}beenResultLeft.size -> {tv_choose.text = "${list.size} 打赏全麦"btn_all_mics.setBackgroundResource(R.drawable.bg_r99_colormain)btn_all_mics.setTextColor(mContext.resources.getColor(R.color.white))}9 -> {tv_choose.text = "9 打赏全麦"btn_all_mics.setBackgroundResource(R.drawable.bg_r99_colormain)btn_all_mics.setTextColor(mContext.resources.getColor(R.color.white))}else -> {var s = ""list.forEach {s = s + it.nickname + ","}s = s.substring(0, s.length - 1)tv_choose.text = "${list.size} ${s}"btn_all_mics.setBackgroundResource(R.drawable.bg_r99_trans_colormain)btn_all_mics.setTextColor(mContext.resources.getColor(R.color.color_main))}}}override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {super.onActivityResult(requestCode, resultCode, data)if (requestCode == 1) {getData()}}/** 获取金币数量,在金币变动之后调用* */fun getData() {Net.post(mContext, UrlUtils().userInfo, emptyMap(), object : Net.Callback(mContext, false) {override fun onSuccess(t: Any?) {val gson = Gson()var userBean = gson.fromJson(JSON.toJSONString(t), UserBean::class.java)MyApplication.getInstance().user = userBeantv_money.text = MyApplication.getInstance().user.money}override fun onError(apiException: Throwable?) {}})}
}


layout dialog_room_detail_gift.xml的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/bg_r8_14123a"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center_vertical"android:orientation="horizontal"android:paddingLeft="15dp"android:paddingRight="15dp"><com.flyco.tablayout.SlidingTabLayoutandroid:id="@+id/ctl"android:layout_width="wrap_content"android:layout_height="@dimen/topbar_height"app:tl_indicator_color="@color/color_main"app:tl_indicator_corner_radius="2dp"app:tl_indicator_gravity="BOTTOM"app:tl_indicator_height="3dp"app:tl_indicator_style="NORMAL"app:tl_indicator_width_equal_title="true"app:tl_tab_space_equal="false"app:tl_textSelectColor="@color/color_main"app:tl_textUnselectColor="@color/color_33"app:tl_textsize="14sp" /><TextViewandroid:id="@+id/tv_sugar"android:layout_width="wrap_content"android:layout_height="match_parent"android:gravity="center"android:paddingLeft="10dp"android:paddingRight="10dp"android:text="摇糖罐"android:textColor="@color/color_33" /><Viewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_weight="1" /><TextViewandroid:id="@+id/tv_money"android:layout_width="wrap_content"android:layout_height="match_parent"android:drawableLeft="@drawable/talk_icon_bi"android:drawableRight="@drawable/talk_icon_more_1"android:drawablePadding="10dp"android:gravity="center_vertical"android:text="0"android:textColor="@color/color_99"android:textSize="11sp" /></LinearLayout><Viewandroid:layout_width="match_parent"android:layout_height="@dimen/height_line"android:background="@color/color_f8f8f8" /><com.lnkj.tangguan.widget.ScrollViewPagerandroid:id="@+id/svp"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"app:layout_constraintTop_toTopOf="parent" /><Buttonandroid:id="@+id/btn_all_bag"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:layout_marginRight="15dp"android:background="@drawable/bg_r99_colormain"android:minWidth="76dp"android:minHeight="32dp"android:text="全部送出"android:textColor="@color/white"android:textSize="14sp"android:visibility="gone"tools:visibility="visible" /><android.support.constraint.ConstraintLayoutandroid:id="@+id/cl_bottom"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:paddingLeft="15dp"android:paddingRight="15dp"android:paddingBottom="0dp"><Buttonandroid:id="@+id/btn_all_mics"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:layout_marginBottom="10dp"android:background="@drawable/bg_r99_trans_colormain"android:minWidth="60dp"android:minHeight="32dp"android:text="全麦"android:textColor="@color/color_main"android:textSize="15sp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toTopOf="parent" /><LinearLayoutandroid:layout_width="0dp"android:layout_height="0dp"app:layout_constraintBottom_toBottomOf="@+id/btn_all_mics"app:layout_constraintLeft_toRightOf="@+id/btn_all_mics"app:layout_constraintRight_toLeftOf="@+id/ll_num"app:layout_constraintTop_toTopOf="@+id/btn_all_mics"><TextViewandroid:id="@+id/tv_choose"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:background="@drawable/bg_r99_trans_f"android:drawableRight="@drawable/talk_btn_top"android:gravity="center"android:paddingLeft="10dp"android:paddingRight="10dp"android:singleLine="true"android:text="选择打赏对象"android:textColor="@color/color_99"android:textSize="14sp" /></LinearLayout><LinearLayoutandroid:id="@+id/ll_num"android:layout_width="wrap_content"android:layout_height="0dp"android:background="@drawable/bg_r99_trans_colormain"android:gravity="center_vertical"app:layout_constraintBottom_toBottomOf="@+id/btn_all_mics"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="@+id/btn_all_mics"><TextViewandroid:id="@+id/tv_count"android:layout_width="wrap_content"android:layout_height="match_parent"android:drawableRight="@drawable/talk_btn_top"android:drawablePadding="5dp"android:gravity="center"android:paddingLeft="10dp"android:paddingRight="5dp"android:text="1"android:textColor="@color/color_33"android:textSize="14sp" /><Buttonandroid:id="@+id/btn_pay"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/bg_r99_colormain"android:minWidth="60dp"android:minHeight="32dp"android:text="打赏"android:textColor="@color/white"android:textSize="14sp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toTopOf="parent" /></LinearLayout></android.support.constraint.ConstraintLayout></LinearLayout>


drawable bg_r8_14123a.xml的代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><solid android:color="@color/white" /><cornersandroid:topLeftRadius="8dp"android:topRightRadius="8dp" />
</shape>


drawable bg_r99_colormain.xml的代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><solid android:color="@color/color_main" /><corners android:radius="99dp" />
</shape>


drawable bg_r99_trans_colormain.xml的代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><solid android:color="@color/white" /><stroke android:color="@color/color_main"android:width="@dimen/height_line"></stroke><corners android:radius="99dp" />
</shape>


GiftFragment.kt的代码:

class GiftFragment : BaseFragment<GiftContract.Present>(), GiftContract.View {companion object {fun newInstance(args: Bundle?): GiftFragment {val fragment = GiftFragment()fragment.arguments = argsreturn fragment}}override val mPresenter: GiftContract.Presentget() = GiftPresent().also { it.attachView(this) }override val layoutRes: Intget() = R.layout.fragment_giftinternal var map: MutableMap<Int, List<GiftBean>> = HashMap()internal var adapters: MutableList<GiftAdapter> = ArrayList()internal var views: MutableList<View> = ArrayList()var allBeen = mutableListOf<GiftBean>()override fun initAll() {mPresenter?.giftWall()}override fun setListener() {}override fun processLogic() {}override fun getContext(): Context {return mContext}override fun onEmpty() {}override fun onError() {}override fun giftWall(mutableList: MutableList<GiftBean>?) {if (mutableList == null) {return}allBeen = mutableListtry {var k = 0var i = 0while (i < mutableList.size) {var been = mutableListOf<GiftBean>()//8是每页想设置的礼物数量if (i + 8 > mutableList.size) {been = mutableList.subList(i, mutableList.size)} else {been = mutableList.subList(i, i + 8)}map.put(k, been)k++views.add(initGridView(been))i = i + 8}val giftPagerAdapter = GiftPagerAdapter(views)vp.setAdapter(giftPagerAdapter)ci.setViewPager(vp)} catch (e: Exception) {e.printStackTrace()}}private fun initGridView(been: List<GiftBean>): View {val rootView = layoutInflater.inflate(R.layout.layout_gift_grid, null)val rv = rootView.findViewById(R.id.gv) as RecyclerViewval giftAdapter = GiftAdapter(been as MutableList<GiftBean>)rv.layoutManager = GridLayoutManager(mContext, 4)giftAdapter?.bindToRecyclerView(rv)giftAdapter?.setOnItemClickListener { adapter, view, position ->var item = adapter.getItem(position) as GiftBeanallBeen.forEach {it.isChecked = it.id == item.id}refresh()}adapters?.add(giftAdapter)return rootView}fun refresh() {var item = allBeen.filter { it.isChecked }.get(0)adapters.forEach { adapter ->adapter.data.forEach {it.isChecked = item.id == it.id}adapter.notifyDataSetChanged()}}
}


fragment_gift的代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/white"tools:context=".ui.fragment0.roomdetail.gift.gift.GiftFragment"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><android.support.v4.view.ViewPagerandroid:id="@+id/vp"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1" /><me.relex.circleindicator.CircleIndicatorandroid:id="@+id/ci"android:layout_width="match_parent"android:layout_height="20dp"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"app:ci_animator="@anim/indicator_no_animator"app:ci_drawable="@drawable/white_radius_square_un"app:ci_drawable_unselected="@drawable/white_radius_square"app:ci_height="6dp"app:ci_margin="6dp"app:ci_width="6dp" /></LinearLayout></FrameLayout>


注:CircleIndicator的库是 compile ‘me.relex:circleindicator:1.2.2@aar’
————————————————
声明:本文由云豹科技转发,如有侵权请联系作者删除

这篇关于语音社交源码群聊开发,需要实现礼物打赏功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/217075

相关文章

SpringBoot3实现Gzip压缩优化的技术指南

《SpringBoot3实现Gzip压缩优化的技术指南》随着Web应用的用户量和数据量增加,网络带宽和页面加载速度逐渐成为瓶颈,为了减少数据传输量,提高用户体验,我们可以使用Gzip压缩HTTP响应,... 目录1、简述2、配置2.1 添加依赖2.2 配置 Gzip 压缩3、服务端应用4、前端应用4.1 N

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整

Java枚举类实现Key-Value映射的多种实现方式

《Java枚举类实现Key-Value映射的多种实现方式》在Java开发中,枚举(Enum)是一种特殊的类,本文将详细介绍Java枚举类实现key-value映射的多种方式,有需要的小伙伴可以根据需要... 目录前言一、基础实现方式1.1 为枚举添加属性和构造方法二、http://www.cppcns.co

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

MySQL双主搭建+keepalived高可用的实现

《MySQL双主搭建+keepalived高可用的实现》本文主要介绍了MySQL双主搭建+keepalived高可用的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、测试环境准备二、主从搭建1.创建复制用户2.创建复制关系3.开启复制,确认复制是否成功4.同

Java实现文件图片的预览和下载功能

《Java实现文件图片的预览和下载功能》这篇文章主要为大家详细介绍了如何使用Java实现文件图片的预览和下载功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... Java实现文件(图片)的预览和下载 @ApiOperation("访问文件") @GetMapping("

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

使用Sentinel自定义返回和实现区分来源方式

《使用Sentinel自定义返回和实现区分来源方式》:本文主要介绍使用Sentinel自定义返回和实现区分来源方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Sentinel自定义返回和实现区分来源1. 自定义错误返回2. 实现区分来源总结Sentinel自定