From b4a71e12827a6ca48941a9c65fe2de7110a2494f Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Fri, 26 Aug 2022 16:37:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=20=E4=BE=A7?= =?UTF-8?q?=E8=BE=B9=E6=A0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 4 +- .../com/yunbao/common/utils/DialogUitl.java | 39 ++- .../views/weight/VerticalViewPager.java | 4 + config.gradle | 4 +- .../yunbao/live/activity/LiveActivity.java | 2 + .../live/activity/LiveAudienceActivity.java | 280 ++++++------------ .../live/dialog/SidebarLiveAudience.java | 19 +- .../yunbao/live/event/LiveAudienceEvent.java | 41 +++ .../live/views/PortraitLiveManager.java | 179 +++++++++-- 9 files changed, 359 insertions(+), 213 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index b0082ba72..b4b8498b4 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -177,7 +177,7 @@ public class AppContext extends CommonAppContext { msg.obj = content.getContent(); if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) - || (TextUtils.equals("g" + PortraitLiveManager.liveID, message.getTargetId())))) { + || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { SocketRyClient.mSocketHandler.sendMessage(msg); } } @@ -240,7 +240,7 @@ public class AppContext extends CommonAppContext { /** * 注册全局异常捕获,有需要时可以在onCreate调用 */ - private void registerError(){ + private void registerError() { NeverCrashUtils.getInstance() .setDebugMode(BuildConfig.DEBUG) .setMainCrashHandler((t, e) -> { diff --git a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java index d7e23fe33..f309a0b24 100644 --- a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java +++ b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java @@ -97,7 +97,7 @@ public class DialogUitl { } public static void showSimpleDialog(Context context, String content, SimpleCallback callback) { - showSimpleDialog(context, content, true, callback); + showSimpleDialog(context, content, false, callback); } public static void showSimpleDialog(Context context, String content, boolean cancelable, SimpleCallback callback) { @@ -114,6 +114,15 @@ public class DialogUitl { .show(); } + public static void showSimpleDialog(Context context, String title, String content, boolean cancelable, SimpleCallback3 callback) { + new Builder(context) + .setTitle(title) + .setContent(content) + .setCancelable(cancelable) + .setClickCallback3(callback) + .build() + .show(); + } public static void showSimpleInputDialog(Context context, String title, String hint, int inputType, int length, SimpleCallback callback) { new Builder(context).setTitle(title) @@ -290,6 +299,7 @@ public class DialogUitl { private int mInputType; private int mLength; private SimpleCallback mClickCallback; + private SimpleCallback3 mClickCallback3; public Builder(Context context) { mContext = context; @@ -350,6 +360,11 @@ public class DialogUitl { return this; } + public Builder setClickCallback3(SimpleCallback3 clickCallback) { + mClickCallback3 = clickCallback; + return this; + } + public Dialog build() { final Dialog dialog = new Dialog(mContext, mBackgroundDimEnabled ? R.style.dialog : R.style.dialog2); dialog.setContentView(mInput ? R.layout.dialog_input : R.layout.dialog_simple); @@ -397,12 +412,24 @@ public class DialogUitl { } } else { dialog.dismiss(); + if (mClickCallback3 != null) { + mClickCallback3.onConfirmClick(dialog); + } + } + } else { dialog.dismiss(); - if (mClickCallback instanceof SimpleCallback2) { - ((SimpleCallback2) mClickCallback).onCancelClick(); + if (mClickCallback3 != null) { + mClickCallback3.onCancel(); + + } else { + + if (mClickCallback instanceof SimpleCallback2) { + ((SimpleCallback2) mClickCallback).onCancelClick(); + } } + } } }; @@ -429,6 +456,12 @@ public class DialogUitl { void onCancelClick(); } + public interface SimpleCallback3 { + void onConfirmClick(Dialog dialog); + + void onCancel(); + } + /** * 城市选择 diff --git a/common/src/main/java/com/yunbao/common/views/weight/VerticalViewPager.java b/common/src/main/java/com/yunbao/common/views/weight/VerticalViewPager.java index d09c17b4d..60207de8c 100644 --- a/common/src/main/java/com/yunbao/common/views/weight/VerticalViewPager.java +++ b/common/src/main/java/com/yunbao/common/views/weight/VerticalViewPager.java @@ -75,6 +75,10 @@ public class VerticalViewPager extends ViewGroup { private boolean mEnableScroll = true; + public boolean ismEnableScroll() { + return mEnableScroll; + } + /** * Used to track what the expected number of items in the adapter should be. * If the app changes this when we don't expect it, we'll throw a big obnoxious exception. diff --git a/config.gradle b/config.gradle index cf3f0a090..7d7250467 100644 --- a/config.gradle +++ b/config.gradle @@ -10,9 +10,9 @@ ext { manifestPlaceholders = [ //正式 -// serverHost : "https://napi.yaoulive.com", + serverHost : "https://napi.yaoulive.com", //測試 - serverHost : "https://ceshi.yaoulive.com", +// serverHost : "https://ceshi.yaoulive.com", //腾讯地图 txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB", diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 82c0bba20..4d5515766 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -327,6 +327,8 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL } } + + @Override public void onBuyLiangName(LiveReceiveGiftBean bean) { if (mLiveRoomViewHolder != null) { 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 f55482dac..f1e61654e 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -1,6 +1,5 @@ package com.yunbao.live.activity; -import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.media.AudioManager; @@ -62,8 +61,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.SocketSendBean; -import com.yunbao.live.utils.LiveImDeletUtil; import com.yunbao.live.views.LiveRoomPlayViewHolder; import com.yunbao.live.views.PortraitLiveManager; @@ -73,15 +70,6 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; import java.util.List; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; -import cn.rongcloud.rtc.base.RTCErrorCode; -import io.rong.imlib.IRongCallback; -import io.rong.imlib.RongIMClient; -import io.rong.imlib.model.Conversation; -import io.rong.message.TextMessage; - import static com.yunbao.live.views.LivePlayRyViewHolder.Micing; /** @@ -110,7 +98,7 @@ public class LiveAudienceActivity extends LiveActivity { public static int fansNum; public static ProcessResultUtil mProcessResultUtil; - private LiveImDeletUtil liveImDeletUtil; + public static int isattention; private LiveBean mLiveBean; @@ -139,7 +127,7 @@ public class LiveAudienceActivity extends LiveActivity { Bus.getOn(this); super.main(); liveAudienceActivity = this; - liveImDeletUtil = new LiveImDeletUtil(); + mProcessResultUtil = new ProcessResultUtil(this); Intent intent = getIntent(); mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); @@ -149,11 +137,6 @@ public class LiveAudienceActivity extends LiveActivity { mLiveBean = intent.getParcelableExtra(Constants.LIVE_BEAN); mLiveUid = mLiveBean.getUid(); mStream = mLiveBean.getStream(); -// if (getIntent().getIntExtra("isry", 0) == 1) { -// isRy = true; -// } else { -// isRy = false; -// } setVolumeControlStream(AudioManager.STREAM_MUSIC); manager = new PortraitLiveManager(this, intent); initView(); @@ -192,25 +175,39 @@ public class LiveAudienceActivity extends LiveActivity { verticalViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - mCurrentItem = position; - Log.e(TAG, "mCurrentItem:" + mCurrentItem); - if (mCurrentItem == itemModelList.size() - 1) { - MainNetManager.get(mContext) - .anchorRecommendType("30", new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(AnchorRecommendModel data) { - if (TextUtils.equals(data.getList().get(0).getUid(), mLiveBean.getUid())) { - data.getList().remove(0); - } - itemModelList.addAll(data.getList()); - mPagerAdapter.notifyDataSetChanged(); - } - @Override - public void onError(String error) { - } - }); + if (Micing == 1) { + + manager.micIngTypeOne(mLiveBean, mLiveType, mLiveTypeVal); + verticalViewPager.setEnableScroll(false); + } else if (Micing == 2) { + verticalViewPager.setEnableScroll(false); + manager.micIngTypeTwo(mLiveBean, mLiveType, mLiveTypeVal); + + } else { + verticalViewPager.setEnableScroll(true); + mCurrentItem = position; + Log.e(TAG, "mCurrentItem:" + mCurrentItem); + if (mCurrentItem == itemModelList.size() - 1) { + MainNetManager.get(mContext) + .anchorRecommendType("30", new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(AnchorRecommendModel data) { + if (TextUtils.equals(data.getList().get(0).getUid(), mLiveBean.getUid())) { + data.getList().remove(0); + } + itemModelList.addAll(data.getList()); + mPagerAdapter.notifyDataSetChanged(); + } + + @Override + public void onError(String error) { + } + }); + } } + + } @Override @@ -414,115 +411,15 @@ public class LiveAudienceActivity extends LiveActivity { @Override public void onBackPressed() { + manager.onBackPressed(); if (Micing == 1) { - DialogUitl.showSimpleDialog(mContext, "您已申請,退出將取消語音連麥申請!", new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - Micing = 0; - //用户申请联麦 - final SocketSendBean msg = new SocketSendBean() - .param("_method_", Constants.LIAN_MAI) - .param("action", 7) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("avatar", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("uid", CommonAppConfig.getInstance().getUid()); - msg.create(); - - String targetId = mLiveUid; - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - liveImDeletUtil.deleteMessages(message.getTargetId(), message.getMessageId()); - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + errorCode.toString()); - liveImDeletUtil.deleteMessages(message.getTargetId(), message.getMessageId()); - } - }); - end(); - } - }); - return; + manager.micIngTypeOne(mLiveBean, mLiveType, mLiveTypeVal); } else if (Micing == 2) { - DialogUitl.showSimpleDialog(mContext, "連麥中,退出將斷開語音連麥!", new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - ToastUtil.show("下麥中,稍等....."); - RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { - - /** - * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 - * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ - @Override - public void onKicked() { - - } - - @Override - public void onSuccess() { - Log.e("ry", "下麦成功"); - // 该用户切换为观众成功,可以以观众身份进行音视频 - //退出多人房间 - HttpClient.getInstance().get("live.leaveDrLm", "live.leaveDrLm") - .params("roomid", LiveActivity.mLiveUid) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.e("ry", code + "退出多人"); - - } - }); - //退出rtc播放 - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "退出多人房间成功"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - Micing = 0; - end(); - } - }); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", errorCode + "退出多人房间失敗"); - - } - }); - - } - - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "下麦失败" + errorCode); - - } - }); - - } - }); - return; + manager.micIngTypeTwo(mLiveBean, mLiveType, mLiveTypeVal); + } else { + super.onBackPressed(); } - end(); + } public void end() { @@ -635,24 +532,34 @@ public class LiveAudienceActivity extends LiveActivity { fragment.show(getSupportFragmentManager(), "ChatChargeDialogFragment"); } + public void setEnableScroll(boolean enableScroll) { + verticalViewPager.setEnableScroll(enableScroll); + } @Subscribe(threadMode = ThreadMode.MAIN) public void onLiveRoomChangeEvent(LiveRoomChangeEvent e) { - LiveBean liveBean = e.getLiveBean(); - if (liveBean != null) { - LiveHttpUtil.cancel(LiveHttpConsts.CHECK_LIVE); - LiveHttpUtil.cancel(LiveHttpConsts.ENTER_ROOM); - LiveHttpUtil.cancel(LiveHttpConsts.ROOM_CHARGE); - manager.onRemove(); - mLiveType = e.getLiveType(); - mLiveTypeVal = e.getLiveTypeVal(); - mLiveBean = liveBean; - mLiveUid = liveBean.getUid(); - mStream = liveBean.getStream(); - mAncherName = liveBean.getUserNiceName(); - manager.onAdd(liveBean, mLiveType, mLiveTypeVal, mLiveSDK); + if (verticalViewPager.ismEnableScroll()) { + LiveBean liveBean = e.getLiveBean(); + if (liveBean != null) { + LiveHttpUtil.cancel(LiveHttpConsts.CHECK_LIVE); + LiveHttpUtil.cancel(LiveHttpConsts.ENTER_ROOM); + LiveHttpUtil.cancel(LiveHttpConsts.ROOM_CHARGE); + manager.onRemove(); + mLiveType = e.getLiveType(); + mLiveTypeVal = e.getLiveTypeVal(); + mLiveBean = liveBean; + mLiveUid = liveBean.getUid(); + mStream = liveBean.getStream(); + mAncherName = liveBean.getUserNiceName(); + manager.onAdd(liveBean, mLiveType, mLiveTypeVal, mLiveSDK); + + } + } else { + verticalViewPager.setEnableScroll(true); } + + } @Override @@ -673,6 +580,15 @@ public class LiveAudienceActivity extends LiveActivity { IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); switch (event.getType()) { case SIDEBAR: + int userIndex = -1; + for (int i = 0; i < list.size(); i++) { + if (TextUtils.equals(list.get(i).getUid(), PortraitLiveManager.liveID)) { + userIndex = i; + } + } + if (userIndex != -1) { + list.remove(userIndex); + } //从右边打开侧边栏 SidebarLiveAudience sidebarLiveAudience = new SidebarLiveAudience(); bundle.putString("Avatar", mLiveBean.getAvatar()); @@ -749,26 +665,32 @@ public class LiveAudienceActivity extends LiveActivity { ZhuangBanActivity.forward(mContext, nobleUrl, false); break; case LIAN_MAI: - //获取房间连麦状态 - HttpClient.getInstance().get("live.getDrLm", "live.getDrLm") - .params("uid", mLiveUid, true) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - LiveMicUserDialogFragment fragment = new LiveMicUserDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.STREAM, mStream); - bundle.putString("By", "1"); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveUserMoreDialogFragment"); - LiveMicUserDialogFragment.activity = ((LiveAudienceActivity) mContext); - } else { - ToastUtil.show(R.string.no_mic_opn); + if (event.getMicIng() == 1) { + manager.micIngTypeOne(event.getBean(), event.getLiveType(), event.getLiveTypeVal()); + } else if (event.getMicIng() == 2) { + manager.micIngTypeTwo(event.getBean(), event.getLiveType(), event.getLiveTypeVal()); + } else { + //获取房间连麦状态 + HttpClient.getInstance().get("live.getDrLm", "live.getDrLm") + .params("uid", mLiveUid, true) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + LiveMicUserDialogFragment fragment = new LiveMicUserDialogFragment(); + Bundle bundle = new Bundle(); + bundle.putString(Constants.LIVE_UID, mLiveUid); + bundle.putString(Constants.STREAM, mStream); + bundle.putString("By", "1"); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveUserMoreDialogFragment"); + LiveMicUserDialogFragment.activity = ((LiveAudienceActivity) mContext); + } else { + ToastUtil.show(R.string.no_mic_opn); + } } - } - }); + }); + } break; case EFFECTS_SETTINGS: EffectsSettingsDialog effectsSettingsDialog = new EffectsSettingsDialog(); @@ -867,15 +789,7 @@ public class LiveAudienceActivity extends LiveActivity { list.clear(); slideInfoModels.clear(); List models = anchorRecommendModel.getList(); - int userIndex = -1; - for (int i = 0; i < list.size(); i++) { - if (TextUtils.equals(list.get(i).getUid(), PortraitLiveManager.liveID)) { - userIndex = i; - } - } - if (userIndex != -1) { - models.remove(userIndex); - } + models.add(0, new AnchorRecommendItemModel()); list.addAll(models); slideInfoModels = anchorRecommendModel.getSlide(); diff --git a/live/src/main/java/com/yunbao/live/dialog/SidebarLiveAudience.java b/live/src/main/java/com/yunbao/live/dialog/SidebarLiveAudience.java index e738164af..bd87ea77c 100644 --- a/live/src/main/java/com/yunbao/live/dialog/SidebarLiveAudience.java +++ b/live/src/main/java/com/yunbao/live/dialog/SidebarLiveAudience.java @@ -34,6 +34,7 @@ import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.event.LiveRoomChangeEvent; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; +import com.yunbao.live.views.LivePlayRyViewHolder; import com.yunbao.live.views.PortraitLiveManager; import org.greenrobot.eventbus.EventBus; @@ -202,13 +203,25 @@ public class SidebarLiveAudience extends AbsDialogFragment { if (liveBean1 == null) { return; } - EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, liveTypeVal)); + if (LivePlayRyViewHolder.Micing == 1) { + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI) + .setMicIng(1) + .setBean(liveBean).setLiveType(liveType).setLiveTypeVal(liveTypeVal)); + } else if (LivePlayRyViewHolder.Micing == 2) { + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI) + .setMicIng(2) + .setBean(liveBean).setLiveType(liveType).setLiveTypeVal(liveTypeVal)); + } else { + EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, liveTypeVal)); + } + }); mCheckLivePresenter.checkLive(liveBean); } else { RouteUtil.forwardUserHome(getActivity(), liveId, 0); - getActivity().finish(); } } }); @@ -219,6 +232,6 @@ public class SidebarLiveAudience extends AbsDialogFragment { super.onDismiss(dialog); Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.REFRESH_THE_LIVEl_PAGE) - ); + ); } } diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index 1471ca115..0626a282d 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -3,6 +3,7 @@ package com.yunbao.live.event; import com.yunbao.common.bean.ActiveModel; import com.yunbao.common.bean.AnchorRecommendItemModel; import com.yunbao.common.bean.BaseModel; +import com.yunbao.live.bean.LiveBean; import com.yunbao.live.bean.OpenParametersModel; public class LiveAudienceEvent extends BaseModel { @@ -11,6 +12,46 @@ public class LiveAudienceEvent extends BaseModel { private String avatar = ""; private OpenParametersModel parametersModel = new OpenParametersModel(); private AnchorRecommendItemModel anchorRecommendItemModel = new AnchorRecommendItemModel(); + private int micIng = 0;//连麦状态 + private LiveBean bean; + private int liveType; + private int liveTypeVal; + + public int getLiveType() { + return liveType; + } + + public LiveAudienceEvent setLiveType(int liveType) { + this.liveType = liveType; + return this; + } + + public int getLiveTypeVal() { + return liveTypeVal; + } + + public LiveAudienceEvent setLiveTypeVal(int liveTypeVal) { + this.liveTypeVal = liveTypeVal; + return this; + } + + public LiveBean getBean() { + return bean; + } + + public LiveAudienceEvent setBean(LiveBean bean) { + this.bean = bean; + return this; + } + + public int getMicIng() { + return micIng; + } + + public LiveAudienceEvent setMicIng(int micIng) { + this.micIng = micIng; + return this; + } public AnchorRecommendItemModel getAnchorRecommendItemModel() { return anchorRecommendItemModel; 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 79905adfb..87ddd89d1 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -5,6 +5,8 @@ import android.app.Dialog; import android.content.Intent; import android.content.res.Configuration; import android.os.CountDownTimer; +import android.os.Handler; +import android.os.Looper; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -35,6 +37,7 @@ import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.CommonHttpConsts; import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; @@ -63,27 +66,38 @@ import com.yunbao.live.dialog.BlowkissDialog; import com.yunbao.live.dialog.NewUserDialog; import com.yunbao.live.event.LinkMicTxAccEvent; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.event.LiveRoomChangeEvent; import com.yunbao.live.http.LiveHttpConsts; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; -import com.yunbao.live.presenter.LiveLinkMicPkPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; 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 com.yunbao.live.socket.SocketSendBean; +import com.yunbao.live.utils.LiveImDeletUtil; import org.greenrobot.eventbus.EventBus; import java.util.List; +import cn.rongcloud.rtc.api.RCRTCEngine; +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; +import cn.rongcloud.rtc.base.RTCErrorCode; +import io.rong.imlib.IRongCallback; import io.rong.imlib.IRongCoreCallback; import io.rong.imlib.IRongCoreEnum; +import io.rong.imlib.RongIMClient; import io.rong.imlib.chatroom.base.RongChatRoomClient; +import io.rong.imlib.model.Conversation; +import io.rong.message.TextMessage; import static com.yunbao.common.CommonAppContext.logger; import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics; +import static com.yunbao.live.views.LivePlayRyViewHolder.Micing; import static com.yunbao.live.views.LiveRoomViewHolder.isStayRoomfive; /** @@ -123,8 +137,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //主播与主播连麦逻辑 private LiveLinkMicAnchorPresenter mLiveLinkMicAnchorPresenter; //主播与主播PK逻辑 - private LiveLinkMicPkPresenter mLiveLinkMicPkPresenter; - //主播与主播PK逻辑 private LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter; //直播间的类型 普通 密码 门票 计时等 private int mLiveType; @@ -150,10 +162,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe private boolean mCoinNotEnough;//余额不足 private boolean mFirstConnectSocket;//是否是第一次连接成功socket private int liveBg; + private LiveImDeletUtil liveImDeletUtil; + public PortraitLiveManager(Activity context, Intent intent) { this.mContext = context; this.mIntent = intent; + liveImDeletUtil = new LiveImDeletUtil(); ininView(); } @@ -203,8 +218,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe .setmLiveType(mLiveType) .setmLiveTypeVal(mLiveTypeVal))); - mLivePlayViewHolder = new LivePlayKsyViewHolder(mContext, playContainer, mIntent.getIntExtra("landscape", 0)); - + mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, mIntent.getIntExtra("landscape", 0)); mLivePlayViewHolder.addToParent(); mLivePlayViewHolder.subscribeActivityLifeCycle(); mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager()); @@ -307,9 +321,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (mLiveLinkMicAnchorPresenter != null) { mLiveLinkMicAnchorPresenter.clearData(); } - if (mLiveLinkMicPkPresenter != null) { - mLiveLinkMicPkPresenter.clearData(); - } if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.clearData(); } @@ -366,9 +377,146 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } + /** + * 申请连麦但是主播还未同意的状态 + */ + public void micIngTypeOne(LiveBean bean, int liveType, int liveTypeVal) { + DialogUitl.showSimpleDialog(mContext, null, "您已申請,退出將取消語音連麥申請!", false, new DialogUitl.SimpleCallback3() { + @Override + public void onConfirmClick(Dialog dialog) { + Micing = 0; + //用户申请联麦 + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.LIAN_MAI) + .param("action", 7) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("avatar", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("uid", CommonAppConfig.getInstance().getUid()); + msg.create(); + + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(liveID, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + liveImDeletUtil.deleteMessages(message.getTargetId(), message.getMessageId()); + if (isBackPressed) { + ((LiveAudienceActivity) mContext).onBackPressed(); + } else { + EventBus.getDefault().post(new LiveRoomChangeEvent(bean, liveType, liveTypeVal)); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + errorCode.toString()); + liveImDeletUtil.deleteMessages(message.getTargetId(), message.getMessageId()); + } + }); + } + + @Override + public void onCancel() { + ((LiveAudienceActivity) mContext).setEnableScroll(true); + } + }); + + + } + + /** + * 正处于连麦中 + */ + public void micIngTypeTwo(LiveBean bean, int liveType, int liveTypeVal) { + DialogUitl.showSimpleDialog(mContext, null, "連麥中,退出將斷開語音連麥!", false, new DialogUitl.SimpleCallback3() { + @Override + public void onConfirmClick(Dialog dialog) { + ToastUtil.show("下麥中,稍等....."); + RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { + + /** + * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 + * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 + */ + @Override + public void onKicked() { + + } + + @Override + public void onSuccess() { + Log.e("ry", "下麦成功"); + // 该用户切换为观众成功,可以以观众身份进行音视频 + //退出多人房间 + HttpClient.getInstance().get("live.leaveDrLm", "live.leaveDrLm") + .params("roomid", liveID) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.e("ry", code + "退出多人"); + + } + }); + //退出rtc播放 + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "退出多人房间成功"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + Micing = 0; + } + }); + if (isBackPressed) { + ((LiveAudienceActivity) mContext).onBackPressed(); + } else { + EventBus.getDefault().post(new LiveRoomChangeEvent(bean, liveType, liveTypeVal)); + } + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", errorCode + "退出多人房间失敗"); + + } + }); + + } + + /** + * 当切换失败且不影响当前角色继续音视频时回调 + * @param errorCode 失败错误码 + */ + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "下麦失败" + errorCode); + + } + }); + } + + @Override + public void onCancel() { + ((LiveAudienceActivity) mContext).setEnableScroll(true); + } + }); + + } + + //是否处于返回键 + private boolean isBackPressed = false; + @Override public void onBackPressed() { - + isBackPressed = true; } @Override @@ -968,23 +1116,14 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.setOtherInfo(pkInfo.getString("pkuid"), pkInfo.getString("pkuimg"), pkInfo.getString("pkuname")); } - if (mLiveLinkMicPkPresenter != null) { - mLiveLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); - } else { - mLiveRyLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); - } + mLiveRyLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); } else if (!pkInfo.getString("end_pk_time").equals("0")) { LivePlayRyViewHolder.setViewUP(3); //pk排名数据 LivePKUserListBean livePKUserListBean = JSON.parseObject(pkInfo.getString("pk_top_users"), LivePKUserListBean.class); - if (mLiveLinkMicPkPresenter != null) { - mLiveLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); - } else { - mLiveRyLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); - - } + mLiveRyLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); } //多人PK } else if (pkInfo != null && pkInfo.getIntValue("drpk_status") == 1) {