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 430527077..aa96bdef8 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -1258,7 +1258,11 @@ public class LiveAudienceActivity extends LiveActivity { } break; - + case LEAVE_PK_SCORE: + if (manager != null) { + manager.upDataPkScore(event.getPkScores(), event.getTime()); + } + break; case PK_TIME_COUNT: if (manager != null) { manager.endDRGif(); 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 91d039452..7b77f93f0 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -10,17 +10,22 @@ import android.graphics.Color; import android.media.AudioManager; import android.os.Handler; import android.os.Looper; +import android.os.SystemClock; import android.text.TextUtils; import android.util.Log; import android.view.Gravity; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.ui.StyledPlayerView; @@ -31,6 +36,7 @@ import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; import com.lzy.okserver.OkDownload; import com.yunbao.common.bean.EnterRoomNewModel; +import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.manager.IMLoginManager; @@ -40,6 +46,7 @@ import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; import com.yunbao.common.utils.MicStatusManager; import com.yunbao.common.utils.ScreenDimenUtil; +import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.common.views.LiveClarityCustomPopup; @@ -646,7 +653,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.topMargin = 0; params.addRule(RelativeLayout.ALIGN_TOP); - // mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation270); mVideoView.requestLayout(); } @@ -1204,5 +1210,130 @@ 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) { + + 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); + + } + + 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; + } + } + } + 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/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index 63bc39eea..440030882 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -3,6 +3,7 @@ package com.yunbao.live.views; import android.content.Context; import android.view.ViewGroup; +import com.alibaba.fastjson.JSONArray; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.utils.ToastUtil; @@ -101,6 +102,7 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL } + public interface OnMicCallback { void onMikUpdate(); 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 a2d2f7704..637b0f48c 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -22,6 +22,7 @@ import androidx.drawerlayout.widget.DrawerLayout; import androidx.viewpager.widget.PagerAdapter; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; import com.lzf.easyfloat.EasyFloat; @@ -129,7 +130,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //侧滑布局 // private DrawerLayout drawerLayout; //直播间拆分布局 - private LiveRoomPlayViewHolder mLivePlayViewHolder; + private LivePlayRyViewHolder mLivePlayViewHolder; //头部布局 public LiveRoomViewHolder mLiveRoomViewHolder; //底部布局 @@ -574,7 +575,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLivePlayViewHolder.setViewUP(4); } - mLiveRoomViewHolder.UpPkBar(pkInfo.getJSONArray("userlist"), mLiveBean.getUid(), pkInfo.getIntValue("drpk_time")); + upDataPkScore(pkInfo.getJSONArray("userlist"), pkInfo.getIntValue("drpk_time")); } //守护相关 mLiveGuardInfo = new LiveGuardInfo(); @@ -692,7 +693,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter = null; } if (mLiveEndViewHolder != null) { - removeLiveEnd(); + removeLiveEnd(); } if (isQuit) { @@ -1818,6 +1819,31 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mViewPager.setCanScroll(enableScroll); } + /** + * 用户端多人Pk + * + * @param pkScores + * @param time + */ + public void upDataPkScore(JSONArray pkScores, int time) { + if (mLivePlayViewHolder != null) { + String liveId = mLiveBean.getUid(); + JSONObject liveModel = null; + //调整数据 + int index = 0; + for (int i = 0; i < pkScores.size(); i++) { + JSONObject score = pkScores.getJSONObject(i); + if (TextUtils.equals(score.getString("id"), liveId)) { + liveModel = score; + index = i; + } + } + pkScores.remove(index); + pkScores.add(0, liveModel); + mLivePlayViewHolder.upDataPkScore(pkScores, time); + + } + } public void endDRGif() { if (mLiveRoomViewHolder != null) {