From e97a4e607c54e8c56ed857e3f90c197970af06ff Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Tue, 14 Feb 2023 15:04:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=9A=E4=BA=BAPK=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E7=82=B9=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/activity/LiveAudienceActivity.java | 40 +++-- .../live/views/LivePlayRyViewHolder.java | 161 ++++------------- .../yunbao/live/views/LiveRoomViewHolder.java | 164 +++++++++++++++++- .../live/views/PortraitLiveManager.java | 21 ++- .../main/res/layout/view_live_pk_details.xml | 4 + 5 files changed, 238 insertions(+), 152 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 629ddb15f..5ff617e85 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -691,24 +691,24 @@ public class LiveAudienceActivity extends LiveActivity { @Subscribe(threadMode = ThreadMode.MAIN) public void onLiveRoomChangeEvent(LiveRoomChangeEvent e) { - LiveBean liveBean = e.getLiveBean(); - if (e.isLiveEnd()) { - manager.removeLiveEnd(); - } - if (liveBean != null) { - LiveHttpUtil.cancel(LiveHttpConsts.CHECK_LIVE); - LiveHttpUtil.cancel(LiveHttpConsts.ENTER_ROOM); - LiveHttpUtil.cancel(LiveHttpConsts.ROOM_CHARGE); - manager.onRemove(false); - mLiveType = e.getLiveType(); - mLiveTypeVal = e.getLiveTypeVal(); - mLiveBean = liveBean; - mLiveUid = liveBean.getUid(); - mStream = liveBean.getStream(); - mAncherName = liveBean.getUserNiceName(); - mAncherIcon = liveBean.getAvatar(); - manager.onAdd(liveBean, mLiveType, mLiveTypeVal, mLiveSDK); - } + LiveBean liveBean = e.getLiveBean(); + if (e.isLiveEnd()) { + manager.removeLiveEnd(); + } + if (liveBean != null) { + LiveHttpUtil.cancel(LiveHttpConsts.CHECK_LIVE); + LiveHttpUtil.cancel(LiveHttpConsts.ENTER_ROOM); + LiveHttpUtil.cancel(LiveHttpConsts.ROOM_CHARGE); + manager.onRemove(false); + mLiveType = e.getLiveType(); + mLiveTypeVal = e.getLiveTypeVal(); + mLiveBean = liveBean; + mLiveUid = liveBean.getUid(); + mStream = liveBean.getStream(); + mAncherName = liveBean.getUserNiceName(); + mAncherIcon = liveBean.getAvatar(); + manager.onAdd(liveBean, mLiveType, mLiveTypeVal, mLiveSDK); + } } @@ -1251,6 +1251,10 @@ public class LiveAudienceActivity extends LiveActivity { case SOCKET_LIVE_DRPK_SET_PK_END_VIEW: if (manager.getmLivePlayViewHolder() != null) { manager.getmLivePlayViewHolder().setPkEndview(); + + } + if (manager != null) { + manager.removeDetailView(); } 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 e4dedb4c0..aef91f2bc 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -1,13 +1,13 @@ package com.yunbao.live.views; import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; -import static cn.rongcloud.rtc.core.RendererCommon.ScalingType.SCALE_ASPECT_FILL; import android.Manifest; import android.app.Dialog; import android.content.Context; import android.graphics.Color; import android.media.AudioManager; +import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.SystemClock; @@ -35,6 +35,7 @@ import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; import com.lzy.okserver.OkDownload; +import com.yunbao.common.Constants; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.HttpCallback; @@ -53,6 +54,7 @@ import com.yunbao.common.views.LiveClarityCustomPopup; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.dialog.LiveUserDialogFragment; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.utils.LiveExoPlayerManager; @@ -89,7 +91,6 @@ import cn.rongcloud.rtc.base.RCRTCRemoteVideoFrame; import cn.rongcloud.rtc.base.RCRTCRoomType; import cn.rongcloud.rtc.base.RCRTCStreamType; import cn.rongcloud.rtc.base.RTCErrorCode; -import cn.rongcloud.rtc.center.stream.RCRTCAudioInputStreamImpl; import cn.rongcloud.rtc.core.RendererCommon; public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @@ -393,7 +394,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.requestLayout(); RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; + params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); params1.addRule(RelativeLayout.ALIGN_TOP); ry_view.setLayoutParams(params1); @@ -556,17 +557,17 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params.addRule(RelativeLayout.ALIGN_TOP); mVideoView.requestLayout(); } - if (detailsView != null) { - mVideoView.removeView(detailsView); - detailsView = null; - } +// if (detailsView != null) { +// mVideoView.removeView(detailsView); +// detailsView = null; +// } } - public void removeDetailView(){ - if (detailsView != null) { - mVideoView.removeView(detailsView); - detailsView = null; - } + public void removeDetailView() { +// if (detailsView != null) { +// mVideoView.removeView(detailsView); +// detailsView = null; +// } } @Override @@ -1221,129 +1222,33 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } } - private int mPkTimeCount = 0; - private Handler countdownHandler = new Handler(); - private View detailsView = null; - private FrameLayout timeTitle; - private TextView textTime; - private TextView textPkName1, textPkName2, textPkName3, textPkName4; - private TextView textGrade1, textGrade2, textGrade3, textGrade4; - private ImageView imageGrade1, imageGrade2, imageGrade3, imageGrade4; - private LinearLayout linearGrade1, linearGrade2, linearGrade3, linearGrade4; - /** - * PK倒计时 - */ - public void upDataPkScore(JSONArray pkScores, int time) { + private int mPkTimeCount = 0; - if (detailsView == null) { - detailsView = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - timeTitle = detailsView.findViewById(R.id.time_title); - textTime = detailsView.findViewById(R.id.text_time); - linearGrade1 = detailsView.findViewById(R.id.lin_pk1); - linearGrade2 = detailsView.findViewById(R.id.lin_pk2); - linearGrade3 = detailsView.findViewById(R.id.lin_pk3); - linearGrade4 = detailsView.findViewById(R.id.lin_pk4); - textPkName1 = detailsView.findViewById(R.id.text_pk_name1); - textPkName2 = detailsView.findViewById(R.id.text_pk_name2); - textPkName3 = detailsView.findViewById(R.id.text_pk_name3); - textPkName4 = detailsView.findViewById(R.id.text_pk_name4); - textGrade1 = detailsView.findViewById(R.id.text_grade1); - textGrade2 = detailsView.findViewById(R.id.text_grade2); - textGrade3 = detailsView.findViewById(R.id.text_grade3); - textGrade4 = detailsView.findViewById(R.id.text_grade4); - imageGrade1 = detailsView.findViewById(R.id.image_grade1); - imageGrade2 = detailsView.findViewById(R.id.image_grade2); - imageGrade3 = detailsView.findViewById(R.id.image_grade3); - imageGrade4 = detailsView.findViewById(R.id.image_grade4); - linearGrade1.setVisibility(View.GONE); - linearGrade2.setVisibility(View.GONE); - linearGrade3.setVisibility(View.GONE); - linearGrade4.setVisibility(View.GONE); - mVideoView.addView(detailsView); - } + public interface PlayViewLayoutInterface { + void playViewLayout(int width, int height); + } - for (int i = 0; i < pkScores.size(); i++) { - JSONObject score = pkScores.getJSONObject(i); - String userNiceName = score.getString("user_nicename"); - long userScore = score.getLong("score"); - int resScore = R.mipmap.icon_livepk_no1; - if (userScore == 0 && !score.containsKey("paiming")) { - resScore = R.mipmap.icon_livepk_no1; - } else { - if (score.containsKey("paiming")) { - int ranking = score.getIntValue("paiming"); - switch (ranking) { - case 1: - resScore = R.mipmap.icon_livepk_no1; - break; - case 2: - resScore = R.mipmap.icon_livepk_no2; - break; - case 3: - resScore = R.mipmap.icon_livepk_no3; - break; - case 4: - resScore = R.mipmap.icon_livepk_no4; - break; - } + private PlayViewLayoutInterface layoutInterface; + + public void setLayoutInterface(PlayViewLayoutInterface layoutInterface) { + mVideoView.post(new Runnable() { + @Override + public void run() { + int width = mVideoView.getMeasuredWidth(); + int height = mVideoView.getMeasuredHeight(); + if (layoutInterface != null) { + layoutInterface.playViewLayout(width, height); } } - if (i == 0) { - linearGrade1.setVisibility(View.VISIBLE); - textPkName1.setText(userNiceName); - ImgLoader.display(mContext, resScore, imageGrade1); - textGrade1.setText(String.valueOf(userScore)); - } else if (i == 1) { - linearGrade2.setVisibility(View.VISIBLE); - textPkName2.setText(userNiceName); - ImgLoader.display(mContext, resScore, imageGrade2); - textGrade2.setText(String.valueOf(userScore)); - } else if (i == 2) { - linearGrade4.setVisibility(View.VISIBLE); - textPkName4.setText(userNiceName); - ImgLoader.display(mContext, resScore, imageGrade4); - textGrade4.setText(String.valueOf(userScore)); - } else if (i == 3) { - linearGrade3.setVisibility(View.VISIBLE); - textPkName3.setText(userNiceName); - ImgLoader.display(mContext, resScore, imageGrade3); - textGrade3.setText(String.valueOf(userScore)); - - } - } - - if (time > 0) { - mPkTimeCount = time; - timeTitle.setVisibility(View.VISIBLE); - countdownHandler.postAtTime(countdownRunnable, getNextSecondTime()); - } - + }); } - private Runnable countdownRunnable = new Runnable() { - @Override - public void run() { - mPkTimeCount--; - if (mPkTimeCount > 0) {// - String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); - textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); - countdownHandler.postAtTime(countdownRunnable, getNextSecondTime()); - } else { - timeTitle.setVisibility(View.GONE); - countdownHandler.removeCallbacks(countdownRunnable); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); - } - } - }; - /** - * 获取下一秒钟的时间 - */ - private long getNextSecondTime() { - long now = SystemClock.uptimeMillis(); - return now + (1000 - now % 1000); - } + + + + + } 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 d144f8573..8c00cec5b 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -36,7 +36,6 @@ import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import androidx.recyclerview.widget.SimpleItemAnimator; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; @@ -116,7 +115,6 @@ import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.ZhuangBanActivity; import com.yunbao.live.adapter.LiveChatAdapter; -import com.yunbao.live.adapter.LiveChatRecyclerViewLayoutManager; import com.yunbao.live.adapter.LiveRoomFastMessageRecyclerViewAdapter; import com.yunbao.live.adapter.LiveUserAdapter; import com.yunbao.live.bean.DrPkbean; @@ -3904,10 +3902,11 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mLiveChatAdapter.insertItem(bean); } } + /** * 幸运100%活动 */ - public void lucky100(MsgModel model){ + public void lucky100(MsgModel model) { if (mLiveChatAdapter != null) { LiveChatBean bean = new LiveChatBean(); bean.setType(LiveChatBean.LUCKY_100_CHECK); @@ -4009,4 +4008,163 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } }; + private Handler countdownHandler = new Handler(); + private View detailsView = null; + private FrameLayout timeTitle; + private TextView textTime; + private TextView textPkName1, textPkName2, textPkName3, textPkName4; + private TextView textGrade1, textGrade2, textGrade3, textGrade4; + private ImageView imageGrade1, imageGrade2, imageGrade3, imageGrade4; + private LinearLayout linearGrade1, linearGrade2, linearGrade3, linearGrade4; + /** + * PK倒计时 + */ + private String userId2, userId3 = "", userId4; + + public void upDataPkScore(JSONArray pkScores, int time) { + if (detailsView == null) { + detailsView = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + timeTitle = detailsView.findViewById(R.id.time_title); + textTime = detailsView.findViewById(R.id.text_time); + linearGrade1 = detailsView.findViewById(R.id.lin_pk1); + linearGrade2 = detailsView.findViewById(R.id.lin_pk2); + linearGrade3 = detailsView.findViewById(R.id.lin_pk3); + linearGrade4 = detailsView.findViewById(R.id.lin_pk4); + textPkName1 = detailsView.findViewById(R.id.text_pk_name1); + textPkName2 = detailsView.findViewById(R.id.text_pk_name2); + textPkName3 = detailsView.findViewById(R.id.text_pk_name3); + textPkName4 = detailsView.findViewById(R.id.text_pk_name4); + textGrade1 = detailsView.findViewById(R.id.text_grade1); + textGrade2 = detailsView.findViewById(R.id.text_grade2); + textGrade3 = detailsView.findViewById(R.id.text_grade3); + textGrade4 = detailsView.findViewById(R.id.text_grade4); + imageGrade1 = detailsView.findViewById(R.id.image_grade1); + imageGrade2 = detailsView.findViewById(R.id.image_grade2); + imageGrade3 = detailsView.findViewById(R.id.image_grade3); + imageGrade4 = detailsView.findViewById(R.id.image_grade4); + linearGrade1.setVisibility(View.GONE); + linearGrade2.setVisibility(View.GONE); + linearGrade3.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + mRoot.addView(detailsView); + mRoot.post(new Runnable() { + @Override + public void run() { + int mScreenWdith = ScreenDimenUtil.getInstance().getScreenWdith(); + int vHeight = mScreenWdith * 720 / 960; + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) detailsView.getLayoutParams(); + params.height = vHeight; + params.width = mScreenWdith; + params.topMargin = DpUtil.dp2px(105); + params.addRule(RelativeLayout.ALIGN_TOP); + detailsView.setLayoutParams(params); + } + }); + + + + } + + for (int i = 0; i < pkScores.size(); i++) { + JSONObject score = pkScores.getJSONObject(i); + String userNiceName = score.getString("user_nicename"); + long userScore = score.getLong("score"); + String userId = score.getString("id"); + int resScore = R.mipmap.icon_livepk_no1; + if (userScore == 0 && !score.containsKey("paiming")) { + resScore = R.mipmap.icon_livepk_no1; + } else { + if (score.containsKey("paiming")) { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + resScore = R.mipmap.icon_livepk_no1; + break; + case 2: + resScore = R.mipmap.icon_livepk_no2; + break; + case 3: + resScore = R.mipmap.icon_livepk_no3; + break; + case 4: + resScore = R.mipmap.icon_livepk_no4; + break; + } + } + } + if (i == 0) { + linearGrade1.setVisibility(View.VISIBLE); + textPkName1.setText(userNiceName); + ImgLoader.display(mContext, resScore, imageGrade1); + textGrade1.setText(String.valueOf(userScore)); + + } else if (i == 1) { + linearGrade2.setVisibility(View.VISIBLE); + textPkName2.setText(userNiceName); + ImgLoader.display(mContext, resScore, imageGrade2); + textGrade2.setText(String.valueOf(userScore)); + userId2 = userId; + } else if (i == 2) { + linearGrade4.setVisibility(View.VISIBLE); + textPkName4.setText(userNiceName); + ImgLoader.display(mContext, resScore, imageGrade4); + textGrade4.setText(String.valueOf(userScore)); + userId4 = userId; + } else if (i == 3) { + linearGrade3.setVisibility(View.VISIBLE); + textPkName3.setText(userNiceName); + ImgLoader.display(mContext, resScore, imageGrade3); + textGrade3.setText(String.valueOf(userScore)); + userId3 = userId; + } + } + + if (time > 0) { + mPkTimeCount = time; + timeTitle.setVisibility(View.VISIBLE); + countdownHandler.postAtTime(countdownRunnable, getNextSecondTime()); + } + textPkName2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showUserDialog(userId2); + } + }); + textPkName4.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showUserDialog(userId4); + } + }); + textPkName3.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showUserDialog(userId3); + } + }); + } + + private Runnable countdownRunnable = new Runnable() { + @Override + public void run() { + mPkTimeCount--; + if (mPkTimeCount > 0) {// + String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); + textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); + countdownHandler.postAtTime(countdownRunnable, getNextSecondTime()); + } else { + timeTitle.setVisibility(View.GONE); + countdownHandler.removeCallbacks(countdownRunnable); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); + } + } + }; + public void removeDetailView() { + if (detailsView != null) { + mRoot.removeView(detailsView); + detailsView = null; + } + } + } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 6f1dbd1c9..4402f42f3 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -256,7 +256,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk) { isEnterRoom = false; openParametersModel = new OpenParametersModel(); - if(mLiveRoomViewHolder!=null){ + if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.UpPkTwo(); } mContext.runOnUiThread(new Runnable() { @@ -581,6 +581,15 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe upDataPkScore(pkInfo.getJSONArray("userlist"), pkInfo.getIntValue("drpk_time")); } +// mLivePlayViewHolder.setLayoutInterface(new LivePlayRyViewHolder.PlayViewLayoutInterface() { +// @Override +// public void playViewLayout(int width, int height) { +// Log.e("播放器的宽高", "宽:" + width + " 高:" + height); +// ScreenDimenUtil util = ScreenDimenUtil.getInstance(); +// int mScreenWdith = util.getScreenWdith(); +// Log.e("播放器的宽高", "mScreenWdith:" + mScreenWdith + " mScreenheight :" + mScreenWdith * 720 / 960); +// } +// }); //守护相关 mLiveGuardInfo = new LiveGuardInfo(); int guardNum = Integer.parseInt(data.getEnterRoomInfo().getGuardNums()); @@ -1830,7 +1839,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe * @param time */ public void upDataPkScore(JSONArray pkScores, int time) { - if (mLivePlayViewHolder != null) { + if (mLiveRoomViewHolder != null) { String liveId = mLiveBean.getUid(); JSONObject liveModel = null; //调整数据 @@ -1844,7 +1853,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } pkScores.remove(index); pkScores.add(0, liveModel); - mLivePlayViewHolder.upDataPkScore(pkScores, time); + mLiveRoomViewHolder.upDataPkScore(pkScores, time); } } @@ -1855,4 +1864,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } + public void removeDetailView() { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.removeDetailView(); + } + } + } diff --git a/live/src/main/res/layout/view_live_pk_details.xml b/live/src/main/res/layout/view_live_pk_details.xml index 3b856255d..0cf81b157 100644 --- a/live/src/main/res/layout/view_live_pk_details.xml +++ b/live/src/main/res/layout/view_live_pk_details.xml @@ -50,6 +50,7 @@ android:maxLines="1" android:ellipsize="end" android:maxWidth="50dp" + android:clickable="true" android:paddingStart="6dp" android:paddingTop="4.33dp" android:paddingEnd="6dp" @@ -110,6 +111,7 @@ android:maxLines="1" android:paddingStart="6dp" android:paddingTop="4.33dp" + android:clickable="true" android:paddingEnd="6dp" android:paddingBottom="4.33dp" android:text="我方" @@ -134,6 +136,7 @@ android:background="@drawable/background_pk_time" android:maxLines="1" android:ellipsize="end" + android:clickable="true" android:maxWidth="50dp" android:paddingStart="6dp" android:paddingTop="4.33dp" @@ -193,6 +196,7 @@ android:maxLines="1" android:ellipsize="end" android:maxWidth="50dp" + android:clickable="true" android:paddingStart="6dp" android:paddingTop="4.33dp" android:paddingEnd="6dp"