From 73414f33494973b1d1b85091266fd4836eb024c0 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 11 May 2024 18:29:46 +0800 Subject: [PATCH] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E8=87=AA=E5=8B=95PK,=E7=9B=B4=E6=8E=A5PK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/live/activity/LiveActivity.java | 2 +- .../live/event/LivePKRightUserInfoEvent.java | 44 ++++++++++++++++++ .../presenter/LiveRyLinkMicPkPresenter.java | 27 ++++++++--- .../yunbao/live/socket/SocketRyClient.java | 45 +++++++++++++++++-- .../live/views/LivePlayRyViewHolder.java | 11 ++++- .../live/views/LivePushRyViewHolder.java | 6 ++- .../yunbao/live/views/LiveRoomViewHolder.java | 6 +++ .../src/main/res/layout/view_live_push_ry.xml | 41 ++++++++--------- 8 files changed, 150 insertions(+), 32 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/event/LivePKRightUserInfoEvent.java diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 73e8c3609..579a75bc6 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -719,7 +719,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL @Override public void onLinkMicPkApply(UserBean u, String stream, int forwhat) { //主播直播间实现此逻辑 - + L.eSw("onLinkMicPkApply----------------------------------------------"); } /** diff --git a/live/src/main/java/com/yunbao/live/event/LivePKRightUserInfoEvent.java b/live/src/main/java/com/yunbao/live/event/LivePKRightUserInfoEvent.java new file mode 100644 index 000000000..152c895e5 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/event/LivePKRightUserInfoEvent.java @@ -0,0 +1,44 @@ +package com.yunbao.live.event; + +/** + * Created by cxf on 2019/3/25. + */ + +public class LivePKRightUserInfoEvent { + String uid; + String uHead; + String uName; + + public LivePKRightUserInfoEvent() { + } + + public LivePKRightUserInfoEvent(String uid, String uHead, String uName) { + this.uid = uid; + this.uHead = uHead; + this.uName = uName; + } + + public String getUid() { + return uid; + } + + public void setUid(String uid) { + this.uid = uid; + } + + public String getuHead() { + return uHead; + } + + public void setuHead(String uHead) { + this.uHead = uHead; + } + + public String getuName() { + return uName; + } + + public void setuName(String uName) { + this.uName = uName; + } +} diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index a91c15a13..eba1534b6 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -66,6 +66,8 @@ import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.bean.LivePKUserListBean; import com.yunbao.live.custom.ProgressTextView; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.event.LiveOpenSuccessEvent; +import com.yunbao.live.event.LivePKRightUserInfoEvent; import com.yunbao.live.interfaces.ILiveLinkMicViewHolder; import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketRyLinkMicPkUtil; @@ -617,6 +619,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } private void isPK(UserBean bean) { + EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); @@ -1330,11 +1333,15 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); livePushRyViewHolder.dr1_preview.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout1.setVisibility(View.GONE); linearGrade1.setVisibility(View.GONE); } + public void setPkUserInfoView(UserBean userBean){ + + } + //多人PK接受申请画 加入副房间 public void dRjoinOtherRoom(UserBean u) { setMyDrPkDetailsView(); @@ -1380,7 +1387,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); livePushRyViewHolder.dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.GONE); linearGrade2.setVisibility(View.GONE); } else if (j == 1) { L.eSw("j == 1:" + j); @@ -1396,7 +1403,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.GONE); linearGrade4.setVisibility(View.GONE); } else if (j == 2) { L.eSw("j == 2:" + j); @@ -1413,7 +1420,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.GONE); linearGrade4.setVisibility(View.GONE); if (detailsView3 != null) { @@ -1428,7 +1435,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); livePushRyViewHolder.dr3_preview.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.VISIBLE); + detailsLinearLayout3.setVisibility(View.GONE); linearGrade3.setVisibility(View.GONE); @@ -2155,6 +2162,10 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } int pkScoreSize = pkScores.size(); if (pkScoreSize == 3) { + detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.VISIBLE); linearGrade2.setVisibility(View.VISIBLE); linearGrade4.setVisibility(View.VISIBLE); @@ -2230,6 +2241,12 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } else { String userID3 = (String) imageGrade3.getTag(); + + detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout3.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.VISIBLE); linearGrade2.setVisibility(View.VISIBLE); linearGrade3.setVisibility(View.VISIBLE); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index bc88a548d..1d92087a8 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -2,6 +2,7 @@ package com.yunbao.live.socket; import static com.blankj.utilcode.util.SnackbarUtils.dismiss; import static com.blankj.utilcode.util.ViewUtils.runOnUiThread; +import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import static com.yunbao.common.Constants.SOCKET_LIVE_MSG_TO_USER; import static com.yunbao.common.Constants.isAnchor; import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK; @@ -89,9 +90,13 @@ import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWManager; +import io.rong.imlib.IRongCallback; import io.rong.imlib.IRongCoreCallback; import io.rong.imlib.IRongCoreEnum; +import io.rong.imlib.RongIMClient; import io.rong.imlib.chatroom.base.RongChatRoomClient; +import io.rong.imlib.model.Conversation; +import io.rong.message.TextMessage; public class SocketRyClient { @@ -1283,7 +1288,8 @@ public class SocketRyClient { u.setId(map.getString("uid")); u.setUserNiceName(map.getString("pkname")); u.setAvatar(map.getString("pkhead")); - mListener.onLinkMicPkApply(u, map.getString("stream"), 1); + u.setRandomPk("11".equals(map.getString("msgtype"))); + mListener.onLinkMicPkApply(u, map.getString("stream"), "11".equals(map.getString("msgtype"))?2:1); break; case 2://收到对方主播PK回调 L.eSw("收到对方主播PK回调"); @@ -1293,6 +1299,8 @@ public class SocketRyClient { if (livePushRyViewHolder != null) { UserBean userBean = new UserBean(); userBean.setId(map.getString("uid")); + userBean.setAvatar(map.getString("pkhead")); + userBean.setUserNiceName(map.getString("pkname")); livePushRyViewHolder.setAnPkRtc(userBean); } break; @@ -1339,7 +1347,38 @@ public class SocketRyClient { } break; case 10://系统发起PK回调 - JSONObject msg1 = new JSONObject(); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 2) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 2) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(map.getString("uid"), conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + + + /*JSONObject msg1 = new JSONObject(); msg1.put("type", "autoLivePK"); msg1.put("uid", CommonAppConfig.getInstance().getUid()); msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); @@ -1377,7 +1416,7 @@ public class SocketRyClient { ToastUtil.show("invite " + map.getString("uid") + " lose :" + rtcErrorCode); } } - }); + });*/ break; } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index c1960b6b5..dc6695a97 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -1,6 +1,7 @@ package com.yunbao.live.views; import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; +import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import android.Manifest; import android.app.Activity; @@ -58,6 +59,7 @@ import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.socket.SocketSendBean; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -93,6 +95,10 @@ import cn.rongcloud.rtc.base.RCRTCStreamType; import cn.rongcloud.rtc.base.RTCErrorCode; import cn.rongcloud.rtc.core.RendererCommon; import io.agora.beautyapi.faceunity.agora.SWAuManager; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.message.TextMessage; public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @@ -1066,6 +1072,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { //将当前主播画面换个画布展示 String pkUid = (String) event.getObject(); setPkView(pkUid); + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_PK_END) { String pkUid = (String) event.getObject(); //endpk(pkUid); @@ -1085,7 +1092,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { joinLiveMic(); return; } - RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() + /*RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO).setLiveRole(RCRTCLiveRole.AUDIENCE).build(); RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback() { @@ -1120,7 +1127,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } - }); + });*/ } diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 6178fa71e..7cc43d910 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -589,6 +589,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } public void setAnPkRtc(UserBean u) { + EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); if (swManager != null && u != null) { //将多人pk画面屏蔽 dr_pk_view.setVisibility(View.GONE); @@ -617,8 +618,9 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX final SocketSendBean msg1 = new SocketSendBean() .param("_method_", Constants.SOCKET_LINK_MIC_PK) .param("action", 4) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) .param("pkuid", u.getId()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("uid", CommonAppConfig.getInstance().getUid()); msg1.create(); @@ -646,6 +648,8 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } }); + + mLiveRyLinkMicPkPresenter.setPkUserInfoView(u); } private int currentPosition = 0; diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 5fdcd3f5d..7e7039dd7 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -181,6 +181,7 @@ import com.yunbao.live.dialog.ReceiveRendPacketPopup; import com.yunbao.live.dialog.ResultRendPacketPopup; import com.yunbao.live.event.LiveAnchorEvent; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.event.LivePKRightUserInfoEvent; import com.yunbao.live.presenter.LiveDanmuPresenter; import com.yunbao.live.presenter.LiveEnterRoomAnimPresenter; import com.yunbao.live.presenter.LiveGiftAnimPresenter; @@ -3037,6 +3038,11 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public boolean pkHandler = true; + @Subscribe(threadMode = ThreadMode.MAIN) + public void setOtherInfo(LivePKRightUserInfoEvent livePKRightUserInfoEvent){ + setOtherInfo(livePKRightUserInfoEvent.getUid(),livePKRightUserInfoEvent.getuHead(),livePKRightUserInfoEvent.getuName()); + } + //左上角显示对方主播头像及昵称 public void setOtherInfo(String touids, String url, String name) { if (!pkHandler) { diff --git a/live/src/main/res/layout/view_live_push_ry.xml b/live/src/main/res/layout/view_live_push_ry.xml index 86fe88ebf..bb814174d 100644 --- a/live/src/main/res/layout/view_live_push_ry.xml +++ b/live/src/main/res/layout/view_live_push_ry.xml @@ -114,12 +114,32 @@ android:layout_height="match_parent" /> + + + + + + - - - - -