直播计时功能添加

This commit is contained in:
18401019693 2023-02-18 13:57:37 +08:00
parent 8d823f7a07
commit 7cb7258210
4 changed files with 63 additions and 3 deletions

View File

@ -30,6 +30,7 @@
app:cardElevation="0dp" /> app:cardElevation="0dp" />
<TextView <TextView
android:id="@+id/live_time"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"

View File

@ -674,6 +674,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
bundle.putBoolean(Constants.HAS_GAME, hasGame); bundle.putBoolean(Constants.HAS_GAME, hasGame);
bundle.putInt("leave", leave); bundle.putInt("leave", leave);
bundle.putBoolean("isPk", isDRPK == 1 || PKing || mLivePushViewHolder.isPking()); bundle.putBoolean("isPk", isDRPK == 1 || PKing || mLivePushViewHolder.isPking());
bundle.putLong("liveTime", mLiveAnchorViewHolder.getmAnchorLiveTime());
bundle.putBoolean(Constants.OPEN_FLASH, mLivePushViewHolder != null && mLivePushViewHolder.isFlashOpen()); bundle.putBoolean(Constants.OPEN_FLASH, mLivePushViewHolder != null && mLivePushViewHolder.isFlashOpen());
fragment.setArguments(bundle); fragment.setArguments(bundle);
fragment.setFunctionClickListener(this); fragment.setFunctionClickListener(this);

View File

@ -13,6 +13,9 @@ import static com.yunbao.common.Constants.LIVE_FUNC_ZSLK;
import static com.yunbao.common.Constants.LIVE_ROBOT; import static com.yunbao.common.Constants.LIVE_ROBOT;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
@ -23,6 +26,7 @@ import android.widget.TextView;
import com.lxj.xpopup.XPopup; import com.lxj.xpopup.XPopup;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.dialog.AbsDialogFragment; import com.yunbao.common.dialog.AbsDialogFragment;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.LiveAnchorMessageCustomPopup; import com.yunbao.common.views.LiveAnchorMessageCustomPopup;
import com.yunbao.live.R; import com.yunbao.live.R;
@ -40,7 +44,7 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements
private LiveFunctionClickListener mFunctionClickListener; private LiveFunctionClickListener mFunctionClickListener;
private int leave = 0; private int leave = 0;
private boolean isPk; private boolean isPk;
private TextView mLiveTimeTextView;//主播的直播时长
// boolean isRy = false; // boolean isRy = false;
@Override @Override
@ -81,6 +85,7 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements
leave = bundle.getInt("leave", 0); leave = bundle.getInt("leave", 0);
isPk = bundle.getBoolean("isPk", false); isPk = bundle.getBoolean("isPk", false);
// isRy = bundle.getBoolean("isRy", false); // isRy = bundle.getBoolean("isRy", false);
mAnchorLiveTime = bundle.getLong("liveTime");
} }
mWishView = findViewById(R.id.live_tool_wish); mWishView = findViewById(R.id.live_tool_wish);
mPrankView = findViewById(R.id.live_tool_prank); mPrankView = findViewById(R.id.live_tool_prank);
@ -92,7 +97,7 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements
mMultiPkView = findViewById(R.id.live_tool_multi_pk); mMultiPkView = findViewById(R.id.live_tool_multi_pk);
mMicView = findViewById(R.id.live_tool_mic); mMicView = findViewById(R.id.live_tool_mic);
mRandomPk = findViewById(R.id.live_tool_random_pk); mRandomPk = findViewById(R.id.live_tool_random_pk);
mLiveTimeTextView = (TextView) findViewById(R.id.live_time);
mWishView.setOnClickListener(this); mWishView.setOnClickListener(this);
mPrankView.setOnClickListener(this); mPrankView.setOnClickListener(this);
mWksView.setOnClickListener(this); mWksView.setOnClickListener(this);
@ -114,7 +119,9 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements
((ImageView) mLeaveView.findViewById(R.id.live_tool_leave_img)).setImageResource(R.mipmap.icon_leave_p); ((ImageView) mLeaveView.findViewById(R.id.live_tool_leave_img)).setImageResource(R.mipmap.icon_leave_p);
((TextView) mLeaveView.findViewById(R.id.live_tool_leave_text)).setText(R.string.live_zslk1); ((TextView) mLeaveView.findViewById(R.id.live_tool_leave_text)).setText(R.string.live_zslk1);
} }
mLiveRoomHandler = new LiveRoomHandler();
mLiveTimeTextView.setText(StringUtil.getDurationText(mAnchorLiveTime));
startAnchorLiveTime();
} }
public void setFunctionClickListener(LiveFunctionClickListener functionClickListener) { public void setFunctionClickListener(LiveFunctionClickListener functionClickListener) {
@ -169,4 +176,52 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements
dismiss(); dismiss();
} }
} }
private final int WHAT_ANCHOR_LIVE_TIME = 3;//直播间主播计时
private LiveRoomHandler mLiveRoomHandler;
private long mAnchorLiveTime;//主播直播时间
/**
* 主播显示直播时间
*/
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 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;
}
} }

View File

@ -87,6 +87,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder {
super(context, parentView); super(context, parentView);
} }
public long getmAnchorLiveTime() {
return mAnchorLiveTime;
}
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {