|
@@ -0,0 +1,1707 @@
|
|
|
+package com.cooleshow.student.ui.live;
|
|
|
+
|
|
|
+import android.animation.ObjectAnimator;
|
|
|
+import android.content.ComponentName;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.ServiceConnection;
|
|
|
+import android.content.pm.ActivityInfo;
|
|
|
+import android.content.res.Configuration;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.IBinder;
|
|
|
+import android.os.Looper;
|
|
|
+import android.provider.Settings;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+import com.airbnb.lottie.LottieAnimationView;
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.cooleshow.base.data.net.ApiException;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
+import com.cooleshow.base.utils.AppUtils;
|
|
|
+import com.cooleshow.base.utils.SizeUtils;
|
|
|
+import com.cooleshow.base.utils.SoftKeyboardUtil;
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
+import com.cooleshow.base.utils.UiUtils;
|
|
|
+import com.cooleshow.base.utils.Utils;
|
|
|
+import com.cooleshow.base.widgets.InputBar;
|
|
|
+import com.cooleshow.student.bean.FriendInfoBean;
|
|
|
+import com.cooleshow.student.ui.live.floatPop.FloatWindowHelper;
|
|
|
+import com.cooleshow.student.ui.live.floatPop.FloatingWindowService;
|
|
|
+import com.cooleshow.student.widgets.dialog.LiveRoomCloseTipDialog;
|
|
|
+import com.cooleshow.student.widgets.dialog.OpenOverlayPermissionTipDialog;
|
|
|
+import com.cooleshow.student.widgets.helper.LiveRoomAddLikeHelper;
|
|
|
+import com.cooleshow.base.widgets.dialog.InputBarDialog;
|
|
|
+import com.cooleshow.student.R;
|
|
|
+import com.cooleshow.student.adapter.MessageAdapter;
|
|
|
+import com.cooleshow.student.bean.LiveRoomInfoBean;
|
|
|
+import com.cooleshow.student.contract.LiveRoomContract;
|
|
|
+import com.cooleshow.student.databinding.ActivityLiveroomLayoutBinding;
|
|
|
+import com.cooleshow.student.presenter.live.LiveRoomPresenter;
|
|
|
+import com.cooleshow.student.utils.helper.LiveRTCEngineInitHelper;
|
|
|
+import com.cooleshow.student.widgets.dialog.LiveRoomCloseMicTipDialog;
|
|
|
+import com.cooleshow.student.widgets.dialog.LiveRoomClosePageOnMicTipDialog;
|
|
|
+import com.cooleshow.student.widgets.dialog.LiveRoomInviteSeatMicTipDialog;
|
|
|
+import com.cooleshow.student.widgets.dialog.LiveRoomShopCarDialog;
|
|
|
+import com.cooleshow.student.widgets.helper.LiveRoomAnimatorHelper;
|
|
|
+import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
+import com.rong.io.live.LiveRoomMsgConstants;
|
|
|
+import com.rong.io.live.config.LiveConfig;
|
|
|
+import com.rong.io.live.helper.LiveEventHelper;
|
|
|
+import com.rong.io.live.message.RCUserKickOutMessage;
|
|
|
+import com.rong.io.live.message.RCUserLogOutUnusualMessage;
|
|
|
+import com.rong.io.live.message.RCUserSeatApplyMessage;
|
|
|
+import com.rong.io.live.message.RCUserSeatResponseMessage;
|
|
|
+import com.rong.io.live.message.RCUserSyncAddLikeCountMessage;
|
|
|
+import com.rong.io.live.widget.LiveRoomMicIconView;
|
|
|
+
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
+import androidx.constraintlayout.widget.ConstraintSet;
|
|
|
+import androidx.constraintlayout.widget.Group;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+import cn.rongcloud.rtc.api.RCRTCAudioRouteManager;
|
|
|
+import cn.rongcloud.rtc.api.RCRTCRemoteUser;
|
|
|
+import cn.rongcloud.rtc.api.RCRTCRoom;
|
|
|
+import cn.rongcloud.rtc.api.RCRTCVideoStream;
|
|
|
+import cn.rongcloud.rtc.api.stream.RCRTCAudioInputStream;
|
|
|
+import cn.rongcloud.rtc.api.stream.RCRTCInputStream;
|
|
|
+import cn.rongcloud.rtc.api.stream.RCRTCVideoInputStream;
|
|
|
+import cn.rongcloud.rtc.api.stream.RCRTCVideoOutputStream;
|
|
|
+import cn.rongcloud.rtc.api.stream.RCRTCVideoView;
|
|
|
+import cn.rongcloud.rtc.base.RCRTCLiveRole;
|
|
|
+import cn.rongcloud.rtc.base.RCRTCMediaType;
|
|
|
+import cn.rongcloud.rtc.base.RCRTCResourceState;
|
|
|
+import cn.rongcloud.rtc.core.RendererCommon;
|
|
|
+import de.hdodenhof.circleimageview.CircleImageView;
|
|
|
+import io.rong.imkit.IMCenter;
|
|
|
+import io.rong.imlib.IRongCoreCallback;
|
|
|
+import io.rong.imlib.IRongCoreEnum;
|
|
|
+import io.rong.imlib.RongIMClient;
|
|
|
+import io.rong.imlib.model.Message;
|
|
|
+import io.rong.imlib.model.MessageContent;
|
|
|
+import io.rong.imlib.model.UserInfo;
|
|
|
+import io.rong.message.TextMessage;
|
|
|
+
|
|
|
+import com.rong.io.live.helper.VideoViewManager;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Author by pq, Date on 2022/3/29.
|
|
|
+ */
|
|
|
+
|
|
|
+@Route(path = RouterPath.LiveCenter.ACTIVITY_LIVE_ROOM)
|
|
|
+public class LiveRoomActivity extends BaseMVPActivity<ActivityLiveroomLayoutBinding, LiveRoomPresenter> implements View.OnClickListener, LiveRoomContract.view, SoftKeyboardUtil.OnSoftInputChangedListener {
|
|
|
+ public static final int SEND_SHOW_FLOAT_WINDOW_TIME = 1000;//退到后台以后检查是否显示悬浮窗等待时长
|
|
|
+ public static final int SEND_APP_BACKGROUND_MSG = 1001;//退到后台消息
|
|
|
+ public static final int SEND_JUMP_OTHER_PAGE_MSG = 1002;//页面切换消息(购物车详情页等等)
|
|
|
+ public static final int OPEN_SHOP_CAR_DIALOG = 1003;//打开购物车
|
|
|
+ ConstraintLayout content_view;
|
|
|
+ RelativeLayout mFlLiveView;
|
|
|
+ LinearLayout ll_like;
|
|
|
+ RecyclerView mRecyclerMsg;
|
|
|
+ TextView mTvNumPeople;
|
|
|
+ ImageView iv_mic;
|
|
|
+ LiveRoomMicIconView mLlMicContainer;
|
|
|
+ TextView mTvAddLikeCount;
|
|
|
+ CircleImageView mIvAvatar;
|
|
|
+ TextView mTvRoomCreateName;
|
|
|
+ Group mGroupViews;
|
|
|
+ ConstraintLayout mViewLiveStatus;
|
|
|
+ ImageView mIvLiveStatusCenterIcon;
|
|
|
+ TextView mTvLiveStatusTipText;
|
|
|
+ ImageView mIvSwitchVideoOrientation;
|
|
|
+ ImageView mIvSwitchVideoOrientationFull;
|
|
|
+ ConstraintLayout cs_header_info;
|
|
|
+ LottieAnimationView mViewShopCarAnim;
|
|
|
+ ImageView mIvShopCar;
|
|
|
+ ImageView mIvClose;
|
|
|
+ TextView tv_input;
|
|
|
+
|
|
|
+ private LiveRoomInfoBean mRoomInfoBean;
|
|
|
+ private String mRoomId;
|
|
|
+ private MessageAdapter mMessageAdapter;
|
|
|
+ private LinearLayoutManager mLinearLayoutManager;
|
|
|
+ private boolean isEnableChat = false;//默认不禁止
|
|
|
+ private boolean isEnableMic = false;//默认不禁止
|
|
|
+ private boolean isEnableAll = false;//默认不禁止 黑名单状态
|
|
|
+ private InputBarDialog mInputBarDialog;
|
|
|
+ private int currentSeatStatus = LiveRoomMsgConstants.MIC_STATUS_NORMAL;//1未连麦,2连麦中,3连麦成功
|
|
|
+ private LiveRoomCloseMicTipDialog mRoomCloseMicTipDialog;
|
|
|
+ private LiveRoomInviteSeatMicTipDialog mInviteSeatMicTipDialog;
|
|
|
+ private int currentAddLikeCount = 0;//当前点赞数量
|
|
|
+ private boolean creatorIsCloseAudioStream = false;
|
|
|
+ private boolean creatorIsCloseVideoStream = false;
|
|
|
+ private String createRoomId = "";
|
|
|
+ private static final String ROOMID_KEY = "roomid_key";
|
|
|
+ private String mUserId;
|
|
|
+ private boolean connectStatusIsPaused = false;
|
|
|
+ private boolean isNeedRefresh = false;//是否需要重新刷新房间信息
|
|
|
+ private ServiceConnection serviceConnection;
|
|
|
+ private ObjectAnimator hideHeaderInfoAnim;
|
|
|
+ private ObjectAnimator showHeaderInfoAnim;
|
|
|
+ private Handler mHandler = new Handler(Looper.myLooper()) {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(@NonNull android.os.Message msg) {
|
|
|
+ if (msg.what == SEND_APP_BACKGROUND_MSG) {
|
|
|
+ //APP切换后台
|
|
|
+ //开启悬浮窗
|
|
|
+ if (AppUtils.isApplicationInBackground(LiveRoomActivity.this)) {
|
|
|
+ startFloatWindowService();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (msg.what == SEND_JUMP_OTHER_PAGE_MSG) {
|
|
|
+ //跳转其他页面时候
|
|
|
+ //开启悬浮窗
|
|
|
+ startFloatWindowService();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (msg.what == OPEN_SHOP_CAR_DIALOG) {
|
|
|
+ showShopCarDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ private RongIMClient.ConnectionStatusListener connectStatusListener = new RongIMClient.ConnectionStatusListener() {
|
|
|
+ @Override
|
|
|
+ public void onChanged(ConnectionStatus status) {
|
|
|
+ Log.i("pq", "LiveRoomActivity receive ConnectionStatus:" + status);
|
|
|
+ if (status == ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT
|
|
|
+ || status == ConnectionStatus.SIGN_OUT || status == ConnectionStatus.TIMEOUT) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ if (status == ConnectionStatus.CONNECTED) {
|
|
|
+ //IM连接成功
|
|
|
+ if (presenter != null && isNeedRefresh) {
|
|
|
+ connectStatusIsPaused = false;
|
|
|
+ presenter.init(mRoomId, false);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //其他状态的时候需要重新刷新房间信息
|
|
|
+ isNeedRefresh = true;
|
|
|
+ }
|
|
|
+ if (status == ConnectionStatus.SUSPEND) {
|
|
|
+ connectStatusIsPaused = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ private LiveRoomClosePageOnMicTipDialog mLiveRoomClosePageOnMicTipDialog;
|
|
|
+ private VideoViewManager mVideoViewManager;
|
|
|
+ private LiveRoomShopCarDialog mShopCarDialog;
|
|
|
+
|
|
|
+ public static void startLiveRoomActivity(Context context, String roomid) {
|
|
|
+ Intent intent = new Intent(context, LiveRoomActivity.class);
|
|
|
+ intent.putExtra(ROOMID_KEY, roomid);
|
|
|
+ context.startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView() {
|
|
|
+ content_view = viewBinding.contentView;
|
|
|
+ mFlLiveView = viewBinding.flLiveView;
|
|
|
+ ll_like = viewBinding.llLike;
|
|
|
+ mRecyclerMsg = viewBinding.recyclerMsg;
|
|
|
+ mTvNumPeople = viewBinding.tvNumPeople;
|
|
|
+ iv_mic = viewBinding.ivMic;
|
|
|
+ mLlMicContainer = viewBinding.llMicContainer;
|
|
|
+ mTvAddLikeCount = viewBinding.tvAddLikeCount;
|
|
|
+ mIvAvatar = viewBinding.ivAvatar;
|
|
|
+ mTvRoomCreateName = viewBinding.tvRoomAuthorName;
|
|
|
+ mGroupViews = viewBinding.groupViews;
|
|
|
+ mViewLiveStatus = viewBinding.viewLiveStatus.csRootLiveStatus;
|
|
|
+ mIvLiveStatusCenterIcon = viewBinding.viewLiveStatus.ivCenterIcon;
|
|
|
+ mTvLiveStatusTipText = viewBinding.viewLiveStatus.tvLiveStatusTipText;
|
|
|
+ mIvSwitchVideoOrientation = viewBinding.ivSwitchVideoOrientation;
|
|
|
+ mIvSwitchVideoOrientationFull = viewBinding.ivSwitchVideoOrientationFull;
|
|
|
+ cs_header_info = viewBinding.csHeaderInfo;
|
|
|
+ mViewShopCarAnim = viewBinding.viewShopCarAnim;
|
|
|
+ mIvShopCar = viewBinding.ivShopCar;
|
|
|
+ mIvClose = viewBinding.ivClose;
|
|
|
+ tv_input = viewBinding.tvInput;
|
|
|
+ initListener();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener() {
|
|
|
+ mIvClose.setOnClickListener(this);
|
|
|
+ mIvSwitchVideoOrientation.setOnClickListener(this);
|
|
|
+ mIvSwitchVideoOrientationFull.setOnClickListener(this);
|
|
|
+ tv_input.setOnClickListener(this);
|
|
|
+ iv_mic.setOnClickListener(this);
|
|
|
+ viewBinding.iconAddLike.setOnClickListener(this);
|
|
|
+ mViewLiveStatus.setOnClickListener(this);
|
|
|
+ mViewShopCarAnim.setOnClickListener(this);
|
|
|
+ mFlLiveView.setOnClickListener(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected ActivityLiveroomLayoutBinding getLayoutView() {
|
|
|
+ return ActivityLiveroomLayoutBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+ super.initData();
|
|
|
+ mRoomId = getIntent().getStringExtra(ROOMID_KEY);
|
|
|
+ if (TextUtils.isEmpty(mRoomId)) {
|
|
|
+ ToastUtil.getInstance().show(this, "房间id不可为空");
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String userToken = UserHelper.getUserToken();
|
|
|
+ if (TextUtils.isEmpty(userToken)) {
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (LiveConfig.isNeedReInitRTC) {
|
|
|
+ //检查是否需要重新初始化RTC
|
|
|
+ LiveRTCEngineInitHelper.initRTC();
|
|
|
+ }
|
|
|
+ // 初始化音频路由管理类
|
|
|
+ RCRTCAudioRouteManager.getInstance().init(Utils.getApp());
|
|
|
+ mFlLiveView.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ checkVideoViewManager();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mUserId = UserHelper.getUserId();
|
|
|
+ mMessageAdapter = new MessageAdapter(this);
|
|
|
+ mLinearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
|
|
|
+ mRecyclerMsg.setLayoutManager(mLinearLayoutManager);
|
|
|
+ mRecyclerMsg.setAdapter(mMessageAdapter);
|
|
|
+ IMCenter.getInstance().addConnectionStatusListener(connectStatusListener);
|
|
|
+ SoftKeyboardUtil.registerSoftInputChangedListener(getWindow(), this);
|
|
|
+ prepareInitRoom();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void prepareInitRoom() {
|
|
|
+ //根据融云的IM连接状态判断是否需要获取房间信息
|
|
|
+ RongIMClient.ConnectionStatusListener.ConnectionStatus currentConnectionStatus = RongIMClient.getInstance().getCurrentConnectionStatus();
|
|
|
+ if (currentConnectionStatus == RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTED) {
|
|
|
+ isNeedRefresh = false;
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.init(mRoomId, false);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //如果IM未连接,等待connectStatusListener回调
|
|
|
+ isNeedRefresh = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void onClick(View view) {
|
|
|
+ int id = view.getId();
|
|
|
+ if (id == R.id.view_live_status) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (id == R.id.iv_close) {
|
|
|
+ if (currentSeatStatus != LiveRoomMsgConstants.MIC_STATUS_NORMAL) {
|
|
|
+ showPageCloseOnMicTipDialog();
|
|
|
+ } else {
|
|
|
+ close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (id == R.id.iv_switch_video_orientation) {
|
|
|
+ //切换横竖屏
|
|
|
+ if (mShopCarDialog != null && mShopCarDialog.isShowing()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ changeOrientation();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.iv_switch_video_orientation_full) {
|
|
|
+ //横屏切换竖屏
|
|
|
+ changeOrientation();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (id == R.id.tv_input) {
|
|
|
+ //底部输入框
|
|
|
+ showInputDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (id == R.id.iv_mic) {
|
|
|
+ //连麦
|
|
|
+ if (checkMicMode()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (connectStatusIsPaused) {
|
|
|
+ //连接状态异常,暂停连麦
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_NORMAL) {
|
|
|
+ //未连麦状态 申请连麦
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_SEAT_APPLY);
|
|
|
+ }
|
|
|
+ updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_CONNECTING);
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, getString(R.string.seat_apply_str));
|
|
|
+ } else {
|
|
|
+ //取消连麦
|
|
|
+ showCloseMicTipDialog();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.icon_add_like) {
|
|
|
+ if (connectStatusIsPaused) {
|
|
|
+ //连接状态异常,暂停连麦
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //点赞
|
|
|
+ LiveRoomAddLikeHelper.getInstance().handleClick(new LiveRoomAddLikeHelper.OnAddLikeResultCallBack() {
|
|
|
+ @Override
|
|
|
+ public void onResult(int count) {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.setAddLikeCount(count);
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_ADD_LIKE_COUNT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ LiveRoomAnimatorHelper.getInstance().startAddLikeAnimation(LiveRoomActivity.this, content_view);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.view_shop_car_anim) {
|
|
|
+ //购物车
|
|
|
+ if (isFullScreen()) {
|
|
|
+ changeOrientation();
|
|
|
+ android.os.Message message = android.os.Message.obtain();
|
|
|
+ message.what = OPEN_SHOP_CAR_DIALOG;
|
|
|
+ mHandler.sendMessageDelayed(message, 500);
|
|
|
+ } else {
|
|
|
+ showShopCarDialog();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.fl_live_view) {
|
|
|
+ //点击隐藏头部信息
|
|
|
+ if (isFullScreen()) {
|
|
|
+ //全屏模式下
|
|
|
+ handleHeaderAnim();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void handleHeaderAnim() {
|
|
|
+ float animOffset = cs_header_info.getTranslationY();
|
|
|
+ if (animOffset == 0) {
|
|
|
+ //隐藏头部信息
|
|
|
+ int bottom = cs_header_info.getBottom();
|
|
|
+ if (hideHeaderInfoAnim == null) {
|
|
|
+ hideHeaderInfoAnim = ObjectAnimator.ofFloat(cs_header_info, "translationY", 0, -bottom);
|
|
|
+ hideHeaderInfoAnim.setDuration(500);
|
|
|
+ }
|
|
|
+ hideHeaderInfoAnim.start();
|
|
|
+ } else {
|
|
|
+ //显示头部信息
|
|
|
+ if (showHeaderInfoAnim == null) {
|
|
|
+ showHeaderInfoAnim = ObjectAnimator.ofFloat(cs_header_info, "translationY", animOffset, 0);
|
|
|
+ showHeaderInfoAnim.setDuration(500);
|
|
|
+ }
|
|
|
+ showHeaderInfoAnim.start();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showShopCarDialog() {
|
|
|
+ if (mShopCarDialog == null) {
|
|
|
+ mShopCarDialog = new LiveRoomShopCarDialog(this);
|
|
|
+ mShopCarDialog.setOnEventListener(new LiveRoomShopCarDialog.OnEventListener() {
|
|
|
+ @Override
|
|
|
+ public void onOpenDetail(String url) {
|
|
|
+ mShopCarDialog.dismiss();
|
|
|
+ //发送XXX正在抢购消息
|
|
|
+// presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_ON_SNAP_UP);
|
|
|
+// sendShowFloatWindowAction(SEND_JUMP_OTHER_PAGE_MSG);
|
|
|
+// ARouter.getInstance()
|
|
|
+// .build(ARouterConstace.ACTIVITY_HTML)
|
|
|
+// .withString(ARouterConstace.URL, url)
|
|
|
+// .withString(ARouterConstace.TITLE, "商品详情")
|
|
|
+// .navigation();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!mShopCarDialog.isShowing()) {
|
|
|
+ mShopCarDialog.show();
|
|
|
+ }
|
|
|
+ mShopCarDialog.setRoomId(mRoomId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showPageCloseOnMicTipDialog() {
|
|
|
+ if (mLiveRoomClosePageOnMicTipDialog == null) {
|
|
|
+ mLiveRoomClosePageOnMicTipDialog = new LiveRoomClosePageOnMicTipDialog(this);
|
|
|
+ mLiveRoomClosePageOnMicTipDialog.setConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ close();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!mLiveRoomClosePageOnMicTipDialog.isShowing()) {
|
|
|
+ mLiveRoomClosePageOnMicTipDialog.show();
|
|
|
+ }
|
|
|
+ mLiveRoomClosePageOnMicTipDialog.setTitle("提示");
|
|
|
+ mLiveRoomClosePageOnMicTipDialog.setContent("连麦中,是否退出房间?");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showCloseMicTipDialog() {
|
|
|
+ if (mRoomCloseMicTipDialog == null) {
|
|
|
+ mRoomCloseMicTipDialog = new LiveRoomCloseMicTipDialog(this);
|
|
|
+ mRoomCloseMicTipDialog.setConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ handleCloseMicEvent();
|
|
|
+ mRoomCloseMicTipDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!mRoomCloseMicTipDialog.isShowing()) {
|
|
|
+ mRoomCloseMicTipDialog.show();
|
|
|
+ }
|
|
|
+ mRoomCloseMicTipDialog.setContent(getString(currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECTING ? R.string.cancel_seat_on_connecting : R.string.cancel_seat_on_connected));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取消连麦
|
|
|
+ */
|
|
|
+ private void handleCloseMicEvent() {
|
|
|
+ if (currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECTING) {
|
|
|
+ //连接中取消连接
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_CANCEL_SEAT_APPLY);
|
|
|
+ updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_NORMAL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECT_SUCCESS) {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.exitMic();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateMicIcon(int micStatus) {
|
|
|
+ //主线程更新
|
|
|
+ iv_mic.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ currentSeatStatus = micStatus;
|
|
|
+ if (micStatus == LiveRoomMsgConstants.MIC_STATUS_NORMAL) {
|
|
|
+ iv_mic.setImageResource(R.drawable.icon_mic_unconnect);
|
|
|
+ }
|
|
|
+ if (micStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECTING) {
|
|
|
+ iv_mic.setImageResource(R.drawable.icon_mic_connecting);
|
|
|
+ }
|
|
|
+ if (micStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECT_SUCCESS) {
|
|
|
+ iv_mic.setImageResource(R.drawable.icon_mic_conected);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showInputDialog() {
|
|
|
+ if (checkChatMode()) return;
|
|
|
+ if (mInputBarDialog == null) {
|
|
|
+ mInputBarDialog = new InputBarDialog(LiveRoomActivity.this, new InputBar.InputBarListener() {
|
|
|
+ @Override
|
|
|
+ public void onClickSend(String message) {
|
|
|
+ //发送消息
|
|
|
+ if (TextUtils.isEmpty(message)) {
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, "消息不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ sendTextMessage(message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onClickEmoji() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mInputBarDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
|
|
+ @Override
|
|
|
+ public void onShow(DialogInterface dialog) {
|
|
|
+ if (mInputBarDialog != null) {
|
|
|
+ mInputBarDialog.showInput();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!mInputBarDialog.isShowing()) {
|
|
|
+ mInputBarDialog.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendTextMessage(String message) {
|
|
|
+ if (checkChatMode()) {
|
|
|
+ //禁止聊天模式
|
|
|
+ if (mInputBarDialog != null) {
|
|
|
+ mInputBarDialog.dismiss();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (presenter != null) {
|
|
|
+ TextMessage textMessage = TextMessage.obtain(message);
|
|
|
+ UserInfo userInfo = new UserInfo(mUserId, UserHelper.getUserName(), null);
|
|
|
+ textMessage.setUserInfo(userInfo);
|
|
|
+ presenter.sendMessage(textMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeOrientation() {
|
|
|
+ int currentOrientation = getCurrentOrientation();
|
|
|
+ boolean isNeedFullScreen = currentOrientation != Configuration.ORIENTATION_LANDSCAPE;
|
|
|
+ if (isNeedFullScreen) {
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
|
+ } else {
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
|
|
+ super.onConfigurationChanged(newConfig);
|
|
|
+ //改变videoView容器布局尺寸
|
|
|
+ resetVideoContainer(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void close() {
|
|
|
+ //断开连接,结束页面
|
|
|
+ onBackPressed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected LiveRoomPresenter createPresenter() {
|
|
|
+ return new LiveRoomPresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取房间信息成功
|
|
|
+ *
|
|
|
+ * @param roomInfoBean
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getRoomInfoSuccess(LiveRoomInfoBean roomInfoBean) {
|
|
|
+ if (roomInfoBean == null || isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean isPc = !TextUtils.equals("pc", roomInfoBean.os);
|
|
|
+ resetVideoContainer(isPc);
|
|
|
+ mRoomInfoBean = roomInfoBean;
|
|
|
+ currentAddLikeCount = roomInfoBean.likeNum;
|
|
|
+ if (!TextUtils.isEmpty(roomInfoBean.roomConfig)) {
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = new JSONObject(roomInfoBean.roomConfig);
|
|
|
+ int chatCtrlMode = jsonObject.optInt("whether_chat", 0);
|
|
|
+ int micCtrlMode = jsonObject.optInt("whether_mic", 0);
|
|
|
+ isEnableChat = chatCtrlMode == 1;
|
|
|
+ isEnableMic = micCtrlMode == 1;
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //黑名单模式
|
|
|
+ isEnableAll = roomInfoBean.blacklistFlag == 1;//1是黑名单 0否
|
|
|
+ updateInputTip();
|
|
|
+ updateAddLikeCountView();
|
|
|
+
|
|
|
+ if (mTvNumPeople != null) {
|
|
|
+ int peopleCount = roomInfoBean.lookNum + 1;//加上自己
|
|
|
+ mTvNumPeople.setText(peopleCount + "人");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mIvAvatar != null) {
|
|
|
+ //创建人头像
|
|
|
+ Glide.with(LiveRoomActivity.this).load(roomInfoBean.speakerPic).placeholder(R.drawable.icon_teacher_default_head).error(R.drawable.icon_teacher_default_head).into(mIvAvatar);
|
|
|
+ }
|
|
|
+ if (mTvRoomCreateName != null) {
|
|
|
+ //创建人昵称
|
|
|
+ mTvRoomCreateName.setText(roomInfoBean.speakerName);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mMessageAdapter != null) {
|
|
|
+ mMessageAdapter.setRoomAuthorId(roomInfoBean.speakerId);
|
|
|
+ }
|
|
|
+ if (presenter != null) {
|
|
|
+ //加入聊天室
|
|
|
+ //加入直播间
|
|
|
+ showLoading();
|
|
|
+ LiveEventHelper.getInstance().register(mRoomInfoBean.roomUid);
|
|
|
+ presenter.leaveRoom(mRoomInfoBean.roomUid, false, true);
|
|
|
+ presenter.joinChartRoom(mRoomInfoBean.roomUid, new IRongCoreCallback.OperationCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess() {
|
|
|
+ Log.i("pq", "加入聊天房间成功");
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_JOIN_ROOM);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
|
|
|
+ Log.i("pq", "加入聊天房间fail:" + coreErrorCode);
|
|
|
+ Toast.makeText(LiveRoomActivity.this, "加入聊天房间fail:" + coreErrorCode, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateInputTip() {
|
|
|
+ if (tv_input == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isEnableAll) {
|
|
|
+ tv_input.setText(getString(R.string.unable_input_tip_str));
|
|
|
+ } else {
|
|
|
+ tv_input.setText(getString(R.string.live_input_tips_str));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getRoomInfoError(Throwable t) {
|
|
|
+ if (isDestroyed() || isFinishing()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (t instanceof ApiException) {
|
|
|
+ ApiException apiException = (ApiException) t;
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, apiException.getErrmsg());
|
|
|
+ }
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void resetVideoContainer(boolean isFullScreen) {
|
|
|
+ if (mVideoViewManager != null) {
|
|
|
+ mVideoViewManager.setIsNeedFillScreen(isFullScreen);
|
|
|
+ }
|
|
|
+ if (isFullScreen) {
|
|
|
+ mGroupViews.setVisibility(View.GONE);
|
|
|
+ mIvClose.setVisibility(View.GONE);
|
|
|
+ mIvSwitchVideoOrientation.setVisibility(View.GONE);
|
|
|
+ mIvSwitchVideoOrientationFull.setVisibility(View.VISIBLE);
|
|
|
+ ConstraintSet set = new ConstraintSet();
|
|
|
+ set.clone(content_view);
|
|
|
+ set.clear(mFlLiveView.getId());
|
|
|
+ set.connect(mFlLiveView.getId(), ConstraintSet.TOP, content_view.getId(), ConstraintSet.TOP, 0);
|
|
|
+ set.connect(mFlLiveView.getId(), ConstraintSet.LEFT, content_view.getId(), ConstraintSet.LEFT, 0);
|
|
|
+ set.connect(mFlLiveView.getId(), ConstraintSet.RIGHT, content_view.getId(), ConstraintSet.RIGHT, 0);
|
|
|
+ set.connect(mFlLiveView.getId(), ConstraintSet.BOTTOM, content_view.getId(), ConstraintSet.BOTTOM, 0);
|
|
|
+ set.applyTo(content_view);
|
|
|
+ } else {
|
|
|
+ //pc端直播,控制居中显示,以及videoview容器的宽高
|
|
|
+ if (cs_header_info.getTranslationY() != 0) {
|
|
|
+ //还原显示头部信息
|
|
|
+ handleHeaderAnim();
|
|
|
+ }
|
|
|
+ mGroupViews.setVisibility(View.VISIBLE);
|
|
|
+ mIvClose.setVisibility(View.VISIBLE);
|
|
|
+ mIvSwitchVideoOrientation.setVisibility(View.VISIBLE);
|
|
|
+ mIvSwitchVideoOrientationFull.setVisibility(View.GONE);
|
|
|
+ ConstraintSet set = new ConstraintSet();
|
|
|
+ set.clone(content_view);
|
|
|
+ set.clear(mFlLiveView.getId());
|
|
|
+ set.connect(mFlLiveView.getId(), ConstraintSet.TOP, cs_header_info.getId(), ConstraintSet.BOTTOM, SizeUtils.dp2px(121));
|
|
|
+ set.connect(mFlLiveView.getId(), ConstraintSet.LEFT, content_view.getId(), ConstraintSet.LEFT, 0);
|
|
|
+ set.connect(mFlLiveView.getId(), ConstraintSet.RIGHT, content_view.getId(), ConstraintSet.RIGHT, 0);
|
|
|
+ int maxHeightAtRatio16_9 = UiUtils.getMaxHeightAtRatio16_9(LiveRoomActivity.this);
|
|
|
+ set.constrainHeight(mFlLiveView.getId(), maxHeightAtRatio16_9);
|
|
|
+ set.applyTo(content_view);
|
|
|
+ }
|
|
|
+ changVideoViewSize();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void changVideoViewSize() {
|
|
|
+ int childCount = mFlLiveView.getChildCount();
|
|
|
+ if (childCount == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ View childAt = mFlLiveView.getChildAt(0);
|
|
|
+ if (childAt instanceof RCRTCVideoView) {
|
|
|
+ RCRTCVideoView videoView = (RCRTCVideoView) childAt;
|
|
|
+// mFlLiveView.removeView(videoView);
|
|
|
+// mFlLiveView.addView(videoView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showFinishView() {
|
|
|
+ //显示结束view
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Log.i("pq", "加入直播间异常");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 主讲人的音频状态
|
|
|
+ *
|
|
|
+ * @param isCloseAudioStream
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void syncAudioStatus(boolean isCloseAudioStream) {
|
|
|
+ this.creatorIsCloseAudioStream = isCloseAudioStream;
|
|
|
+ if (creatorIsCloseAudioStream && creatorIsCloseVideoStream) {
|
|
|
+ //如果是关闭音频,同时判断下视频的状态
|
|
|
+ showRestView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showRestView() {
|
|
|
+ showLiveStatusView(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showCloseVideoView() {
|
|
|
+ //关闭了视频
|
|
|
+ creatorIsCloseVideoStream = true;
|
|
|
+ if (creatorIsCloseAudioStream) {
|
|
|
+ //同时音频也关闭了
|
|
|
+ showRestView();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ showLiveStatusView(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showLiveStatusView(boolean isRestView) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mViewLiveStatus == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //显示视频画面已经关闭页面
|
|
|
+ mViewLiveStatus.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ hideLoading();
|
|
|
+ mViewLiveStatus.setVisibility(View.VISIBLE);
|
|
|
+ if (isRestView) {
|
|
|
+ mIvLiveStatusCenterIcon.setImageResource(R.drawable.icon_live_room_rest_bg);
|
|
|
+ mTvLiveStatusTipText.setText("休息一下马上回来!!");
|
|
|
+ } else {
|
|
|
+ mIvLiveStatusCenterIcon.setImageResource(R.drawable.icon_live_room_close_video);
|
|
|
+ mTvLiveStatusTipText.setText("主持人已关闭画面!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showEmptyStatusView() {
|
|
|
+ //显示老师不在线view
|
|
|
+ showRestView();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getContentView() {
|
|
|
+ return content_view;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addMessageList(List<MessageContent> messageContents, boolean isReset) {
|
|
|
+ //添加多条消息至页面
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addMessageContent(Message message, boolean isReset) {
|
|
|
+ //添加单条消息至页面
|
|
|
+ Log.i("pq", "收到需要显示msg:" + message);
|
|
|
+ //只处理直播间消息,以及本直播间消息
|
|
|
+ if (mMessageAdapter != null) {
|
|
|
+ mMessageAdapter.addMessage(message);
|
|
|
+ if (mRecyclerMsg != null && mLinearLayoutManager != null) {
|
|
|
+ mRecyclerMsg.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mRecyclerMsg.scrollToPosition(mMessageAdapter.getItemCount() - 1);
|
|
|
+// mRecyclerMsg.scrollToPosition(mMessageAdapter.getItemCount() - 1);
|
|
|
+// mLinearLayoutManager.scrollToPositionWithOffset(mMessageAdapter.getItemCount() - 1, 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateAddLikeCountView() {
|
|
|
+ if (mTvAddLikeCount != null) {
|
|
|
+ mTvAddLikeCount.setText(getString(R.string.live_room_add_like_count_str, currentAddLikeCount));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 控制聊天模式
|
|
|
+ *
|
|
|
+ * @param isEnableChat
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void switchChatMode(boolean isEnableChat) {
|
|
|
+ //控制聊天模式
|
|
|
+ Log.i("pq", "聊天禁止:" + isEnableChat);
|
|
|
+ this.isEnableChat = isEnableChat;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void liveRoomOffline() {
|
|
|
+ //关闭直播间
|
|
|
+ ToastUtil.getInstance().show(this, "直播已结束");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void liveGoodsChange(String jsonStr) {
|
|
|
+ //直播间商品发生变化
|
|
|
+ if (isDestroyed() || isFinishing()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mShopCarDialog != null) {
|
|
|
+ mShopCarDialog.changeGoods(jsonStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param rcUserSeatResponseMessage
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void seatResponse(RCUserSeatResponseMessage rcUserSeatResponseMessage) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (rcUserSeatResponseMessage == null || !isOwn(rcUserSeatResponseMessage.getAudienceId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (rcUserSeatResponseMessage != null) {
|
|
|
+ int type = rcUserSeatResponseMessage.getType();
|
|
|
+ if (type == LiveRoomMsgConstants.MIC_RESPONSE_AGREE) {
|
|
|
+ //主播同意
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.joinMic();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (type == LiveRoomMsgConstants.MIC_RESPONSE_DISAGREE) {
|
|
|
+ //主播拒绝
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, getString(R.string.create_refuse_seat_tip));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSwitchRole(String userId, RCRTCLiveRole role) {
|
|
|
+ Log.i("pq", "onSwitchRole:" + userId);
|
|
|
+ if (role.getType() == RCRTCLiveRole.AUDIENCE.getType()) {
|
|
|
+ //主播身份切换观众身份 下麦
|
|
|
+ notifyMicContainerDel(userId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserJoinRoom(RCRTCRemoteUser rcrtcRemoteUser) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Log.i("pq", "onUserJoinRoom:" + rcrtcRemoteUser.getUserId());
|
|
|
+ if (TextUtils.equals(rcrtcRemoteUser.getUserId(), createRoomId)) {
|
|
|
+ createRoomId = "";//重置一下createRoomId,防止创建者退出又进入,全局控制变量未刷新
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserLeftRoomMic(RCRTCRemoteUser rcrtcRemoteUser) {
|
|
|
+ Log.i("pq", "onUserLeftRoomMic:" + rcrtcRemoteUser.getUserId());
|
|
|
+ if (rcrtcRemoteUser != null) {
|
|
|
+ notifyMicContainerDel(rcrtcRemoteUser.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserOfflineRoomMic(RCRTCRemoteUser rcrtcRemoteUser) {
|
|
|
+ Log.i("pq", "onUserOfflineRoomMic:" + rcrtcRemoteUser.getUserId());
|
|
|
+ if (rcrtcRemoteUser != null) {
|
|
|
+ notifyMicContainerDel(rcrtcRemoteUser.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncMemberCount(String count) {
|
|
|
+ //同步成员数量
|
|
|
+ Log.i("pq", "syncMemberCount" + count);
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mTvNumPeople != null) {
|
|
|
+ mTvNumPeople.setText(count + "人");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserKickOutMsg(RCUserKickOutMessage userKickOutMessage) {
|
|
|
+ //用户被踢出消息
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (userKickOutMessage == null || !isOwn(userKickOutMessage.getTargetId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String targetId = userKickOutMessage.getTargetId();
|
|
|
+ Log.i("pq", "receive kickOut msg targetId:" + targetId);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 控制连麦模式
|
|
|
+ *
|
|
|
+ * @param isEnableMic
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void changeMicControlMode(boolean isEnableMic) {
|
|
|
+ //禁止连麦模式
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Log.i("pq", "receive mic mode control msg 禁麦模式:" + isEnableMic);
|
|
|
+ this.isEnableMic = isEnableMic;
|
|
|
+ if (isEnableMic) {
|
|
|
+ handleCloseMicEvent();
|
|
|
+ if (mLlMicContainer != null) {
|
|
|
+ mLlMicContainer.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mLlMicContainer.delAll();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void refresh() {
|
|
|
+ List<RCRTCVideoOutputStream> outputStreams = new ArrayList<>();
|
|
|
+ List<RCRTCVideoInputStream> input = new ArrayList<>();
|
|
|
+ List<RCRTCAudioInputStream> audioinputstream = new ArrayList<>();
|
|
|
+ presenter.getVideoStream(outputStreams, input, audioinputstream);
|
|
|
+ updateVideoView(outputStreams, input, audioinputstream);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void subscribeAVStreamSuccess(List<RCRTCInputStream> inputStreams) {
|
|
|
+ if (inputStreams != null) {
|
|
|
+ refresh();
|
|
|
+ } else {
|
|
|
+ showEmptyStatusView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSubscribeFailed() {
|
|
|
+ //订阅流失败
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setRoomData(LiveRoomInfoBean roomInfoBean) {
|
|
|
+ //保存房间信息
|
|
|
+ if (presenter != null) {
|
|
|
+ //通知加入房间成功
|
|
|
+ presenter.notifyJoinRoomAction(mRoomId, mUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void notifyMicContainerAdd(String userId, String userName) {
|
|
|
+ mLlMicContainer.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ String lastName = userName;
|
|
|
+ UserInfo targetUser = mLlMicContainer.getUserInfoIfExist(userId);
|
|
|
+ if (targetUser != null && !TextUtils.equals(targetUser.getName(), LiveRoomMicIconView.DEFAULT_NICK)) {
|
|
|
+ lastName = targetUser.getName();
|
|
|
+ } else {
|
|
|
+ if (TextUtils.isEmpty(lastName)) {
|
|
|
+ //如果昵称为空,查询昵称
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.getUserInfoByUserId(userId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mLlMicContainer.addMicUser(new UserInfo(userId, lastName, null));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void notifyMicContainerDel(String userId) {
|
|
|
+ mLlMicContainer.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mLlMicContainer.deleteMicUser(new UserInfo(userId, "", null));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 连麦成功-身份切换主播成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onSeatMicSuccess() {
|
|
|
+ updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_CONNECT_SUCCESS);
|
|
|
+ notifyMicContainerAdd(mUserId, UserHelper.getUserName());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 连麦失败
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onSeatMicFail() {
|
|
|
+ updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_NORMAL);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * \
|
|
|
+ * 退出连麦成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onExitSeatMicSuccess() {
|
|
|
+ updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_NORMAL);
|
|
|
+ notifyMicContainerDel(mUserId);
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_DOWN_SEAT_MIC);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 主播邀请上麦
|
|
|
+ *
|
|
|
+ * @param seatApplyMessage
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onInviteSeatMic(RCUserSeatApplyMessage seatApplyMessage) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (seatApplyMessage == null || !isOwn(seatApplyMessage.getAudienceId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (seatApplyMessage.getType() == LiveRoomMsgConstants.MIC_ACTION_INVITE_SEAT_BY_CREATE) {
|
|
|
+ //主讲人邀请观众上麦
|
|
|
+ showInviteSeatDialog();
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+ if (seatApplyMessage.getType() == LiveRoomMsgConstants.MIC_ACTION_CANCEL_INVITE_SEAT_BY_CREATE) {
|
|
|
+ //主讲人取消邀请观众上麦
|
|
|
+ if (mInviteSeatMicTipDialog != null) {
|
|
|
+ mInviteSeatMicTipDialog.dismiss();
|
|
|
+ }
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, getString(R.string.create_recall_seat_invite_tip));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (seatApplyMessage.getType() == LiveRoomMsgConstants.MIC_ACTION_CANCEL_SEAT_BY_CREATE) {
|
|
|
+ //主讲人讲观众抱下麦
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, getString(R.string.down_mic_by_create_tip));
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.exitMic();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserUnusualLogout(RCUserLogOutUnusualMessage loginOutUnusualMessage) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (loginOutUnusualMessage == null || !isOwn(loginOutUnusualMessage.getUserId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Log.i("pq", "unusual logout");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 暂停直播,进行下麦处理
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onLivePause() {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ToastUtil.getInstance().show(this, getString(R.string.live_is_pause_str));
|
|
|
+ handleCloseMicEvent();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 点赞数量同步
|
|
|
+ *
|
|
|
+ * @param addLikeMessage
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onAddLikeMessage(Message message, RCUserSyncAddLikeCountMessage addLikeMessage) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.equals(message.getSenderUserId(), mUserId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (addLikeMessage != null) {
|
|
|
+ if (mTvAddLikeCount != null && addLikeMessage != null) {
|
|
|
+// int counts = addLikeMessage.getCounts();
|
|
|
+// currentAddLikeCount += counts;
|
|
|
+ currentAddLikeCount = addLikeMessage.getCount();
|
|
|
+ updateAddLikeCountView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取上麦用户信息成功
|
|
|
+ *
|
|
|
+ * @param friendInfoBean
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getFriendInfoSuccess(FriendInfoBean friendInfoBean) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mLlMicContainer != null) {
|
|
|
+ mLlMicContainer.addMicUser(new UserInfo(friendInfoBean.friendId, friendInfoBean.friendNickname, null));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPublishSuccess() {
|
|
|
+ refresh();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 黑名单状态切换
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ * @param isAddBlack
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void changeBlackUserStatus(String userId, boolean isAddBlack) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isOwn(userId)) {
|
|
|
+ isEnableAll = isAddBlack;
|
|
|
+ if (isEnableAll) {
|
|
|
+ //取消连麦
|
|
|
+ if (currentSeatStatus != LiveRoomMsgConstants.MIC_STATUS_NORMAL) {
|
|
|
+ handleCloseMicEvent();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updateInputTip();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isOwn(String targetUserId) {
|
|
|
+ return TextUtils.equals(mUserId, targetUserId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showInviteSeatDialog() {
|
|
|
+ if (mInviteSeatMicTipDialog == null) {
|
|
|
+ mInviteSeatMicTipDialog = new LiveRoomInviteSeatMicTipDialog(this);
|
|
|
+ mInviteSeatMicTipDialog.setViewClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (v.getId() == R.id.tv_sure) {
|
|
|
+ //被邀请连麦->同意连麦
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_CANCEL_SEAT_AGREE_RESPONSE);
|
|
|
+ presenter.joinMic();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (v.getId() == R.id.tv_cancel) {
|
|
|
+ //被邀请连麦->拒绝连麦
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_CANCEL_SEAT_DISAGREE_RESPONSE);
|
|
|
+ }
|
|
|
+ //重置一下连麦状态
|
|
|
+ handleCloseMicEvent();
|
|
|
+ }
|
|
|
+ mInviteSeatMicTipDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!mInviteSeatMicTipDialog.isShowing()) {
|
|
|
+ mInviteSeatMicTipDialog.show();
|
|
|
+ }
|
|
|
+ String defaultNick = "主讲人";
|
|
|
+ if (mRoomInfoBean != null && !TextUtils.isEmpty(mRoomInfoBean.speakerName)) {
|
|
|
+ defaultNick = mRoomInfoBean.speakerName;
|
|
|
+ }
|
|
|
+ mInviteSeatMicTipDialog.setContent(defaultNick);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void updateVideoView(List<RCRTCVideoOutputStream> outputStreams, List<RCRTCVideoInputStream> inputStreams, List<RCRTCAudioInputStream> audioInputStreams) {
|
|
|
+ mFlLiveView.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ ArrayList<RCRTCVideoStream> videoStreams = new ArrayList<RCRTCVideoStream>();
|
|
|
+ videoStreams.addAll(outputStreams);
|
|
|
+ videoStreams.addAll(inputStreams);
|
|
|
+ ArrayList<RCRTCVideoView> list = new ArrayList<>();
|
|
|
+ ArrayList<String> otherAudioUserIds = new ArrayList<>();
|
|
|
+ boolean isNormalCreateAudioStatus = true;
|
|
|
+
|
|
|
+ //视频流
|
|
|
+ for (int i = 0; i < videoStreams.size(); i++) {
|
|
|
+ RCRTCVideoStream rcrtcVideoStream = videoStreams.get(i);
|
|
|
+ RCRTCVideoView rongRTCVideoView = new RCRTCVideoView(LiveRoomActivity.this);
|
|
|
+ rcrtcVideoStream.setVideoView(rongRTCVideoView);
|
|
|
+ list.add(rongRTCVideoView);
|
|
|
+ }
|
|
|
+
|
|
|
+ //音频流
|
|
|
+ for (int i = 0; i < audioInputStreams.size(); i++) {
|
|
|
+ RCRTCAudioInputStream audioInputStream = audioInputStreams.get(i);
|
|
|
+ if (audioInputStream.getMediaType() == RCRTCMediaType.AUDIO) {
|
|
|
+ //音频流判断显示上麦用户
|
|
|
+ String userId = audioInputStream.getUserId();
|
|
|
+ if (TextUtils.equals(mUserId, userId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (mRoomInfoBean != null) {
|
|
|
+ if (!TextUtils.equals(mRoomInfoBean.speakerId, userId)) {
|
|
|
+ otherAudioUserIds.add(userId);
|
|
|
+ } else {
|
|
|
+ //主播的音频流
|
|
|
+ RCRTCResourceState resourceState = audioInputStream.getResourceState();
|
|
|
+ isNormalCreateAudioStatus = resourceState == RCRTCResourceState.NORMAL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (otherAudioUserIds.size() != 0) {
|
|
|
+ mLlMicContainer.delAllExcludeOwn();
|
|
|
+ for (int i = 0; i < otherAudioUserIds.size(); i++) {
|
|
|
+ String onMicUserId = otherAudioUserIds.get(i);
|
|
|
+ notifyMicContainerAdd(onMicUserId, "");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mLlMicContainer.delAllExcludeOwn();
|
|
|
+ }
|
|
|
+ if (list.size() != 0) {
|
|
|
+ creatorIsCloseVideoStream = false;
|
|
|
+ mViewLiveStatus.setVisibility(View.GONE);
|
|
|
+ checkVideoViewManager();
|
|
|
+ mVideoViewManager.update(list, 0, true);
|
|
|
+ } else {
|
|
|
+ creatorIsCloseVideoStream = true;
|
|
|
+ if (isNormalCreateAudioStatus) {
|
|
|
+ showCloseVideoView();
|
|
|
+ } else {
|
|
|
+ //主播关闭了视频流,同时音频流的状态也不是normal状态时
|
|
|
+ showRestView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查VideoViewManager是否未null;
|
|
|
+ */
|
|
|
+ private void checkVideoViewManager() {
|
|
|
+ if (mVideoViewManager == null) {
|
|
|
+ mVideoViewManager = new VideoViewManager(mFlLiveView, mFlLiveView.getWidth(), mFlLiveView.getHeight());
|
|
|
+ mVideoViewManager.setRetryClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (presenter != null) {
|
|
|
+ //重新订阅房间的流信息
|
|
|
+ presenter.subscribeAVStream();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean findMainScreenStreams(String streamUserId, String streamTag) {
|
|
|
+ if (TextUtils.equals("screenshare", streamTag)) {
|
|
|
+ //屏幕共享流
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (TextUtils.equals(mRoomInfoBean.speakerId, streamUserId)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当远端或本端视频流发生变化时全量更新ui
|
|
|
+ */
|
|
|
+ void updateVideoView(List<RCRTCInputStream> inputStreams) {
|
|
|
+ mFlLiveView.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ hideLoading();
|
|
|
+ ArrayList<RCRTCVideoView> list = new ArrayList<>();
|
|
|
+ ArrayList<String> otherAudioUserIds = new ArrayList<>();
|
|
|
+ boolean isNormalCreateAudioStatus = true;
|
|
|
+ if (null != inputStreams) {
|
|
|
+ for (RCRTCInputStream i : inputStreams) {
|
|
|
+ if (i.getMediaType() == RCRTCMediaType.VIDEO) {
|
|
|
+// if (mRoomInfoBean != null) {
|
|
|
+// if (TextUtils.equals(createRoomId, i.getUserId())) {
|
|
|
+// Log.i("pq","已存在相同的流,无须重复渲染");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// }
|
|
|
+ RCRTCVideoInputStream j = (RCRTCVideoInputStream) i;
|
|
|
+ RCRTCVideoView rongRTCVideoView = new RCRTCVideoView(LiveRoomActivity.this);
|
|
|
+ j.setVideoView(rongRTCVideoView);
|
|
|
+ createRoomId = j.getUserId();
|
|
|
+ list.add(rongRTCVideoView);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i.getMediaType() == RCRTCMediaType.AUDIO) {
|
|
|
+ //音频流判断显示上麦用户
|
|
|
+ String userId = i.getUserId();
|
|
|
+ if (TextUtils.equals(mUserId, userId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (mRoomInfoBean != null) {
|
|
|
+ if (!TextUtils.equals(mRoomInfoBean.speakerId, userId)) {
|
|
|
+ otherAudioUserIds.add(userId);
|
|
|
+ } else {
|
|
|
+ //主播的音频流
|
|
|
+ RCRTCAudioInputStream rcrtcAudioInputStream = (RCRTCAudioInputStream) i;
|
|
|
+ RCRTCResourceState resourceState = rcrtcAudioInputStream.getResourceState();
|
|
|
+ isNormalCreateAudioStatus = resourceState == RCRTCResourceState.NORMAL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (otherAudioUserIds.size() != 0) {
|
|
|
+ mLlMicContainer.delAllExcludeOwn();
|
|
|
+ for (int i = 0; i < otherAudioUserIds.size(); i++) {
|
|
|
+ String onMicUserId = otherAudioUserIds.get(i);
|
|
|
+ notifyMicContainerAdd(onMicUserId, "");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mLlMicContainer.delAllExcludeOwn();
|
|
|
+ }
|
|
|
+ if (list.size() != 0) {
|
|
|
+ creatorIsCloseVideoStream = false;
|
|
|
+ mViewLiveStatus.setVisibility(View.GONE);
|
|
|
+ RCRTCVideoView rcrtcVideoView = list.get(list.size() - 1);
|
|
|
+ mFlLiveView.removeAllViews();
|
|
|
+// mFlLiveView.addView(rcrtcVideoView);
|
|
|
+ rcrtcVideoView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
|
|
|
+ RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
+ params.addRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
+ // 将远端视图添加至布局
|
|
|
+ mFlLiveView.addView(rcrtcVideoView, params);
|
|
|
+ } else {
|
|
|
+ creatorIsCloseVideoStream = true;
|
|
|
+ if (isNormalCreateAudioStatus) {
|
|
|
+ showCloseVideoView();
|
|
|
+ } else {
|
|
|
+ //主播关闭了视频流,同时音频流的状态也不是normal状态时
|
|
|
+ showRestView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onSaveInstanceState(Bundle outState) {
|
|
|
+ super.onSaveInstanceState(outState);
|
|
|
+ Log.i("LiveRoomActivity", "onSaveInstanceState");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBackPressed() {
|
|
|
+ boolean permissionOverlay = FloatWindowHelper.requestOverlayPermission(this);
|
|
|
+ if (!permissionOverlay) {
|
|
|
+ showOpenOverlayPermissionTipDialog();
|
|
|
+ } else {
|
|
|
+ if (isFullScreen()) {
|
|
|
+ changeOrientation();
|
|
|
+ } else {
|
|
|
+ showExitLiveTipDialog();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退出直播间提示弹窗
|
|
|
+ */
|
|
|
+ private void showExitLiveTipDialog() {
|
|
|
+ LiveRoomCloseTipDialog closeTipDialog = new LiveRoomCloseTipDialog(this);
|
|
|
+ closeTipDialog.setConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ closeTipDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showOpenOverlayPermissionTipDialog() {
|
|
|
+ OpenOverlayPermissionTipDialog overlayPermissionTipDialog = new OpenOverlayPermissionTipDialog(this);
|
|
|
+ overlayPermissionTipDialog.setConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ overlayPermissionTipDialog.dismiss();
|
|
|
+ Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
|
|
|
+ startActivityForResult(intent, FloatWindowHelper.REQUEST_OVERLAY_CODE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ overlayPermissionTipDialog.show();
|
|
|
+ overlayPermissionTipDialog.setCancelClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ overlayPermissionTipDialog.dismiss();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
+ super.onRestoreInstanceState(savedInstanceState);
|
|
|
+// String str = savedInstanceState.getString("key");
|
|
|
+ Log.i("LiveRoomActivity", "onRestoreInstanceState");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private int getCurrentOrientation() {
|
|
|
+ return getResources().getConfiguration().orientation;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isFullScreen() {
|
|
|
+ return getCurrentOrientation() == Configuration.ORIENTATION_LANDSCAPE;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void startFloatWindowService() {
|
|
|
+ boolean hasPermission = FloatWindowHelper.requestOverlayPermission(this);
|
|
|
+ if (hasPermission) {
|
|
|
+ if (mVideoViewManager != null && mVideoViewManager.getAllVideoViews() != null && mVideoViewManager.getAllVideoViews().size() > 0) {
|
|
|
+ Intent intent = new Intent(this, FloatingWindowService.class);
|
|
|
+ initServiceConnection();
|
|
|
+ bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initServiceConnection() {
|
|
|
+ if (serviceConnection == null) {
|
|
|
+ serviceConnection = new ServiceConnection() {
|
|
|
+ @Override
|
|
|
+ public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
+ if (service instanceof FloatingWindowService.MyBinder) {
|
|
|
+ FloatingWindowService.MyBinder mBinder = (FloatingWindowService.MyBinder) service;
|
|
|
+ if (mVideoViewManager != null) {
|
|
|
+ ArrayList<RCRTCVideoView> allVideoViews = mVideoViewManager.getAllVideoViews();
|
|
|
+ mBinder.addVideoView(allVideoViews);
|
|
|
+ }
|
|
|
+ mBinder.setOnEventListener(new FloatingWindowService.OnEventListener() {
|
|
|
+ @Override
|
|
|
+ public void onServiceDestroy() {
|
|
|
+ if (mVideoViewManager != null) {
|
|
|
+ mVideoViewManager.update(mVideoViewManager.getAllVideoViews(), 0, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUnbindService() {
|
|
|
+ muteAll(true);
|
|
|
+ unbindService();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onServiceDisconnected(ComponentName name) {
|
|
|
+ if (mVideoViewManager != null) {
|
|
|
+ mVideoViewManager.update(mVideoViewManager.getAllVideoViews(), 0, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否静音全部
|
|
|
+ *
|
|
|
+ * @param isMute
|
|
|
+ */
|
|
|
+ private void muteAll(boolean isMute) {
|
|
|
+ if (LiveEventHelper.getInstance().getRtcRoom() != null) {
|
|
|
+ RCRTCRoom rtcRoom = LiveEventHelper.getInstance().getRtcRoom();
|
|
|
+ if (rtcRoom.getLocalUser() != null) {
|
|
|
+ LiveEventHelper.getInstance().getRtcRoom().muteAllRemoteAudio(isMute);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onRestart() {
|
|
|
+ super.onRestart();
|
|
|
+ unbindService();
|
|
|
+ //取消全部静音
|
|
|
+ muteAll(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 销毁悬浮窗service
|
|
|
+ */
|
|
|
+ private void unbindService() {
|
|
|
+ if (serviceConnection != null) {
|
|
|
+ try {
|
|
|
+ boolean isExist = AppUtils.isServiceWork(this, FloatingWindowService.CLASS_PATH);
|
|
|
+ if (isExist) {
|
|
|
+ unbindService(serviceConnection);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ sendShowFloatWindowAction(SEND_APP_BACKGROUND_MSG);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendShowFloatWindowAction(int what) {
|
|
|
+ android.os.Message message = android.os.Message.obtain();
|
|
|
+ message.what = what;
|
|
|
+ mHandler.sendMessageDelayed(message, SEND_SHOW_FLOAT_WINDOW_TIME);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查聊天模式
|
|
|
+ */
|
|
|
+ public boolean checkChatMode() {
|
|
|
+ if (isEnableAll) {
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, "您已被管理员禁言");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (isEnableChat) {
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, "禁止聊天模式");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查mic模式
|
|
|
+ */
|
|
|
+ public boolean checkMicMode() {
|
|
|
+ if (isEnableAll) {
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, "您已被管理员禁言");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (isEnableMic) {
|
|
|
+ ToastUtil.getInstance().show(LiveRoomActivity.this, getString(R.string.enable_mic_mode_tip));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ if (presenter != null) {
|
|
|
+ //通知离开房间
|
|
|
+ presenter.notifyLeaveRoomAction();
|
|
|
+ }
|
|
|
+ super.onDestroy();
|
|
|
+ if (connectStatusListener != null) {
|
|
|
+ IMCenter.getInstance().removeConnectionStatusListener(connectStatusListener);
|
|
|
+ }
|
|
|
+ //取消动画
|
|
|
+ if (hideHeaderInfoAnim != null) {
|
|
|
+ hideHeaderInfoAnim.cancel();
|
|
|
+ hideHeaderInfoAnim = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (showHeaderInfoAnim != null) {
|
|
|
+ showHeaderInfoAnim.cancel();
|
|
|
+ showHeaderInfoAnim = null;
|
|
|
+ }
|
|
|
+ SoftKeyboardUtil.unregisterSoftInputChangedListener(getWindow());
|
|
|
+ LiveRoomAnimatorHelper.getInstance().releaseAnimator();
|
|
|
+ LiveRoomAddLikeHelper.getInstance().release();
|
|
|
+ LiveEventHelper.getInstance().unRegister();
|
|
|
+ RCRTCAudioRouteManager.getInstance().unInit();
|
|
|
+ if (mHandler != null) {
|
|
|
+ mHandler.removeCallbacksAndMessages(null);
|
|
|
+ }
|
|
|
+ if (mVideoViewManager != null) {
|
|
|
+ mVideoViewManager.onRelease();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSoftInputChanged(int height) {
|
|
|
+ Log.i("pq", "height" + height);
|
|
|
+ if (height == 0) {
|
|
|
+ //软键盘隐藏
|
|
|
+ Log.i("pq", "SoftInput hide");
|
|
|
+ if (mInputBarDialog != null && mInputBarDialog.isShowing()) {
|
|
|
+ mInputBarDialog.dismiss();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //软键盘弹出
|
|
|
+ Log.i("pq", "SoftInput show");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|