From f62a0930927cde825aafd4f2357c2d86650b7a09 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 7 Dec 2022 16:10:22 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E8=87=AA=E7=94=B1PK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/activity/LiveRyAnchorActivity.java | 22 ++++++++++----- .../live/adapter/RandomPkRecyclerAdapter.java | 18 ++++++++++++- .../live/dialog/FreePkDialogFragment.java | 27 ++++++++++--------- .../layout/dialog_live_free_pk_function.xml | 2 +- .../src/main/res/layout/item_random_pk_rv.xml | 1 + live/src/main/res/values/strings.xml | 1 + 6 files changed, 49 insertions(+), 22 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 478e5b8ec..52b9de898 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -68,6 +68,7 @@ import com.yunbao.live.bean.LiveKsyConfigBean; import com.yunbao.live.bean.LiveReceiveGiftBean; import com.yunbao.common.bean.LiveUserGiftBean; import com.yunbao.common.bean.MicUserBean; +import com.yunbao.live.dialog.FreePkDialogFragment; import com.yunbao.live.dialog.LiveLinkMicListDialogFragment; import com.yunbao.live.dialog.LiveNewFunctionDialogFragment; import com.yunbao.live.dialog.LiveNewWishListDialogFragment; @@ -161,11 +162,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl @Override public void onStartPK(String pkUid) { ToastUtil.show("发起随机PK:" + pkUid); - JSONObject msg1 = new JSONObject(); - msg1.put("uid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); + JSONObject msg1 = buildLinkMicJSON(); msg1.put("randomPk", true); linkMicAnchorApply(pkUid, pkUid, msg1.toString()); } @@ -402,7 +399,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl break; case Constants.LIVE_FUNC_LINK_MIC://连麦 if (isDRPK != 1) { - openLinkMicAnchorWindow(false); + //openLinkMicAnchorWindow(false); + openFreePkWindow(); } else { ToastUtil.show("您已在PK中"); } @@ -603,6 +601,12 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl fragment.setArguments(bundle); fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment"); } + public void openFreePkWindow(){ + FreePkDialogFragment fragment = new FreePkDialogFragment(); + Bundle bundle = new Bundle(); + fragment.setArguments(bundle); + fragment.show(getSupportFragmentManager(), "FreePkDialogFragment"); + } /** * 随机PK @@ -1065,12 +1069,16 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl * @param stream 对方主播的stream */ public void linkMicAnchorApply(String pkUid, String stream) { + JSONObject msg1 = buildLinkMicJSON(); + linkMicAnchorApply(pkUid, stream, msg1.toString()); + } + public JSONObject buildLinkMicJSON(){ JSONObject msg1 = new JSONObject(); msg1.put("uid", CommonAppConfig.getInstance().getUid()); msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); - linkMicAnchorApply(pkUid, stream, msg1.toString()); + return msg1; } public void linkMicAnchorApply(final String pkUid, String stream, String extra) { diff --git a/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java index f2e7467d7..1cca06847 100644 --- a/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java @@ -14,7 +14,13 @@ import com.makeramen.roundedimageview.RoundedImageView; import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.bean.RandomPkUserBean; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.manager.IMRTCManager; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; +import com.yunbao.live.activity.LiveRyAnchorActivity; + +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.base.RTCErrorCode; public class RandomPkRecyclerAdapter extends RefreshAdapter { private static final int HEAD = 0; @@ -85,6 +91,16 @@ public class RandomPkRecyclerAdapter extends RefreshAdapter { mAvatar = itemView.findViewById(R.id.item_avatar); mPkStatus = itemView.findViewById(R.id.item_pk); mFollow = itemView.findViewById(R.id.item_follow); + mPkStatus.setOnClickListener(v -> { + RandomPkUserBean bean = (RandomPkUserBean) itemView.getTag(); + if (bean.isPk()) { + ToastUtil.show(R.string.free_pk_user_pking); + return; + } + ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), + ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() + ); + }); } @Override @@ -94,7 +110,7 @@ public class RandomPkRecyclerAdapter extends RefreshAdapter { if (bean == null) { return; } - System.out.println("bean = " + bean); + itemView.setTag(bean); mNum.setText((position) + ""); if (position % 2 == 0) { itemView.setBackgroundResource(R.drawable.bg_item_random_pk_type_1); diff --git a/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java index d87a6b158..bb82dda15 100644 --- a/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java @@ -30,6 +30,7 @@ import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.common.utils.WordsTypeUtil; @@ -48,18 +49,20 @@ import java.util.TimerTask; * 自由PK */ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnClickListener { + private static final int TAB_STATUS_SEARCH = 1; + private static final int TAB_STATUS_FOLLOW = 2; + private static final String TAG = "自由PK"; private int mLiveUid; private TabLayout tabLayout; private View reset; private CommonRefreshView mRecyclerView; - private View mPkInfoLayout; private View mSearchLayout; private EditText mSearch; private ImageView mClear; private RandomPkRecyclerAdapter adapter; private DataHelper helper; - + private int tabStatus; @Override @@ -82,7 +85,7 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl WindowManager.LayoutParams params = window.getAttributes(); window.setWindowAnimations(R.style.bottomToTopAnim); params.width = WindowManager.LayoutParams.MATCH_PARENT; - params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.height = DpUtil.dp2px(330); params.gravity = Gravity.BOTTOM; window.setAttributes(params); } @@ -108,7 +111,6 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl tabLayout = (TabLayout) findViewById(R.id.menu_tab); reset = findViewById(R.id.menu_reset); mRecyclerView = (CommonRefreshView) findViewById(R.id.random_container_view); - mPkInfoLayout = findViewById(R.id.layout_random_pk_info); mSearchLayout = findViewById(R.id.random_pk_search_layout); mSearch = (EditText) findViewById(R.id.search_edit); mClear = (ImageView) findViewById(R.id.search_clear); @@ -148,26 +150,27 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl private void initTab() { TabLayout.Tab searchTag = tabLayout.newTab(); TabLayout.Tab listTag = tabLayout.newTab(); - searchTag.setTag(1); + searchTag.setTag(TAB_STATUS_SEARCH); searchTag.setText("主播搜索"); - listTag.setTag(2); + listTag.setTag(TAB_STATUS_FOLLOW); listTag.setText("關注列表"); tabLayout.addTab(searchTag); tabLayout.addTab(listTag); + tabStatus = TAB_STATUS_SEARCH; tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { if (tab.getTag() != null) { - mPkInfoLayout.setVisibility(View.GONE); + tabStatus = (int) tab.getTag(); mRecyclerView.setVisibility(View.GONE); - mSearchLayout.setVisibility(View.INVISIBLE); - switch ((int) tab.getTag()) { - case 1: + mSearchLayout.setVisibility(View.GONE); + switch (tabStatus) { + case TAB_STATUS_SEARCH: mSearchLayout.setVisibility(View.VISIBLE); mRecyclerView.setVisibility(View.VISIBLE); mRecyclerView.initData(); break; - case 2: + case TAB_STATUS_FOLLOW: mRecyclerView.setVisibility(View.VISIBLE); mRecyclerView.initData(); break; @@ -188,8 +191,6 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl } - - @Override public void onClick(View v) { int id = v.getId(); diff --git a/live/src/main/res/layout/dialog_live_free_pk_function.xml b/live/src/main/res/layout/dialog_live_free_pk_function.xml index 5c2d57dae..1c5b0422b 100644 --- a/live/src/main/res/layout/dialog_live_free_pk_function.xml +++ b/live/src/main/res/layout/dialog_live_free_pk_function.xml @@ -99,7 +99,7 @@ diff --git a/live/src/main/res/layout/item_random_pk_rv.xml b/live/src/main/res/layout/item_random_pk_rv.xml index 54bd44ee6..b43334e37 100644 --- a/live/src/main/res/layout/item_random_pk_rv.xml +++ b/live/src/main/res/layout/item_random_pk_rv.xml @@ -37,6 +37,7 @@ app:riv_oval="true" /> 正在退出匹配 %s 退出過程中也有可能匹配到對手 請輸入您要pk的主播昵稱或id + 對方正在PK中