()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()}.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?) {}})}}