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 c80613bcb..1ec5d9e1c 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -43,10 +43,7 @@ import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.L; 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.WordUtil; import com.yunbao.common.views.weight.VerticalViewPager; import com.yunbao.live.R; 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.LiveHttpUtil; 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.utils.LiveImDeletUtil; import com.yunbao.live.views.LiveRoomPlayViewHolder; @@ -106,9 +101,7 @@ public class LiveAudienceActivity extends LiveActivity { //直播间滑动数据列表 private List itemModelList = new ArrayList<>(); - private boolean mCoinNotEnough;//余额不足 - private LiveRoomCheckLivePresenter mCheckLivePresenter; - private boolean mLighted; + private PayPresenter mPayPresenter; public ImageView btnSmallScreen; public static String is_fans; @@ -151,6 +144,9 @@ public class LiveAudienceActivity extends LiveActivity { mLiveType = intent.getIntExtra(Constants.LIVE_TYPE, Constants.LIVE_TYPE_NORMAL); mLiveTypeVal = intent.getIntExtra(Constants.LIVE_TYPE_VAL, 0); mLiveBean = intent.getParcelableExtra(Constants.LIVE_BEAN); + mLiveUid = mLiveBean.getUid(); + mStream = mLiveBean.getStream(); + setVolumeControlStream(AudioManager.STREAM_MUSIC); manager = new PortraitLiveManager(this, intent); initView(); @@ -245,9 +241,9 @@ public class LiveAudienceActivity extends LiveActivity { } // 满足此种条件,表明需要加载直播视频,以及聊天室了 - if (viewGroup.getId() == mCurrentItem && (position == 0)&& mCurrentItem != mLastPosition) { + if (viewGroup.getId() == mCurrentItem && (position == 0) && mCurrentItem != mLastPosition) { - loadData(viewGroup,mCurrentItem); + loadData(viewGroup, mCurrentItem); } } @@ -282,7 +278,8 @@ public class LiveAudienceActivity extends LiveActivity { mLiveType = liveType; mLiveTypeVal = liveTypeVal; mLiveBean = liveBean1; - mStream = liveBean.getStream(); + mLiveUid = mLiveBean.getUid(); + mStream = mLiveBean.getStream(); mAncherName = liveBean.getUserNiceName(); //加载当前页面数据 View rootView = manager.getRootView(); @@ -365,13 +362,6 @@ public class LiveAudienceActivity extends LiveActivity { } - /** - * 结束观看 - */ - public void endPlay() { - manager.endPlay(); - release(); - } @Override 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 @@ -574,18 +554,7 @@ public class LiveAudienceActivity extends LiveActivity { * 点亮 */ public void light() { - if (!mLighted) { - 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(); - } + manager.light(); } @@ -593,7 +562,7 @@ public class LiveAudienceActivity extends LiveActivity { * 计时收费更新主播映票数 */ public void roomChargeUpdateVotes() { - sendUpdateVotesMessage(mLiveTypeVal); + manager.sendUpdateVotesMessage(); } /** @@ -618,43 +587,11 @@ public class LiveAudienceActivity extends LiveActivity { * 充值成功 */ public void onChargeSuccess() { - if (mLiveType == Constants.LIVE_TYPE_TIME) { - 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(); - } - }); - } - } - } - }); - } - } + manager.onChargeSuccess(); } public void setCoinNotEnough(boolean coinNotEnough) { - mCoinNotEnough = coinNotEnough; + manager.setCoinNotEnough(coinNotEnough); } 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 922cb9649..ce3e93217 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -1,6 +1,7 @@ package com.yunbao.live.views; import android.app.Activity; +import android.app.Dialog; import android.content.Intent; import android.content.res.Configuration; 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.manager.IMLoginManager; 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.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.utils.formatBigNum; import com.yunbao.common.views.SlideInBannerViewHolder; import com.yunbao.live.R; 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.LiveRoomCheckLivePresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; +import com.yunbao.live.socket.SocketChatUtil; import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketMessageListener; +import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; import org.greenrobot.eventbus.EventBus; @@ -155,6 +163,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe private String is_fans; private String anyway; private boolean mEnd; + private boolean mLighted; + private boolean mCoinNotEnough;//余额不足 + private boolean mFirstConnectSocket;//是否是第一次连接成功socket public PortraitLiveManager(Activity context, Intent intent) { this.mContext = context; @@ -435,7 +446,23 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override 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 @@ -445,57 +472,111 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onChat(LiveChatBean bean, int index) { - + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.insertChat(bean, index); + } + if (bean.getType() == LiveChatBean.LIGHT) { + onLight(); + } } @Override public void onLight() { - + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.playLightAnim(); + } } @Override 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 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 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 public void onBuyZuoji(LiveReceiveGiftBean bean) { - + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.showBuyZuojiMessage(bean); + } } @Override public void onBuyLiangName(LiveReceiveGiftBean bean) { - + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.showBuyLiangNameMessage(bean); + } } @Override public void onBuyVip(LiveReceiveGiftBean bean) { - + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.showBuyVipMessage(bean); + } } @Override public void onSys(LiveReceiveGiftBean bean) { - + mLiveRoomViewHolder.showSysMessage(bean); } @Override 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 public void onSendDanMu(LiveDanMuBean bean) { - + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.showDanmu(bean); + } } @Override @@ -534,7 +615,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @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 @@ -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); + } + } }