From 606fc64262821fa01af1461b7f8853a3c5d37fc5 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Wed, 14 Dec 2022 16:31:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BB=E6=92=AD=E6=92=AD=E6=94=BE=E6=97=B6=E9=95=BF=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/activity/LiveRyAnchorActivity.java | 2 + .../yunbao/live/views/LiveRoomViewHolder.java | 20 +------ .../live/views/LiveRyAnchorViewHolder.java | 59 ++++++++++++++++++- .../main/res/layout/view_ry_live_anchor.xml | 21 +++++++ 4 files changed, 82 insertions(+), 20 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 4b567190b..6e2cf06d3 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -670,6 +670,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl L.e("createRoom----播放地址--->" + playUrl); mLiveBean.setPull(playUrl); mTxAppId = obj.getString("tx_appid"); + //移除开播前的设置控件,添加直播间控件 if (mLiveReadyViewHolder != null) { mLiveReadyViewHolder.removeFromParent(); @@ -701,6 +702,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl mLiveAnchorViewHolder = new LiveRyAnchorViewHolder(mContext, mContainer); mLiveAnchorViewHolder.setLiveBean(mLiveBean); mLiveAnchorViewHolder.addToParent(); + mLiveAnchorViewHolder.startAnchorLiveTime(); } mLiveBottomViewHolder = mLiveAnchorViewHolder; mSocketRyClient = new SocketRyClient(mLiveUid, this); 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 56003c782..b255d29a3 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -208,8 +208,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis private GifImageView mGifImageView; public static SVGAImageView mSVGAImageView; private ViewGroup mLiveGiftPrizePoolContainer; - private TextView mLiveTimeTextView;//主播的直播时长 - private long mAnchorLiveTime;//主播直播时间 + private View mBtnPrizePool;//奖池按钮 private TextView mPrizePoolLevel;//奖池等级 private int forAct; @@ -939,9 +938,6 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mBtnRedPack.setOnClickListener(this); if (mContext instanceof LiveAudienceActivity) { mRoot.setOnClickListener(this); - } else { - mLiveTimeTextView = (TextView) findViewById(R.id.live_time); - mLiveTimeTextView.setVisibility(View.VISIBLE); } mLightAnimPresenter = new LiveLightAnimPresenter(mContext, mParentView); mLiveEnterRoomAnimPresenter = new LiveEnterRoomAnimPresenter(mContext, mContentView, mScreenWdith); @@ -2916,16 +2912,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } } - /** - * 主播显示直播时间 - */ - private void showAnchorLiveTime() { - if (mLiveTimeTextView != null) { - mAnchorLiveTime += 1000; - mLiveTimeTextView.setText(StringUtil.getDurationText(mAnchorLiveTime)); - startAnchorLiveTime(); - } - } + public void startAnchorLiveTime() { if (mLiveRoomHandler != null) { @@ -3226,9 +3213,6 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis case WHAT_TIME_CHARGE: mLiveRoomViewHolder.requestTimeCharge(); break; - case WHAT_ANCHOR_LIVE_TIME: - mLiveRoomViewHolder.showAnchorLiveTime(); - break; case WHAT_ANCHOR_PAUSE: mLiveRoomViewHolder.anchorEndLive(); break; diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index bff0273c6..19f774b6a 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -4,13 +4,15 @@ import static com.yunbao.live.activity.LiveActivity.mLiveUid; import static com.yunbao.live.activity.LiveRyAnchorActivity.PKing; import static com.yunbao.live.activity.LiveRyAnchorActivity.pk_nub; import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.START_MESSAGE; -import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.WISH_LIST; import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.WISH_LIST_UPDATE; import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.leaveDRRoom; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.SystemClock; import android.text.TextUtils; import android.util.Log; import android.view.View; @@ -37,6 +39,7 @@ import com.yunbao.common.http.HttpClient; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveRyAnchorActivity; @@ -77,10 +80,13 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { private LiveBean mLiveBean; private List mBannerList = new ArrayList<>(); private String activityUrl; - + private TextView mLiveTimeTextView;//主播的直播时长 + private long mAnchorLiveTime;//主播直播时间 + private LiveRoomHandler mLiveRoomHandler; public LiveRyAnchorViewHolder(Context context, ViewGroup parentView) { super(context, parentView); + } @Override @@ -163,6 +169,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { } }); findViewById(R.id.btn_link_mic).setOnClickListener(this); + mLiveTimeTextView = (TextView) findViewById(R.id.live_time); + mLiveTimeTextView.setVisibility(View.VISIBLE); + mLiveRoomHandler = new LiveRoomHandler(); } @Override @@ -568,4 +577,50 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { initWishList(); setLiveUid(mLiveBean.getUid()); } + + /** + * 主播显示直播时间 + */ + private void showAnchorLiveTime() { + if (mLiveTimeTextView != null) { + mAnchorLiveTime += 1000; + mLiveTimeTextView.setText(StringUtil.getDurationText(mAnchorLiveTime)); + startAnchorLiveTime(); + } + } + + public void startAnchorLiveTime() { + if (mLiveRoomHandler != null) { + mLiveRoomHandler.sendEmptyMessageAtTime(WHAT_ANCHOR_LIVE_TIME, getNextTime(1000)); + } + } + + private final int WHAT_ANCHOR_LIVE_TIME = 3;//直播间主播计时 + + private class LiveRoomHandler extends Handler { + @Override + public void handleMessage(Message msg) { + + switch (msg.what) { + + case WHAT_ANCHOR_LIVE_TIME: + showAnchorLiveTime(); + break; + + + } + } + + public void release() { + removeCallbacksAndMessages(null); + } + } + + private long getNextTime(int time) { + long now = SystemClock.uptimeMillis(); + if (time < 1000) { + return now + time; + } + return now + time + -now % 1000; + } } diff --git a/live/src/main/res/layout/view_ry_live_anchor.xml b/live/src/main/res/layout/view_ry_live_anchor.xml index 796bfaad5..51c1b3c32 100644 --- a/live/src/main/res/layout/view_ry_live_anchor.xml +++ b/live/src/main/res/layout/view_ry_live_anchor.xml @@ -133,6 +133,7 @@ PK" android:layout_height="45dp" android:layout_gravity="bottom"> + + \ No newline at end of file