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

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

相关文章

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

关于数据埋点,你需要了解这些基本知识

产品汪每天都在和数据打交道,你知道数据来自哪里吗? 移动app端内的用户行为数据大多来自埋点,了解一些埋点知识,能和数据分析师、技术侃大山,参与到前期的数据采集,更重要是让最终的埋点数据能为我所用,否则可怜巴巴等上几个月是常有的事。   埋点类型 根据埋点方式,可以区分为: 手动埋点半自动埋点全自动埋点 秉承“任何事物都有两面性”的道理:自动程度高的,能解决通用统计,便于统一化管理,但个性化定

Hadoop企业开发案例调优场景

需求 (1)需求:从1G数据中,统计每个单词出现次数。服务器3台,每台配置4G内存,4核CPU,4线程。 (2)需求分析: 1G / 128m = 8个MapTask;1个ReduceTask;1个mrAppMaster 平均每个节点运行10个 / 3台 ≈ 3个任务(4    3    3) HDFS参数调优 (1)修改:hadoop-env.sh export HDFS_NAMENOD

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

嵌入式QT开发:构建高效智能的嵌入式系统

摘要: 本文深入探讨了嵌入式 QT 相关的各个方面。从 QT 框架的基础架构和核心概念出发,详细阐述了其在嵌入式环境中的优势与特点。文中分析了嵌入式 QT 的开发环境搭建过程,包括交叉编译工具链的配置等关键步骤。进一步探讨了嵌入式 QT 的界面设计与开发,涵盖了从基本控件的使用到复杂界面布局的构建。同时也深入研究了信号与槽机制在嵌入式系统中的应用,以及嵌入式 QT 与硬件设备的交互,包括输入输出设

OpenHarmony鸿蒙开发( Beta5.0)无感配网详解

1、简介 无感配网是指在设备联网过程中无需输入热点相关账号信息,即可快速实现设备配网,是一种兼顾高效性、可靠性和安全性的配网方式。 2、配网原理 2.1 通信原理 手机和智能设备之间的信息传递,利用特有的NAN协议实现。利用手机和智能设备之间的WiFi 感知订阅、发布能力,实现了数字管家应用和设备之间的发现。在完成设备间的认证和响应后,即可发送相关配网数据。同时还支持与常规Sof

C++11第三弹:lambda表达式 | 新的类功能 | 模板的可变参数

🌈个人主页: 南桥几晴秋 🌈C++专栏: 南桥谈C++ 🌈C语言专栏: C语言学习系列 🌈Linux学习专栏: 南桥谈Linux 🌈数据结构学习专栏: 数据结构杂谈 🌈数据库学习专栏: 南桥谈MySQL 🌈Qt学习专栏: 南桥谈Qt 🌈菜鸡代码练习: 练习随想记录 🌈git学习: 南桥谈Git 🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈�

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

阿里开源语音识别SenseVoiceWindows环境部署

SenseVoice介绍 SenseVoice 专注于高精度多语言语音识别、情感辨识和音频事件检测多语言识别: 采用超过 40 万小时数据训练,支持超过 50 种语言,识别效果上优于 Whisper 模型。富文本识别:具备优秀的情感识别,能够在测试数据上达到和超过目前最佳情感识别模型的效果。支持声音事件检测能力,支持音乐、掌声、笑声、哭声、咳嗽、喷嚏等多种常见人机交互事件进行检测。高效推

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象