直播间的滚动

This commit is contained in:
18401019693 2022-08-20 17:00:35 +08:00
parent 18d62e5d56
commit 5ef2015715
2 changed files with 179 additions and 87 deletions

View File

@ -43,10 +43,7 @@ import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.L; import com.yunbao.common.utils.L;
import com.yunbao.common.utils.ProcessResultUtil; import com.yunbao.common.utils.ProcessResultUtil;
import com.yunbao.common.utils.RandomUtil;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.common.views.weight.VerticalViewPager; import com.yunbao.common.views.weight.VerticalViewPager;
import com.yunbao.live.R; import com.yunbao.live.R;
import com.yunbao.live.adapter.VerticalPagerAdapter; import com.yunbao.live.adapter.VerticalPagerAdapter;
@ -62,8 +59,6 @@ import com.yunbao.live.event.LiveRoomChangeEvent;
import com.yunbao.live.http.LiveHttpConsts; import com.yunbao.live.http.LiveHttpConsts;
import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import com.yunbao.live.socket.SocketChatUtil;
import com.yunbao.live.socket.SocketRyChatUtil;
import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.socket.SocketSendBean;
import com.yunbao.live.utils.LiveImDeletUtil; import com.yunbao.live.utils.LiveImDeletUtil;
import com.yunbao.live.views.LiveRoomPlayViewHolder; import com.yunbao.live.views.LiveRoomPlayViewHolder;
@ -106,9 +101,7 @@ public class LiveAudienceActivity extends LiveActivity {
//直播间滑动数据列表 //直播间滑动数据列表
private List<AnchorRecommendItemModel> itemModelList = new ArrayList<>(); private List<AnchorRecommendItemModel> itemModelList = new ArrayList<>();
private boolean mCoinNotEnough;//余额不足
private LiveRoomCheckLivePresenter mCheckLivePresenter;
private boolean mLighted;
private PayPresenter mPayPresenter; private PayPresenter mPayPresenter;
public ImageView btnSmallScreen; public ImageView btnSmallScreen;
public static String is_fans; public static String is_fans;
@ -151,6 +144,9 @@ public class LiveAudienceActivity extends LiveActivity {
mLiveType = intent.getIntExtra(Constants.LIVE_TYPE, Constants.LIVE_TYPE_NORMAL); mLiveType = intent.getIntExtra(Constants.LIVE_TYPE, Constants.LIVE_TYPE_NORMAL);
mLiveTypeVal = intent.getIntExtra(Constants.LIVE_TYPE_VAL, 0); mLiveTypeVal = intent.getIntExtra(Constants.LIVE_TYPE_VAL, 0);
mLiveBean = intent.getParcelableExtra(Constants.LIVE_BEAN); mLiveBean = intent.getParcelableExtra(Constants.LIVE_BEAN);
mLiveUid = mLiveBean.getUid();
mStream = mLiveBean.getStream();
setVolumeControlStream(AudioManager.STREAM_MUSIC); setVolumeControlStream(AudioManager.STREAM_MUSIC);
manager = new PortraitLiveManager(this, intent); manager = new PortraitLiveManager(this, intent);
initView(); initView();
@ -282,7 +278,8 @@ public class LiveAudienceActivity extends LiveActivity {
mLiveType = liveType; mLiveType = liveType;
mLiveTypeVal = liveTypeVal; mLiveTypeVal = liveTypeVal;
mLiveBean = liveBean1; mLiveBean = liveBean1;
mStream = liveBean.getStream(); mLiveUid = mLiveBean.getUid();
mStream = mLiveBean.getStream();
mAncherName = liveBean.getUserNiceName(); mAncherName = liveBean.getUserNiceName();
//加载当前页面数据 //加载当前页面数据
View rootView = manager.getRootView(); View rootView = manager.getRootView();
@ -365,13 +362,6 @@ public class LiveAudienceActivity extends LiveActivity {
} }
/**
* 结束观看
*/
public void endPlay() {
manager.endPlay();
release();
}
@Override @Override
protected void release() { protected void release() {
@ -398,17 +388,7 @@ public class LiveAudienceActivity extends LiveActivity {
/** /**
* 观众收到踢人消息 * /**
*/
@Override
public void onKick(String touid) {
if (!TextUtils.isEmpty(touid) && touid.equals(CommonAppConfig.getInstance().getUid())) {//被踢的是自己
exitLiveRoom();
ToastUtil.show(WordUtil.getString(R.string.live_kicked_2));
}
}
/**
* 观众收到禁言消息 * 观众收到禁言消息
*/ */
@Override @Override
@ -574,18 +554,7 @@ public class LiveAudienceActivity extends LiveActivity {
* 点亮 * 点亮
*/ */
public void light() { public void light() {
if (!mLighted) { manager.light();
mLighted = true;
int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE;
if (isRy == false) {
SocketChatUtil.sendLightMessage(mLiveUid, 1 + RandomUtil.nextInt(6), guardType);
} else {
SocketRyChatUtil.sendLightMessage(mLiveUid, 1 + RandomUtil.nextInt(6), guardType);
}
}
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.playLightAnim();
}
} }
@ -593,7 +562,7 @@ public class LiveAudienceActivity extends LiveActivity {
* 计时收费更新主播映票数 * 计时收费更新主播映票数
*/ */
public void roomChargeUpdateVotes() { public void roomChargeUpdateVotes() {
sendUpdateVotesMessage(mLiveTypeVal); manager.sendUpdateVotesMessage();
} }
/** /**
@ -618,43 +587,11 @@ public class LiveAudienceActivity extends LiveActivity {
* 充值成功 * 充值成功
*/ */
public void onChargeSuccess() { public void onChargeSuccess() {
if (mLiveType == Constants.LIVE_TYPE_TIME) { manager.onChargeSuccess();
if (mCoinNotEnough) {
mCoinNotEnough = false;
LiveHttpUtil.roomCharge(mLiveUid, mStream, new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0) {
roomChargeUpdateVotes();
if (mLiveRoomViewHolder != null) {
resumePlay();
mLiveRoomViewHolder.startRequestTimeCharge();
}
} else {
if (code == 1008) {//余额不足
mCoinNotEnough = true;
DialogUitl.showSimpleDialog(mContext, WordUtil.getString(R.string.live_coin_not_enough), false,
new DialogUitl.SimpleCallback2() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
RouteUtil.forwardMyCoin(mContext);
}
@Override
public void onCancelClick() {
exitLiveRoom();
}
});
}
}
}
});
}
}
} }
public void setCoinNotEnough(boolean coinNotEnough) { public void setCoinNotEnough(boolean coinNotEnough) {
mCoinNotEnough = coinNotEnough; manager.setCoinNotEnough(coinNotEnough);
} }

View File

@ -1,6 +1,7 @@
package com.yunbao.live.views; package com.yunbao.live.views;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Outline; import android.graphics.Outline;
@ -45,7 +46,12 @@ import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.main.MainNetManager; import com.yunbao.common.http.main.MainNetManager;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DeviceUtils;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.RandomUtil;
import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.common.utils.formatBigNum;
import com.yunbao.common.views.SlideInBannerViewHolder; import com.yunbao.common.views.SlideInBannerViewHolder;
import com.yunbao.live.R; import com.yunbao.live.R;
import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveActivity;
@ -72,8 +78,10 @@ import com.yunbao.live.presenter.LiveLinkMicPkPresenter;
import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter;
import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter;
import com.yunbao.live.socket.SocketChatUtil;
import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketClient;
import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketMessageListener;
import com.yunbao.live.socket.SocketRyChatUtil;
import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketRyClient;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
@ -155,6 +163,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
private String is_fans; private String is_fans;
private String anyway; private String anyway;
private boolean mEnd; private boolean mEnd;
private boolean mLighted;
private boolean mCoinNotEnough;//余额不足
private boolean mFirstConnectSocket;//是否是第一次连接成功socket
public PortraitLiveManager(Activity context, Intent intent) { public PortraitLiveManager(Activity context, Intent intent) {
this.mContext = context; this.mContext = context;
@ -435,7 +446,23 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
@Override @Override
public void onConnect(boolean successConn) { public void onConnect(boolean successConn) {
if (successConn) {
if (!mFirstConnectSocket) {
mFirstConnectSocket = true;
if (mLiveType == Constants.LIVE_TYPE_PAY || mLiveType == Constants.LIVE_TYPE_TIME) {
if (!(mIntent.getIntExtra("isry", 0) == 1)) {
SocketChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal, 1);
} else {
SocketRyChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal, 1);
}
}
if (!(mIntent.getIntExtra("isry", 0) == 1)) {
SocketChatUtil.getFakeFans(mLiveBean.getUid());
} else {
SocketRyChatUtil.getFakeFans(mLiveBean.getUid());
}
}
}
} }
@Override @Override
@ -445,57 +472,111 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
@Override @Override
public void onChat(LiveChatBean bean, int index) { public void onChat(LiveChatBean bean, int index) {
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.insertChat(bean, index);
}
if (bean.getType() == LiveChatBean.LIGHT) {
onLight();
}
} }
@Override @Override
public void onLight() { public void onLight() {
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.playLightAnim();
}
} }
@Override @Override
public void onEnterRoom(LiveEnterRoomBean bean) { public void onEnterRoom(LiveEnterRoomBean bean) {
if (mLiveRoomViewHolder != null) {
LiveUserGiftBean u = bean.getUserBean();
if (!bean.getUserBean().getCar().getWords().equals("")) {
bean.getLiveChatBean().setContent(bean.getUserBean().getCar().getWords());
}
mLiveRoomViewHolder.insertChat(bean.getLiveChatBean(), 1);
mLiveRoomViewHolder.onEnterRoom(bean);
}
} }
@Override @Override
public void onLeaveRoom(UserBean bean) { public void onLeaveRoom(UserBean bean) {
if (mLiveLinkMicPresenter != null) {
mLiveLinkMicPresenter.onAudienceLeaveRoom(bean);
}
try {
if (mLiveRoomViewHolder.room_hot != null) {
if (!"".equals(bean.getHot_num()) && !"0".equals(bean.getHot_num())) {
mLiveRoomViewHolder.room_hot.setText(formatBigNum.formatBigNum(bean.getHot_num()));
}
}
} catch (Exception ignored) {
} }
}
@Override @Override
public void onSendGift(LiveReceiveGiftBean bean) { public void onSendGift(LiveReceiveGiftBean bean) {
//购买守护
if (bean.ismTypeBuyGuard()) {
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.showGuardGifMessage(bean);
}
} else {
if (mLiveRoomViewHolder != null) {
if (bean.getmLiveUId().equals(bean.getRoomnum())) {
mLiveRoomViewHolder.insertChat(bean.getLiveChatBean(), 1);
}
mLiveRoomViewHolder.showGiftMessage(bean, false);
} }
}
}
@Override @Override
public void onBuyZuoji(LiveReceiveGiftBean bean) { public void onBuyZuoji(LiveReceiveGiftBean bean) {
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.showBuyZuojiMessage(bean);
}
} }
@Override @Override
public void onBuyLiangName(LiveReceiveGiftBean bean) { public void onBuyLiangName(LiveReceiveGiftBean bean) {
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.showBuyLiangNameMessage(bean);
}
} }
@Override @Override
public void onBuyVip(LiveReceiveGiftBean bean) { public void onBuyVip(LiveReceiveGiftBean bean) {
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.showBuyVipMessage(bean);
}
} }
@Override @Override
public void onSys(LiveReceiveGiftBean bean) { public void onSys(LiveReceiveGiftBean bean) {
mLiveRoomViewHolder.showSysMessage(bean);
} }
@Override @Override
public void onSendGiftPk(long leftGift, long rightGift, LivePKUserListBean bean) { public void onSendGiftPk(long leftGift, long rightGift, LivePKUserListBean bean) {
if (!(mIntent.getIntExtra("isry", 0) == 1)) {
if (mLiveLinkMicPkPresenter != null) {
mLiveLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean);
}
} else {
if (mLiveRyLinkMicPkPresenter != null) {
mLiveRyLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean);
}
}
} }
@Override @Override
public void onSendDanMu(LiveDanMuBean bean) { public void onSendDanMu(LiveDanMuBean bean) {
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.showDanmu(bean);
}
} }
@Override @Override
@ -534,7 +615,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
@Override @Override
public void onKick(String touid) { public void onKick(String touid) {
if (!TextUtils.isEmpty(touid) && touid.equals(CommonAppConfig.getInstance().getUid())) {//被踢的是自己
exitLiveRoom();
ToastUtil.show(WordUtil.getString(R.string.live_kicked_2));
}
} }
@Override @Override
@ -1283,4 +1367,75 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
} }
} }
/**
* 点亮
*/
public void light() {
if (!mLighted) {
mLighted = true;
int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE;
if (!(mIntent.getIntExtra("isry", 0) == 1)) {
SocketChatUtil.sendLightMessage(mLiveBean.getUid(), 1 + RandomUtil.nextInt(6), guardType);
} else {
SocketRyChatUtil.sendLightMessage(mLiveBean.getUid(), 1 + RandomUtil.nextInt(6), guardType);
}
}
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.playLightAnim();
}
}
public void setCoinNotEnough(boolean coinNotEnough) {
mCoinNotEnough = coinNotEnough;
}
/**
* 充值成功
*/
public void onChargeSuccess() {
if (mLiveType == Constants.LIVE_TYPE_TIME) {
if (mCoinNotEnough) {
mCoinNotEnough = false;
LiveHttpUtil.roomCharge(mLiveBean.getUid(), mLiveBean.getStream(), new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0) {
sendUpdateVotesMessage();
if (mLiveRoomViewHolder != null) {
resumePlay();
mLiveRoomViewHolder.startRequestTimeCharge();
}
} else {
if (code == 1008) {//余额不足
mCoinNotEnough = true;
DialogUitl.showSimpleDialog(mContext, WordUtil.getString(R.string.live_coin_not_enough), false,
new DialogUitl.SimpleCallback2() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
RouteUtil.forwardMyCoin(mContext);
}
@Override
public void onCancelClick() {
exitLiveRoom();
}
});
}
}
}
});
}
}
}
/**
* 更新主播映票数
*/
public void sendUpdateVotesMessage() {
if (!(mIntent.getIntExtra("isry", 0) == 1)) {
SocketChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal);
} else {
SocketRyChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal);
}
}
} }