From 49167f332d8602d9ab90e73c29d759960bb836cf Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 12 Dec 2022 16:30:32 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E9=9A=A8=E6=A9=9F/=E8=87=AA=E7=94=B1P?= =?UTF-8?q?K?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/manager/RandomPkManager.java | 14 +++++++++ .../live/adapter/FreePkRecyclerAdapter.java | 2 +- .../presenter/LiveRyLinkMicPkPresenter.java | 24 ++++++++------ .../yunbao/live/socket/SocketRyClient.java | 3 ++ .../live/views/LivePushRyViewHolder.java | 31 ++++++++++++------- .../yunbao/main/activity/MainActivity.java | 6 ++-- 6 files changed, 54 insertions(+), 26 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java index 1fe11f400..c7aa5aea1 100644 --- a/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java +++ b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java @@ -50,6 +50,10 @@ public class RandomPkManager { return manager; } + public int getStatus() { + return status; + } + /** * 添加监听器 */ @@ -152,6 +156,13 @@ public class RandomPkManager { return rankPkInfoBean != null && rankPkInfoBean.isRankPKTime(); } + /** + * 是否为随机PK模式 + */ + public boolean isRandomModel() { + return status == PK_STATUS_START || status == PK_STATUS_REQUEST || status == PK_STATUS_EXIT_ING; + } + /** * 开始匹配 */ @@ -327,6 +338,9 @@ public class RandomPkManager { * 设置PK状态 */ public void setPkStatus(int status) { + if (!isRandomModel()) { + return; + } if (this.status == PK_STATUS_DEFAULT || this.status == PK_STATUS_EXIT_ING) {//默认状态下不响应随机PK接口 return; } diff --git a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java index e520f6c9c..bf2f9d378 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java @@ -134,7 +134,7 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { @Override public void onSuccess(SetAttentsModel data) { bean.setAttention(data.getIsattent()); - if ("1" .equals(data.getIsattent())) { + if ("1".equals(data.getIsattent())) { ToastUtil.show(R.string.following); mOnItemClickListener.onItemClick(bean, 1); } else { 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 7064b83ff..054cb050d 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -1,6 +1,7 @@ package com.yunbao.live.presenter; import android.app.Dialog; + import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; @@ -602,7 +603,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } } else { - isPK(); + isPK(u); } } @@ -755,7 +756,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } - private void isPK() { + private void isPK(UserBean bean) { ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); @@ -771,8 +772,12 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - - IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { + if (bean != null && bean.isRandomPk()) { + msg1.put("random_pk", bean.isRandomPk() ? 1 : 0); + msg1.put("is_ladders", bean.getRankPkImgUrl()); + } + System.out.println("PK回执 = " + msg1.toString()); + IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { @Override public void onSuccess() { RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback() { @@ -968,7 +973,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - isPK(); + isPK(u); } else { if (mPkWaitCount < 0) { rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { @@ -1012,8 +1017,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } }); - } else { - refusePk(u); } mApplyUid = null; mApplyStream = null; @@ -1184,6 +1187,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { dialog.dismiss(); + task.cancel(); apply(); } @@ -1218,7 +1222,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { void apply() { - isPK(); + isPK(u); } }) .build().show(); @@ -1236,7 +1240,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void onSuccess() { final SocketSendBean msg1 = new SocketSendBean() .param("_method_", SOCKET_LINK_MIC_PK) - // .param("randomPk",u.isRandomPk()+"") + // .param("randomPk",u.isRandomPk()+"") .param("action", 3); msg1.create(); @@ -1988,7 +1992,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } if (mLiveLinkMicPkViewHolder != null) { if (!TextUtils.isEmpty(winUid)) { - if ("0" .equals(winUid)) { + if ("0".equals(winUid)) { mLiveLinkMicPkViewHolder.end(0); mLiveLinkMicPkViewHolder.hideTime(); if (mHandler != null) { 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 6dd4df3ca..9d3c9ef83 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -1079,6 +1079,9 @@ public class SocketRyClient { }); } mListener.onLinkMicPkClose(1); + if (RandomPkManager.getInstance().isRandomModel()) { + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_DEFAULT); + } break; case 7://对方主播正在忙的回调 mListener.onLinkMicPkBusy(); 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 b609194ab..f0b5e36a1 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -37,6 +37,7 @@ import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMRTCManager; +import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; @@ -310,20 +311,25 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX userBean1.setUserNiceName("null"); userBean1.setAvatar("null"); } + //单人PK,减掉次数 + if (!RandomPkManager.getInstance().isRandomModel()) { + ToastUtil.show("单人PK,扣次数 = " + RandomPkManager.getInstance().getStatus()); + LiveNetManager.get(mContext).setFreePkNum(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + + } + + @Override + public void onError(String error) { + + } + }); + } else { + ToastUtil.show("随机PK,不扣次数"); + } mLiveRyLinkMicPkPresenter.onLinkMicToPk(userBean1); mLiveRyLinkMicPkPresenter.onLinkMicPkStart(inviteeRoomId, 3); - //单人PK,减掉次数 - LiveNetManager.get(mContext).setFreePkNum(new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { - - } - - @Override - public void onError(String error) { - - } - }); } } }); @@ -379,6 +385,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onConfirmClick(Dialog dialog, String content) { //断开连麦 + HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout") .execute(new HttpCallback() { @Override diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 37e1c32ee..efd5f0da4 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -642,9 +642,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene //关注 FollowActivity.forward(mContext, CommonAppConfig.getInstance().getUid(), 0); } else if (i == R.id.img_trophy) { - // MainListActivity.forward(mContext, 0); - RandomPkDialogFragment fragment = new RandomPkDialogFragment(); - fragment.show(this.getSupportFragmentManager(), "RandomPkDialogFragment"); + MainListActivity.forward(mContext, 0); + //RandomPkDialogFragment fragment = new RandomPkDialogFragment(); + //fragment.show(this.getSupportFragmentManager(), "RandomPkDialogFragment"); }