|
@@ -0,0 +1,1684 @@
|
|
|
+package com.daya.tclive.ui;
|
|
|
+
|
|
|
+import android.Manifest;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
+import android.os.Message;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.KeyEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.widget.FrameLayout;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
+import com.cooleshow.base.utils.AppUtils;
|
|
|
+import com.cooleshow.base.utils.GsonUtils;
|
|
|
+import com.cooleshow.base.utils.PermissionUtils;
|
|
|
+import com.cooleshow.base.utils.SoftKeyboardUtil;
|
|
|
+import com.cooleshow.base.utils.TimeUtils;
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
+import com.cooleshow.base.utils.ToastUtils;
|
|
|
+import com.cooleshow.base.utils.UiUtils;
|
|
|
+import com.cooleshow.base.widgets.InputBar;
|
|
|
+import com.cooleshow.base.widgets.dialog.CommonConfirmDialog;
|
|
|
+import com.cooleshow.base.widgets.dialog.InputBarDialog;
|
|
|
+import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
+import com.daya.tclive.R;
|
|
|
+import com.daya.tclive.adapter.TTLiveRoomMessageAdapter;
|
|
|
+import com.daya.tclive.bean.FriendInfoBean;
|
|
|
+import com.daya.tclive.bean.LiveCourseCountTimeResultBean;
|
|
|
+import com.daya.tclive.bean.LiveCourseTimeInfo;
|
|
|
+import com.daya.tclive.bean.LiveRoomInfoBean;
|
|
|
+import com.daya.tclive.bean.LiveStatusSEMIMsg;
|
|
|
+import com.daya.tclive.bean.TTMessage;
|
|
|
+import com.daya.tclive.bean.TTUserInfo;
|
|
|
+import com.daya.tclive.bean.User;
|
|
|
+import com.daya.tclive.constants.ARouterConstace;
|
|
|
+import com.daya.tclive.constants.LiveRoomMsgConstants;
|
|
|
+import com.daya.tclive.contract.TCLiveRoomContract;
|
|
|
+import com.daya.tclive.databinding.ActivityTcTeacherLiveRoomLayoutBinding;
|
|
|
+import com.daya.tclive.helper.LiveCourseCountTimeHelper;
|
|
|
+import com.daya.tclive.helper.LiveMemberHelper;
|
|
|
+import com.daya.tclive.helper.LiveMessageHelper;
|
|
|
+import com.daya.tclive.helper.LiveRoomAnimatorHelper;
|
|
|
+import com.daya.tclive.helper.LiveRoomMicMemberHelper;
|
|
|
+import com.daya.tclive.helper.TTLiveHelper;
|
|
|
+import com.daya.tclive.manager.TCIMSdkManager;
|
|
|
+import com.daya.tclive.manager.TRTCSdkManager;
|
|
|
+import com.daya.tclive.message.TCAddLikeMessage;
|
|
|
+import com.daya.tclive.message.TCLiveForceKickMessage;
|
|
|
+import com.daya.tclive.message.TCUserEnterMessage;
|
|
|
+import com.daya.tclive.message.TCUserLeaveMessage;
|
|
|
+import com.daya.tclive.message.TCUserLogOutUnNormalMessage;
|
|
|
+import com.daya.tclive.message.TCUserMicStatusChangeMessage;
|
|
|
+import com.daya.tclive.message.TCUserSeatApplyMessage;
|
|
|
+import com.daya.tclive.message.TCUserSnappingUpMessage;
|
|
|
+import com.daya.tclive.presenter.TCLivePresenter;
|
|
|
+import com.daya.tclive.widget.TTLiveRoomMicIconView;
|
|
|
+import com.daya.tclive.widget.dialog.LiveMicOnEventListener;
|
|
|
+import com.daya.tclive.widget.dialog.LiveRoomManagerDialog;
|
|
|
+import com.daya.tclive.widget.dialog.TTLiveMicManagerDialog;
|
|
|
+import com.gyf.immersionbar.ImmersionBar;
|
|
|
+import com.tbruyelle.rxpermissions3.RxPermissions;
|
|
|
+import com.tencent.imsdk.v2.V2TIMSDKListener;
|
|
|
+import com.tencent.imsdk.v2.V2TIMUserFullInfo;
|
|
|
+import com.tencent.imsdk.v2.V2TIMUserStatus;
|
|
|
+import com.tencent.rtmp.ui.TXCloudVideoView;
|
|
|
+
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+import androidx.viewbinding.ViewBinding;
|
|
|
+import io.reactivex.rxjava3.disposables.Disposable;
|
|
|
+import com.daya.tclive.constants.TTLiveConfig;
|
|
|
+import com.tencent.trtc.TRTCStatistics;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Author by pq, Date on 2023/3/2.
|
|
|
+ */
|
|
|
+@Route(path = ARouterConstace.ACTIVITY_TC_LIVE_ROOM_TEACHER)
|
|
|
+public class TCTeacherLiveRoomActivity extends BaseMVPActivity<ActivityTcTeacherLiveRoomLayoutBinding,TCLivePresenter> implements TCLiveRoomContract.TCLiveRoomView, SoftKeyboardUtil.OnSoftInputChangedListener, LiveRoomMicMemberHelper.OnEventListener, View.OnClickListener {
|
|
|
+ TXCloudVideoView mVideoView;
|
|
|
+ FrameLayout mFlCreateOptions;
|
|
|
+ ConstraintLayout mCsMainLayout;
|
|
|
+ RecyclerView recyclerMsg;
|
|
|
+ FrameLayout mFlJoinBarrage;
|
|
|
+ TextView mTvJoinBarrage;
|
|
|
+ FrameLayout mFlSnapUpBarrage;
|
|
|
+ TextView mTvSnapUpBarrage;
|
|
|
+ TextView mTvOnMicNumTip;
|
|
|
+ TextView mTvNumPeople;
|
|
|
+ ImageView mIvMicMode;
|
|
|
+ TextView mTvAddLikeCount;
|
|
|
+ TextView mTvRoomCreateName;
|
|
|
+ ImageView mIvAvatar;
|
|
|
+ ImageView mIvLiveDelay;
|
|
|
+ TextView mTvLiveDelay;
|
|
|
+ TTLiveRoomMicIconView llMicContainer;
|
|
|
+ LinearLayout llCountTimeTip;
|
|
|
+ TextView tvCountTimeValue;
|
|
|
+ TextView tvCountTimeTip;
|
|
|
+ ImageView iconFinishLive;
|
|
|
+ public static final int SYNC_ADD_LIKE_TIME = 10000;//同步点赞数时长(兼心跳功能)
|
|
|
+ public static final int COUNT_TIME = 1000;//计时间隔
|
|
|
+ public static final int SYNC_MIC_USER_STATUS_TIME = 2000;//同步在麦上人
|
|
|
+ public static final int SEND_APP_BACKGROUND_MSG = 1001;//退到后台消息
|
|
|
+ public static final int SEND_SYNC_MIC_USER_STATUS_MSG = 1002;//同步在麦上用户状态消息
|
|
|
+ public static final int SEND_COUNT_TIME_MSG = 1003;//计时消息
|
|
|
+ public static final int SEND_EXIT_COUNT_TIME_MSG = 1004;//退出直播课消息
|
|
|
+
|
|
|
+
|
|
|
+ public static final String TAG = "liveRoom";
|
|
|
+ public static final String ROOMID_KEY = "roomid_key";
|
|
|
+ public static final String COURSE_ID_KEY = "course_id_key";
|
|
|
+ public static final String SUBJECT_ID_KEY = "subject_id_key";
|
|
|
+ private int currentLiveMode = TTLiveConfig.LIVE_MODE_PREVIEW;//默认是预览模式
|
|
|
+ private int currentLiveStatus = TTLiveConfig.LIVE_STATUS_NORMAL;
|
|
|
+ private String mRoomId = "";
|
|
|
+ private String mUserId = "";
|
|
|
+ private LiveRoomInfoBean mRoomInfoBean;
|
|
|
+ private LiveRoomManagerDialog mRoomManagerDialog;
|
|
|
+ private CommonConfirmDialog mConfirmDialog;
|
|
|
+ private TTLiveRoomMessageAdapter mMessageAdapter;
|
|
|
+ private LinearLayoutManager mLinearLayoutManager;
|
|
|
+ private InputBarDialog mInputBarDialog;
|
|
|
+ private boolean isAutoScrollToLast = true;
|
|
|
+ private long currentAddLikeCount = 0;//当前点赞数量
|
|
|
+ private LiveRoomMicMemberHelper mRoomMicMemberHelper;
|
|
|
+ private TTLiveMicManagerDialog mLiveMicManagerDialog;
|
|
|
+ private boolean isDisAbleMic = false;// disable true 关闭麦克风 false 打开麦克风
|
|
|
+ private boolean isOnResume = false;
|
|
|
+ private boolean isConnectImFailed = false;//IM状态是否异常
|
|
|
+
|
|
|
+ private long normalTotalTime = 0;//直播课剩余时间
|
|
|
+ private long serviceTimeStamp = -1;//服务器时间节点
|
|
|
+ private int currentCountType = LiveCourseCountTimeHelper.COUNT_TYPE_COURSE;
|
|
|
+ private long autoCloseNetworkRoomTime = 0;//直播课到时间强制退出时间
|
|
|
+ private String liveCourseId = "";
|
|
|
+ private String subjectId;
|
|
|
+
|
|
|
+ private Handler mHandler = new Handler(Looper.myLooper()) {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(@NonNull Message msg) {
|
|
|
+ int what = msg.what;
|
|
|
+ if (what == SEND_APP_BACKGROUND_MSG) {
|
|
|
+ if (!isOnResume && AppUtils.isApplicationInBackground(TCTeacherLiveRoomActivity.this)) {
|
|
|
+ Log.i("pq", "onPause publish");
|
|
|
+ pauseLive();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (what == SEND_SYNC_MIC_USER_STATUS_MSG) {
|
|
|
+ if (presenter != null) {
|
|
|
+ ArrayList<User> onMicUsers = mRoomMicMemberHelper.getOnMicUsers();
|
|
|
+ ArrayList<LiveStatusSEMIMsg.UserStatusBean> statusBeans = convertOnMicUser(onMicUsers);
|
|
|
+ LiveStatusSEMIMsg semiMsg = LiveStatusSEMIMsg.createSyncMessage(statusBeans);
|
|
|
+ String s = GsonUtils.toJson(semiMsg);
|
|
|
+ presenter.sendSEMIMessage(s);
|
|
|
+ }
|
|
|
+ sendSyncOnMicStatusMessage();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (what == SEND_COUNT_TIME_MSG) {
|
|
|
+ normalTotalTime -= 1000;
|
|
|
+ serviceTimeStamp += 1000;
|
|
|
+ setTimeText(normalTotalTime);
|
|
|
+ if (normalTotalTime > 0) {
|
|
|
+ sendCountTimeMessage();
|
|
|
+ } else {
|
|
|
+ parseTime();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (what == SEND_EXIT_COUNT_TIME_MSG) {
|
|
|
+ autoCloseNetworkRoomTime -= 1000;
|
|
|
+ setTimeText(autoCloseNetworkRoomTime);
|
|
|
+ if (autoCloseNetworkRoomTime <= 0) {
|
|
|
+ finish();
|
|
|
+ } else {
|
|
|
+ sendExitCountTimeMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private void parseTime() {
|
|
|
+ LiveCourseCountTimeResultBean bean = LiveCourseCountTimeHelper.getInstance().parseTimeInfoToCountTime(serviceTimeStamp);
|
|
|
+ if (bean != null) {
|
|
|
+ clearCountTimeMessage();
|
|
|
+ if (bean.getStatus() == LiveCourseCountTimeHelper.STATUS_NORMAL) {
|
|
|
+ //支持计时条件
|
|
|
+ llCountTimeTip.setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ if (bean.getStatus() == LiveCourseCountTimeHelper.STATUS_FINISH) {
|
|
|
+ //时间已结束
|
|
|
+ ToastUtil.getInstance().show(TCTeacherLiveRoomActivity.this, "直播课已结束");
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ llCountTimeTip.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ if (bean.getType() == LiveCourseCountTimeHelper.COUNT_TYPE_FINISH) {
|
|
|
+ autoCloseNetworkRoomTime = bean.getTotalTime();
|
|
|
+ if (autoCloseNetworkRoomTime > 0) {
|
|
|
+ updateCountTip(LiveCourseCountTimeHelper.COUNT_TYPE_FINISH);
|
|
|
+ setTimeText(autoCloseNetworkRoomTime);
|
|
|
+ sendExitCountTimeMessage();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ normalTotalTime = bean.getTotalTime();
|
|
|
+ updateCountTip(bean.getType());
|
|
|
+ setTimeText(normalTotalTime);
|
|
|
+ sendCountTimeMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArrayList<LiveStatusSEMIMsg.UserStatusBean> convertOnMicUser(ArrayList<User> onMicUsers) {
|
|
|
+ if (onMicUsers != null && onMicUsers.size() > 0) {
|
|
|
+ ArrayList<LiveStatusSEMIMsg.UserStatusBean> statusBeans = new ArrayList<>();
|
|
|
+ for (int i = 0; i < onMicUsers.size(); i++) {
|
|
|
+ User user = onMicUsers.get(i);
|
|
|
+ LiveStatusSEMIMsg.UserStatusBean userStatusBean = new LiveStatusSEMIMsg.UserStatusBean();
|
|
|
+ userStatusBean.setUserId(user.getUserId());
|
|
|
+ String extra = user.getExtra();
|
|
|
+ try {
|
|
|
+ JSONObject extraJson = new JSONObject(extra);
|
|
|
+ String micStatusResult = extraJson.optString(TTLiveConfig.LIVE_ROOM_MIC_STATUS_KEY, TTLiveConfig.LIVE_ROOM_MIC_STATUS_OFF_VALUE);
|
|
|
+ userStatusBean.setMicStatus(TextUtils.equals(micStatusResult, TTLiveConfig.LIVE_ROOM_MIC_STATUS_ON_VALUE));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ statusBeans.add(userStatusBean);
|
|
|
+ }
|
|
|
+ return statusBeans;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startCountTime() {
|
|
|
+ parseTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setTimeText(long time) {
|
|
|
+ tvCountTimeValue.setText(TimeUtils.msToTime((int) time));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendSyncOnMicStatusMessage() {
|
|
|
+ Message obtain = Message.obtain();
|
|
|
+ obtain.what = SEND_SYNC_MIC_USER_STATUS_MSG;
|
|
|
+ mHandler.removeMessages(SEND_SYNC_MIC_USER_STATUS_MSG);
|
|
|
+ mHandler.sendMessageDelayed(obtain, SYNC_MIC_USER_STATUS_TIME);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendCountTimeMessage() {
|
|
|
+ Message obtain = Message.obtain();
|
|
|
+ obtain.what = SEND_COUNT_TIME_MSG;
|
|
|
+ mHandler.removeMessages(SEND_COUNT_TIME_MSG);
|
|
|
+ mHandler.sendMessageDelayed(obtain, COUNT_TIME);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendExitCountTimeMessage() {
|
|
|
+ Message obtain = Message.obtain();
|
|
|
+ obtain.what = SEND_EXIT_COUNT_TIME_MSG;
|
|
|
+ mHandler.removeMessages(SEND_EXIT_COUNT_TIME_MSG);
|
|
|
+ mHandler.sendMessageDelayed(obtain, COUNT_TIME);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void clearCountTimeMessage() {
|
|
|
+ mHandler.removeMessages(SEND_COUNT_TIME_MSG);
|
|
|
+ mHandler.removeMessages(SEND_EXIT_COUNT_TIME_MSG);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateCountTip(int type) {
|
|
|
+ if (currentCountType == type) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ currentCountType = type;
|
|
|
+ if (type == LiveCourseCountTimeHelper.COUNT_TYPE_COURSE) {
|
|
|
+ tvCountTimeValue.setTextColor(getResources().getColor(R.color.color_00fff0));
|
|
|
+ tvCountTimeTip.setText("课程时长:");
|
|
|
+ }
|
|
|
+ if (type == LiveCourseCountTimeHelper.COUNT_TYPE_REST) {
|
|
|
+ tvCountTimeValue.setTextColor(getResources().getColor(R.color.color_00fff0));
|
|
|
+ tvCountTimeTip.setText("课间时间:");
|
|
|
+ }
|
|
|
+ if (type == LiveCourseCountTimeHelper.COUNT_TYPE_FINISH) {
|
|
|
+ tvCountTimeValue.setTextColor(getResources().getColor(R.color.color_ff605e));
|
|
|
+ tvCountTimeTip.setText("直播即将关闭:");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendSyncOnMicStatusMessageAtOnce() {
|
|
|
+ mHandler.removeMessages(SEND_SYNC_MIC_USER_STATUS_MSG);
|
|
|
+ Message obtain = Message.obtain();
|
|
|
+ obtain.what = SEND_SYNC_MIC_USER_STATUS_MSG;
|
|
|
+ mHandler.sendMessage(obtain);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Runnable mRunnable = new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ //10S更新一次当前UI,通知服务端点赞数量
|
|
|
+ Log.i("pq", "sync add like:" + currentAddLikeCount);
|
|
|
+ updateAddLikeCountView(currentAddLikeCount);
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.syncAddLikeNum(String.valueOf(currentAddLikeCount), mRoomId);
|
|
|
+// presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_ADD_LIKE_COUNT, currentAddLikeCount);
|
|
|
+ }
|
|
|
+ syncAddLikeNum();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ private V2TIMSDKListener mTIMSDKListener = new V2TIMSDKListener() {
|
|
|
+ @Override
|
|
|
+ public void onConnecting() {
|
|
|
+ super.onConnecting();
|
|
|
+ Log.i(TAG, "onConnecting");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onConnectSuccess() {
|
|
|
+ super.onConnectSuccess();
|
|
|
+ Log.i(TAG, "onConnectSuccess");
|
|
|
+ if (isConnectImFailed) {
|
|
|
+ ToastUtil.getInstance().show(TCTeacherLiveRoomActivity.this, "网络已恢复");
|
|
|
+ isConnectImFailed = false;
|
|
|
+ presenter.getAllGroupAttributes(mRoomId);
|
|
|
+ presenter.getAllGroupCounter(mRoomId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onConnectFailed(int code, String error) {
|
|
|
+ super.onConnectFailed(code, error);
|
|
|
+ Log.i(TAG, "onConnectFailed");
|
|
|
+ isConnectImFailed = true;
|
|
|
+ ToastUtil.getInstance().show(TCTeacherLiveRoomActivity.this, "直播已断开,请检查您的网络");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onKickedOffline() {
|
|
|
+ super.onKickedOffline();
|
|
|
+ Log.i(TAG, "onKickedOffline");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserSigExpired() {
|
|
|
+ super.onUserSigExpired();
|
|
|
+ Log.i(TAG, "onUserSigExpired");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSelfInfoUpdated(V2TIMUserFullInfo info) {
|
|
|
+ super.onSelfInfoUpdated(info);
|
|
|
+ Log.i(TAG, "onSelfInfoUpdated");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserStatusChanged(List<V2TIMUserStatus> userStatusList) {
|
|
|
+ super.onUserStatusChanged(userStatusList);
|
|
|
+ Log.i(TAG, "onUserStatusChanged");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView() {
|
|
|
+ mVideoView = viewBinding.liveVideoView;
|
|
|
+ mFlCreateOptions = viewBinding.viewCreateOptions.flRoot;
|
|
|
+ mCsMainLayout = viewBinding.viewMainLayout.csRoot;
|
|
|
+ recyclerMsg =viewBinding.viewMainLayout.recyclerMsg;
|
|
|
+ mFlJoinBarrage =viewBinding.viewMainLayout.flJoinBarrage;
|
|
|
+ mTvJoinBarrage =viewBinding.viewMainLayout.tvJoinBarrage;
|
|
|
+ mFlSnapUpBarrage = viewBinding.viewMainLayout.flSnapUpBarrage;
|
|
|
+ mTvSnapUpBarrage = viewBinding.viewMainLayout.tvSnapUpBarrage;
|
|
|
+ mTvOnMicNumTip = viewBinding.viewMainLayout.tvOnMicNumTip;
|
|
|
+ mTvNumPeople = viewBinding.viewMainLayout.tvNumPeople;
|
|
|
+ mIvMicMode = viewBinding.viewMainLayout.ivMicMode;
|
|
|
+ mTvAddLikeCount = viewBinding.viewMainLayout.tvAddLikeCount;
|
|
|
+ mTvRoomCreateName = viewBinding.viewMainLayout.tvRoomAuthorName;
|
|
|
+ mIvAvatar = viewBinding.viewMainLayout.ivAvatar;
|
|
|
+ mIvLiveDelay = viewBinding.viewMainLayout.ivLiveDelay;
|
|
|
+ mTvLiveDelay = viewBinding.viewMainLayout.tvLiveDelay;
|
|
|
+ llMicContainer = viewBinding.viewMainLayout.llMicContainer;
|
|
|
+ llCountTimeTip = viewBinding.viewMainLayout.llCountTimeTip;
|
|
|
+ tvCountTimeValue = viewBinding.viewMainLayout.tvCountTimeValue;
|
|
|
+ tvCountTimeTip = viewBinding.viewMainLayout.tvCountTimeTip;
|
|
|
+ iconFinishLive = viewBinding.viewMainLayout.iconFinishLive;
|
|
|
+ setStatusBarColor();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected ActivityTcTeacherLiveRoomLayoutBinding getLayoutView() {
|
|
|
+
|
|
|
+ return ActivityTcTeacherLiveRoomLayoutBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setStatusBarColor() {
|
|
|
+// ImmersionBar.with(this)
|
|
|
+// .keyboardEnable(false)//为了防止软键盘顶起底部布局
|
|
|
+// .transparentStatusBar()
|
|
|
+// .statusBarDarkFont(false, 0.2f) //原理:如果当前设备支持状态栏字体变色,会设置状态栏字体为黑色,如果当前设备不支持状态栏字体变色,会使当前状态栏加上透明度,否则不执行透明度
|
|
|
+// .autoDarkModeEnable(false)
|
|
|
+// .flymeOSStatusBarFontColor(com.rui.common_base.R.color.white) //修改flyme OS状态栏字体颜色
|
|
|
+// .init(); //必须调用方可沉浸
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+ super.initData();
|
|
|
+ mRoomId = getIntent().getStringExtra(ROOMID_KEY);
|
|
|
+ if (getIntent().hasExtra(COURSE_ID_KEY)) {
|
|
|
+ liveCourseId = getIntent().getStringExtra(COURSE_ID_KEY);
|
|
|
+ }
|
|
|
+ if (getIntent().hasExtra(SUBJECT_ID_KEY)) {
|
|
|
+ subjectId = getIntent().getStringExtra(SUBJECT_ID_KEY);
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(mRoomId)) {
|
|
|
+ ToastUtil.getInstance().show(this, "房间id不可为空");
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String userToken = UserHelper.getUserToken();
|
|
|
+ if (TextUtils.isEmpty(userToken)) {
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isLiveCourse()) {
|
|
|
+ iconFinishLive.setImageResource(R.drawable.icon_live_course_pause);
|
|
|
+ }
|
|
|
+ mUserId = UserHelper.getUserId();
|
|
|
+ mRoomMicMemberHelper = new LiveRoomMicMemberHelper();
|
|
|
+ mRoomMicMemberHelper.setOnEventListener(this);
|
|
|
+ mMessageAdapter = new TTLiveRoomMessageAdapter(this);
|
|
|
+ mLinearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
|
|
|
+ recyclerMsg.setLayoutManager(mLinearLayoutManager);
|
|
|
+ recyclerMsg.setAdapter(mMessageAdapter);
|
|
|
+ checkNeedPermission();
|
|
|
+ initListener();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected TCLivePresenter createPresenter() {
|
|
|
+ return new TCLivePresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkNeedPermission() {
|
|
|
+ Disposable disposable = new RxPermissions(TCTeacherLiveRoomActivity.this)
|
|
|
+ .request(Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
|
+ , Manifest.permission.CAMERA)
|
|
|
+ .subscribe(permission -> {
|
|
|
+ if (permission) {
|
|
|
+ initLiveConfig();
|
|
|
+ } else {
|
|
|
+ CommonConfirmDialog confirmDialog = new CommonConfirmDialog(TCTeacherLiveRoomActivity.this);
|
|
|
+ confirmDialog.show();
|
|
|
+ confirmDialog.setContent("直播需要麦克风、摄像头、储存权限,去设置?");
|
|
|
+ confirmDialog.setConfirmText("去设置");
|
|
|
+ confirmDialog.setOnConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ PermissionUtils.toSelfSetting(TCTeacherLiveRoomActivity.this);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void initLiveConfig() {
|
|
|
+ Log.i("pq", "initPublishConfig");
|
|
|
+ presenter.initPublishConfig(this);
|
|
|
+ prepareInitRoom();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener() {
|
|
|
+ TCIMSdkManager.getInstance().addEventListener(mTIMSDKListener);
|
|
|
+ SoftKeyboardUtil.registerSoftInputChangedListener(getWindow(), this);
|
|
|
+ recyclerMsg.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
+ @Override
|
|
|
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
|
|
+ super.onScrollStateChanged(recyclerView, newState);
|
|
|
+ if (mLinearLayoutManager == null || mMessageAdapter == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int lastCompletelyVisibleItemPosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
|
|
|
+ if (lastCompletelyVisibleItemPosition == mMessageAdapter.getMessageSize() - 1) {
|
|
|
+ isAutoScrollToLast = true;
|
|
|
+ } else {
|
|
|
+ isAutoScrollToLast = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void prepareInitRoom() {
|
|
|
+ presenter.getRoomInfo(mRoomId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getRoomInfoSuccess(LiveRoomInfoBean roomInfoBean) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (roomInfoBean == null) {
|
|
|
+ ToastUtil.getInstance().showShort("获取房间信息失败,请退出重试");
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.mRoomInfoBean = roomInfoBean;
|
|
|
+ syncAddLikeNum();
|
|
|
+ if (mMessageAdapter != null) {
|
|
|
+ mMessageAdapter.setRoomAuthorId(roomInfoBean.speakerId);
|
|
|
+ }
|
|
|
+ int peopleCount = roomInfoBean.lookNum;
|
|
|
+ setPeopleCount(peopleCount);
|
|
|
+ //同步点赞数
|
|
|
+ updateAddLikeCountView(roomInfoBean.likeNum);
|
|
|
+ //创建人头像
|
|
|
+ Glide.with(this).load(roomInfoBean.speakerPic).placeholder(com.cooleshow.base.R.drawable.icon_default_head).error(com.cooleshow.base.R.drawable.icon_default_head).into(mIvAvatar);
|
|
|
+ //创建人昵称
|
|
|
+ mTvRoomCreateName.setText(roomInfoBean.speakerName);
|
|
|
+ if (presenter != null) {
|
|
|
+ //配置直播的config配置
|
|
|
+ Log.i("pq", "isPreviewMode:" + isPreviewMode());
|
|
|
+ if (isPreviewMode()) {
|
|
|
+ openPreViewMode();
|
|
|
+ } else {
|
|
|
+ //加入房间
|
|
|
+ if (!TextUtils.isEmpty(roomInfoBean.getUserSig())) {
|
|
|
+ presenter.enterRoom(mUserId, mRoomId, mVideoView, roomInfoBean.getUserSig());
|
|
|
+ presenter.connectIM(mRoomId, mUserId, roomInfoBean.getUserSig());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setPeopleCount(int peopleCount) {
|
|
|
+ mTvNumPeople.setText(String.format("%s人", LiveMemberHelper.getMemberCountText(peopleCount)));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener2(){
|
|
|
+ viewBinding.viewCreateOptions.ivReverseCamera.setOnClickListener(this);
|
|
|
+ viewBinding.viewCreateOptions.tvStartLive.setOnClickListener(this);
|
|
|
+ viewBinding.viewCreateOptions.tvClose.setOnClickListener(this);
|
|
|
+ viewBinding.viewMainLayout.tvInput.setOnClickListener(this);
|
|
|
+ viewBinding.viewMainLayout.ivMic.setOnClickListener(this);
|
|
|
+ viewBinding.viewMainLayout.iconFinishLive.setOnClickListener(this);
|
|
|
+ viewBinding.viewMainLayout.mainIvReverseCamera.setOnClickListener(this);
|
|
|
+ viewBinding.viewMainLayout.ivMicMode.setOnClickListener(this);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onClick(View v) {
|
|
|
+ int id = v.getId();
|
|
|
+ if (id == R.id.tv_close) {
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (id == R.id.iv_reverse_camera || id == R.id.main_iv_reverse_camera) {
|
|
|
+ //翻转摄像头
|
|
|
+ presenter.switchCamera();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.tv_start_live) {
|
|
|
+ //开始直播
|
|
|
+ if (UiUtils.isFastClick()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mRoomInfoBean != null) {
|
|
|
+ //预览模式,开启直播
|
|
|
+ //点开启直播之前再次验证一下房间信息
|
|
|
+ currentLiveMode = TTLiveConfig.LIVE_MODE_LIVE_START;
|
|
|
+ presenter.getRoomInfo(mRoomId);
|
|
|
+ if (!TextUtils.isEmpty(liveCourseId)) {
|
|
|
+ presenter.getLiveCourseInfo(liveCourseId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.iv_mic) {
|
|
|
+ //连麦管理
|
|
|
+ showMicManagerDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.tv_input) {
|
|
|
+ //底部输入框
|
|
|
+ showInputDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.icon_finish_live) {
|
|
|
+ if (isLiveCourse()) {
|
|
|
+ showPaseLiveTipDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //显示直播间管理弹窗
|
|
|
+ showLiveRoomManagerDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.iv_mic_mode) {
|
|
|
+ //禁音切换
|
|
|
+ updateMicMode();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ this.isOnResume = true;
|
|
|
+ if (isLiveMode() && isLivePause()) {
|
|
|
+ Log.i("pq", "onResume publish");
|
|
|
+ currentLiveMode = TTLiveConfig.LIVE_MODE_LIVE_START;
|
|
|
+ presenter.getRoomInfo(mRoomId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ this.isOnResume = false;
|
|
|
+ if (isLiveMode()) {
|
|
|
+ //退到后台,延迟2S发送检测消息,
|
|
|
+ Message obtain = Message.obtain();
|
|
|
+ obtain.what = SEND_APP_BACKGROUND_MSG;
|
|
|
+ mHandler.sendMessageDelayed(obtain, 2000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateAddLikeCountView(long count) {
|
|
|
+ this.currentAddLikeCount = count;
|
|
|
+ if (mTvAddLikeCount != null) {
|
|
|
+ mTvAddLikeCount.setText(getString(R.string.live_room_add_like_count_str, LiveMemberHelper.getStarsCountText(currentAddLikeCount)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateMicMode() {
|
|
|
+ if (isDisAbleMic) {
|
|
|
+ presenter.setMicrophoneDisable(false);
|
|
|
+ isDisAbleMic = false;
|
|
|
+ ToastUtil.getInstance().show(this, "您已开启麦克风");
|
|
|
+ mIvMicMode.setImageResource(R.drawable.icon_mic_mode_on);
|
|
|
+ } else {
|
|
|
+ presenter.setMicrophoneDisable(true);
|
|
|
+ isDisAbleMic = true;
|
|
|
+ ToastUtil.getInstance().show(this, "您已关闭麦克风");
|
|
|
+ mIvMicMode.setImageResource(R.drawable.icon_mic_mode_off);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示直播间管理弹窗
|
|
|
+ */
|
|
|
+ private void showLiveRoomManagerDialog() {
|
|
|
+ if (mRoomManagerDialog == null) {
|
|
|
+ mRoomManagerDialog = new LiveRoomManagerDialog(this);
|
|
|
+ mRoomManagerDialog.setOnEventListener(new LiveRoomManagerDialog.OnEventListener() {
|
|
|
+ @Override
|
|
|
+ public void onPauseLive() {
|
|
|
+ //暂停直播
|
|
|
+ showPaseLiveTipDialog();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFinishLive() {
|
|
|
+ //结束直播
|
|
|
+ showCommonTipDialog(getString(R.string.finish_live_tip_str), getString(R.string.live_finish_str), new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.notifyCloseLiveRoomAction(mRoomId);
|
|
|
+ }
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!mRoomManagerDialog.isShowing()) {
|
|
|
+ mRoomManagerDialog.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showPaseLiveTipDialog() {
|
|
|
+ showCommonTipDialog(getString(R.string.live_pause_tip_str), getString(R.string.pause_live), new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (mConfirmDialog != null) {
|
|
|
+ mConfirmDialog.dismiss();
|
|
|
+ }
|
|
|
+ if (mRoomManagerDialog != null) {
|
|
|
+ mRoomManagerDialog.dismiss();
|
|
|
+ }
|
|
|
+ pauseLive();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示通用提示弹窗
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ * @param confirmText
|
|
|
+ */
|
|
|
+ private void showCommonTipDialog(String content, String confirmText, View.OnClickListener listener) {
|
|
|
+ if (mConfirmDialog == null) {
|
|
|
+ mConfirmDialog = new CommonConfirmDialog(this);
|
|
|
+ }
|
|
|
+ if (!mConfirmDialog.isShowing()) {
|
|
|
+ mConfirmDialog.show();
|
|
|
+ }
|
|
|
+ mConfirmDialog.setContent(content);
|
|
|
+ mConfirmDialog.setConfirmText(confirmText);
|
|
|
+ mConfirmDialog.setOnConfirmClickListener(listener);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 切换直播模式
|
|
|
+ *
|
|
|
+ * @param mode
|
|
|
+ */
|
|
|
+ private void switchLiveMode(int mode) {
|
|
|
+ //切换直播模式
|
|
|
+ currentLiveMode = mode;
|
|
|
+ if (mode == TTLiveConfig.LIVE_MODE_PREVIEW) {
|
|
|
+ //直播暂停模式,切换成预览模式
|
|
|
+ //通知关闭直播录像
|
|
|
+// switchOpsLiveVideoMode(LiveConfig.CLOSE_OPS_LIVE_VIDEO_TYPE);
|
|
|
+ openPreViewMode();
|
|
|
+ } else {
|
|
|
+ //直播模式
|
|
|
+// presenter.startPublish(mRoomId, mUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 暂停直播
|
|
|
+ */
|
|
|
+ private void pauseLive() {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.stopPublish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否是预览模式
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean isPreviewMode() {
|
|
|
+ return currentLiveMode == TTLiveConfig.LIVE_MODE_PREVIEW;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getRoomInfoError(Throwable throwable) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void enterLiveRoomSuccess() {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ config3AParamsIfNeed();
|
|
|
+ presenter.startPublish(mRoomId, mUserId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void config3AParamsIfNeed() {
|
|
|
+ if (!TextUtils.isEmpty(subjectId)) {
|
|
|
+ presenter.config3AParamsFromSubject(subjectId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPublishSuccess() {
|
|
|
+ switchMainUI();
|
|
|
+ presenter.setMicrophoneDisable(isDisAbleMic);
|
|
|
+ currentLiveStatus = TTLiveConfig.LIVE_STATUS_NORMAL;
|
|
|
+ presenter.notifyJoinRoomAction(mRoomId, mUserId);
|
|
|
+ presenter.notifyLiveRoomStatus(mRoomId, true);
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_TEACHER_START_PUBLISH);
|
|
|
+ //推流成功同步在麦上用户状态等
|
|
|
+ sendSyncOnMicStatusMessage();
|
|
|
+// presenter.setGroupAttribute(mRoomId, TTLiveConfig.LIVE_ROOM_LIVE_STATUS_KEY, TTLiveConfig.STATUS_ON);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStopPublishing() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onExitRoomSuccess() {
|
|
|
+ currentLiveStatus = TTLiveConfig.LIVE_STATUS_PAUSE;
|
|
|
+ presenter.notifyLiveRoomStatus(mRoomId, false);
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_PAUSE_LIVE);
|
|
|
+ switchLiveMode(isOnResume ? TTLiveConfig.LIVE_MODE_PREVIEW : TTLiveConfig.LIVE_MODE_LIVE_START);
|
|
|
+// presenter.setGroupAttribute(mRoomId, TTLiveConfig.LIVE_ROOM_LIVE_STATUS_KEY, TTLiveConfig.STATUS_OFF);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void loginIMSuccess() {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.joinIMGroup(mRoomId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void connectIMError(int errorCode, String errorMsg) {
|
|
|
+ ToastUtil.getInstance().show(this, "加入直播间群聊异常,请退出重试");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addMessageContent(TTMessage message) {
|
|
|
+ //添加单条消息至页面
|
|
|
+ Log.i("pq", "收到需要显示msg:" + message);
|
|
|
+ //只处理直播间消息,以及本直播间消息
|
|
|
+ if (mMessageAdapter != null) {
|
|
|
+ mMessageAdapter.addMessage(message);
|
|
|
+ if (mLinearLayoutManager != null) {
|
|
|
+ recyclerMsg.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (isAutoScrollToLast) {
|
|
|
+ if (recyclerMsg != null) {
|
|
|
+ recyclerMsg.scrollToPosition(mMessageAdapter.getItemCount() - 1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Log.i("pq", "收到消息,不触发滚动");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void joinGroupSuccess() {
|
|
|
+ hideLoading();
|
|
|
+ presenter.bindGroupListener();
|
|
|
+ presenter.getAllGroupAttributes(mRoomId);
|
|
|
+ presenter.getAllGroupCounter(mRoomId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void joinGroupError(int code, String des) {
|
|
|
+ hideLoading();
|
|
|
+ ToastUtil.getInstance().show(this, "加入直播群组失败,请退出重试");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void receiveJoinMessage(TCUserEnterMessage joinRoomMessage) {
|
|
|
+ //收到加入房间消息
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (joinRoomMessage == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //加入房间之前把申请列表删除
|
|
|
+ String userId = "";
|
|
|
+ if (joinRoomMessage.getSendUserInfo() != null) {
|
|
|
+ userId = joinRoomMessage.getSendUserInfo().getSendUserId();
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(userId)) {
|
|
|
+ delUser(userId);
|
|
|
+ }
|
|
|
+ if (isCanShowBarrage()) {
|
|
|
+ mTvJoinBarrage.setText(getString(R.string.enter_live_tip_str, TTLiveHelper.getMessageName(joinRoomMessage)));
|
|
|
+ showBarrageViewAnim(mFlJoinBarrage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示弹幕消息
|
|
|
+ */
|
|
|
+ private void showBarrageViewAnim(View targetView) {
|
|
|
+ if (mFlJoinBarrage.getVisibility() == View.VISIBLE || mFlSnapUpBarrage.getVisibility() == View.VISIBLE) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LiveRoomAnimatorHelper.getInstance().startBarrageViewAnimation(this, targetView);
|
|
|
+ hideBarrageView();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 隐藏弹幕消息
|
|
|
+ */
|
|
|
+ private void hideBarrageView() {
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (mFlJoinBarrage != null) {
|
|
|
+ mFlJoinBarrage.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ if (mFlSnapUpBarrage != null) {
|
|
|
+ mFlSnapUpBarrage.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, TTLiveConfig.LIVE_HIDE_BARRAGE_VIEW_TIME);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否显示弹幕消息
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean isCanShowBarrage() {
|
|
|
+ return mFlJoinBarrage.getVisibility() != View.VISIBLE && mFlSnapUpBarrage.getVisibility() != View.VISIBLE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void receiveSnapUpMessage(TCUserSnappingUpMessage rcOnSnappingUpMessage) {
|
|
|
+ //收到抢购消息
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (rcOnSnappingUpMessage == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isCanShowBarrage()) {
|
|
|
+ mTvSnapUpBarrage.setText(getString(R.string.live_snap_up_tip_str, TTLiveHelper.getMessageName(rcOnSnappingUpMessage)));
|
|
|
+ showBarrageViewAnim(mFlSnapUpBarrage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAddLikeMessage(TCAddLikeMessage addLikeMessage) {
|
|
|
+ if (isFinishing() || isDestroyed() || addLikeMessage == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Log.i("pq", "receive addlikeNum:" + addLikeMessage.getCounts());
|
|
|
+ currentAddLikeCount += addLikeMessage.getCounts();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSeatApplyMessage(TCUserSeatApplyMessage seatApplyMessage) {
|
|
|
+ //连麦申请消息
|
|
|
+ if (isFinishing() || isDestroyed() || seatApplyMessage == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!isOwn(seatApplyMessage.getTeacherId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (seatApplyMessage.getType() == LiveRoomMsgConstants.MIC_ACTION_SEAT_BY_USER) {
|
|
|
+ //观众申请
|
|
|
+ User user = new User();
|
|
|
+ user.setUserName(seatApplyMessage.getAudienceName());
|
|
|
+ user.setUserId(seatApplyMessage.getAudienceId());
|
|
|
+ user.setPortrait(seatApplyMessage.getAudienceAvatar());
|
|
|
+ mRoomMicMemberHelper.addApplyUser(user);
|
|
|
+ updateMicManagerData();
|
|
|
+ }
|
|
|
+ if (seatApplyMessage.getType() == LiveRoomMsgConstants.ACTION_SEND_CANCEL_SEAT_APPLY || seatApplyMessage.getType() == LiveRoomMsgConstants.MIC_ACTION_CANCEL_SEAT_BY_USER) {
|
|
|
+ //观众取消
|
|
|
+ User user = new User();
|
|
|
+ user.setUserName(seatApplyMessage.getAudienceName());
|
|
|
+ user.setUserId(seatApplyMessage.getAudienceId());
|
|
|
+ user.setPortrait(seatApplyMessage.getAudienceAvatar());
|
|
|
+ mRoomMicMemberHelper.delApplyUser(user, false);
|
|
|
+ updateMicManagerData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateMicManagerData() {
|
|
|
+ if (mLiveMicManagerDialog != null) {
|
|
|
+ mLiveMicManagerDialog.setApplyListData(mRoomMicMemberHelper.getOnApplyMicUsers());
|
|
|
+ mLiveMicManagerDialog.setOnMicListData(mRoomMicMemberHelper.getOnMicUsers());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (llMicContainer != null) {
|
|
|
+ llMicContainer.refreshUIByUser(convertUserInfo(mRoomMicMemberHelper.getOnMicUsers()));
|
|
|
+ }
|
|
|
+ if (mTvOnMicNumTip != null) {
|
|
|
+ ArrayList<User> onApplyMicUsers = mRoomMicMemberHelper.getOnApplyMicUsers();
|
|
|
+ if (onApplyMicUsers != null && onApplyMicUsers.size() > 0) {
|
|
|
+ mTvOnMicNumTip.setVisibility(View.VISIBLE);
|
|
|
+ mTvOnMicNumTip.setText(String.valueOf(onApplyMicUsers.size()));
|
|
|
+ } else {
|
|
|
+ mTvOnMicNumTip.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArrayList<TTUserInfo> convertUserInfo(ArrayList<User> onMicUsers) {
|
|
|
+ ArrayList<TTUserInfo> resultUserInfo = new ArrayList<>();
|
|
|
+ if (onMicUsers != null && onMicUsers.size() > 0) {
|
|
|
+ for (int i = 0; i < onMicUsers.size(); i++) {
|
|
|
+ User user = onMicUsers.get(i);
|
|
|
+ TTUserInfo userInfo = new TTUserInfo(user.getUserId(), user.getUserName(), user.getPortraitUri());
|
|
|
+ userInfo.setMicStatus(TTLiveConfig.parseMuteMicModeFromExtra(user.getExtra()));
|
|
|
+ resultUserInfo.add(userInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultUserInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示连麦控制弹窗
|
|
|
+ */
|
|
|
+ private void showMicManagerDialog() {
|
|
|
+ if (mLiveMicManagerDialog == null) {
|
|
|
+ mLiveMicManagerDialog = new TTLiveMicManagerDialog(this);
|
|
|
+ mLiveMicManagerDialog.setOnEventListener(new LiveMicOnEventListener() {
|
|
|
+ @Override
|
|
|
+ public void onAgreeApply(User user) {
|
|
|
+ ArrayList<User> onMicUsers = mRoomMicMemberHelper.getOnMicUsers();
|
|
|
+ if (onMicUsers != null && onMicUsers.size() >= 4) {
|
|
|
+ ToastUtil.getInstance().show(TCTeacherLiveRoomActivity.this, "最多支持4人上麦哦~");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //同意连麦申请
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_AGREE_MIC_APPLY, user);
|
|
|
+ if (mRoomMicMemberHelper != null) {
|
|
|
+ mRoomMicMemberHelper.delApplyUser(user, true);
|
|
|
+ }
|
|
|
+ updateMicManagerData();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUnderMic(User user) {
|
|
|
+ //下麦
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_CANCEL_ON_MIC_BY_TEACHER, user);
|
|
|
+ if (mRoomMicMemberHelper != null) {
|
|
|
+ mRoomMicMemberHelper.delOnMicUser(user);
|
|
|
+ }
|
|
|
+ updateMicManagerData();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onChangeMuteTargetMic(String targetUserId, boolean isMute) {
|
|
|
+ //改变上麦人禁音模式
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_CONTROL_MIC_MUTE_MODE, targetUserId, isMute);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRefuseAllMicApply() {
|
|
|
+ if (mRoomMicMemberHelper != null) {
|
|
|
+ mRoomMicMemberHelper.delAllApplyUser();
|
|
|
+ }
|
|
|
+ updateMicManagerData();
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_REFUSE_ALL_MIC_APPLY_MSG);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSwitchMicMode(boolean isEnable) {
|
|
|
+ if (isEnable) {
|
|
|
+ if (mRoomMicMemberHelper != null) {
|
|
|
+ mRoomMicMemberHelper.delAllApplyUser();
|
|
|
+ }
|
|
|
+ updateMicManagerData();
|
|
|
+ }
|
|
|
+ if (presenter != null) {
|
|
|
+ //1禁止连麦 0否
|
|
|
+ presenter.syncMicMode(mRoomId, isEnable ? 1 : 0);
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SWITCH_MIC_MODE, isEnable);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUnderAllMic() {
|
|
|
+ if (mRoomMicMemberHelper != null) {
|
|
|
+ mRoomMicMemberHelper.delAllOnMicUser();
|
|
|
+ mRoomMicMemberHelper.delAllUserCache();
|
|
|
+ }
|
|
|
+ updateMicManagerData();
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_UNDER_ALL_MIC_MSG);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCloseAllMic(boolean isCloseAllMic) {
|
|
|
+ //全部闭麦
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.notifyLiveRoomCloseMic(mRoomId, isCloseAllMic);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!mLiveMicManagerDialog.isShowing()) {
|
|
|
+ mLiveMicManagerDialog.show();
|
|
|
+ }
|
|
|
+ mLiveMicManagerDialog.setApplyListData(mRoomMicMemberHelper.getOnApplyMicUsers());
|
|
|
+ mLiveMicManagerDialog.setOnMicListData(mRoomMicMemberHelper.getOnMicUsers());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除麦上用户
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ */
|
|
|
+ private void delOnMicUser(String userId) {
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (mRoomMicMemberHelper != null) {
|
|
|
+ mRoomMicMemberHelper.delOnMicUser(userId);
|
|
|
+ updateMicManagerData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加上麦用户
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ */
|
|
|
+ private void addOnMicUser(String userId) {
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ User user = mRoomMicMemberHelper.createUser(userId);
|
|
|
+ mRoomMicMemberHelper.addOnMicUser(user);
|
|
|
+ updateMicManagerData();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户判断消息目标是否是自己
|
|
|
+ *
|
|
|
+ * @param targetId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean isOwn(String targetId) {
|
|
|
+ return TextUtils.equals(targetId, mUserId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * \
|
|
|
+ * 是否是直播中
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean isLiveMode() {
|
|
|
+ return currentLiveMode == TTLiveConfig.LIVE_MODE_LIVE_START;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 直播暂停状态
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean isLivePause() {
|
|
|
+ return currentLiveStatus == TTLiveConfig.LIVE_STATUS_PAUSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncMemberCount(int count) {
|
|
|
+ //同步成员数量
|
|
|
+ Log.i("pq", "syncMemberCount" + count);
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+// setPeopleCount(count);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void liveRoomOffline() {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ToastUtil.getInstance().show(this, "直播已结束");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserLeaveRoom(TCUserLeaveMessage leaveRoomMessage) {
|
|
|
+ //用户离开直播间消息
|
|
|
+ if (presenter != null && mRoomMicMemberHelper != null) {
|
|
|
+ //删除连麦申请
|
|
|
+ if (leaveRoomMessage != null && leaveRoomMessage.getSendUserInfo() != null) {
|
|
|
+ String targetUserId = leaveRoomMessage.getSendUserInfo().getSendUserId();
|
|
|
+ if (!TextUtils.isEmpty(targetUserId)) {
|
|
|
+ delUser(targetUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserLeaveRoomUnNormal(TCUserLogOutUnNormalMessage leaveRoomMessage) {
|
|
|
+ //用户离开直播间消息
|
|
|
+ if (presenter != null && mRoomMicMemberHelper != null) {
|
|
|
+ //删除连麦申请
|
|
|
+ if (leaveRoomMessage != null && leaveRoomMessage.getSendUserInfo() != null) {
|
|
|
+ String targetUserId = leaveRoomMessage.getSendUserInfo().getSendUserId();
|
|
|
+ if (!TextUtils.isEmpty(targetUserId)) {
|
|
|
+ delUser(targetUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRemoteUserEnterRoom(String userId) {
|
|
|
+ if (!TextUtils.equals(mRoomInfoBean.speakerId, userId)) {
|
|
|
+ addOnMicUser(userId);
|
|
|
+ sendSyncOnMicStatusMessageAtOnce();
|
|
|
+ }
|
|
|
+ ArrayList<String> onMicUserIds = mRoomMicMemberHelper.getOnMicUserIds();
|
|
|
+ presenter.startMixStream(mUserId, mRoomId, onMicUserIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRemoteUserLeaveRoom(String userId, int reason) {
|
|
|
+ delOnMicUser(userId);
|
|
|
+ sendSyncOnMicStatusMessageAtOnce();
|
|
|
+ ArrayList<String> onMicUserIds = mRoomMicMemberHelper.getOnMicUserIds();
|
|
|
+ presenter.startMixStream(mUserId, mRoomId, onMicUserIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStatistics(TRTCStatistics statistics) {
|
|
|
+ if (statistics != null) {
|
|
|
+ int rtt = statistics.rtt;
|
|
|
+ if (rtt > 999) {
|
|
|
+ rtt = 999;
|
|
|
+ }
|
|
|
+ updateLiveDelayUI(rtt, isConnectImFailed ? 100 : statistics.upLoss);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getFriendInfoSuccess(FriendInfoBean data) {
|
|
|
+ if (isFinishing() || isDestroyed() || data == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ FriendInfoBean.FriendBean friend = data.friend;
|
|
|
+ if (friend == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ User user = new User();
|
|
|
+ user.setUserId(data.friendId);
|
|
|
+ user.setUserName(data.friendNickname);
|
|
|
+ user.setPortrait(data.friend.avatar);
|
|
|
+ mRoomMicMemberHelper.refreshUserInfo(user);
|
|
|
+ refreshMicData();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateLiveDelayUI(int delay, long lossRate) {
|
|
|
+ if (mHandler != null) {
|
|
|
+ mHandler.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (mTvLiveDelay == null || mIvLiveDelay == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (lossRate == 100) {
|
|
|
+ mTvLiveDelay.setText(getString(R.string.net_error_tip));
|
|
|
+ mIvLiveDelay.setImageResource(R.drawable.icon_live_delay_high);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mTvLiveDelay.setText(getString(R.string.live_delay_text, delay));
|
|
|
+ if (delay <= TTLiveConfig.LIVE_DELAY_NORMAL) {
|
|
|
+ //正常延迟模式
|
|
|
+ mIvLiveDelay.setImageResource(R.drawable.icon_live_delay_normal);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (delay <= TTLiveConfig.LIVE_DELAY_MIDDLE) {
|
|
|
+ //一般延迟模式
|
|
|
+ mIvLiveDelay.setImageResource(R.drawable.icon_live_delay_middle);
|
|
|
+ } else {
|
|
|
+ //一般延迟模式
|
|
|
+ mIvLiveDelay.setImageResource(R.drawable.icon_live_delay_high);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void delUser(String targetUserId) {
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mRoomMicMemberHelper.delOnMicUser(targetUserId);
|
|
|
+ mRoomMicMemberHelper.delApplyUser(targetUserId);
|
|
|
+ updateMicManagerData();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 切换主场景
|
|
|
+ */
|
|
|
+ private void switchMainUI() {
|
|
|
+ if (currentLiveMode == TTLiveConfig.LIVE_MODE_PREVIEW) {
|
|
|
+ mFlCreateOptions.setVisibility(View.VISIBLE);
|
|
|
+ mCsMainLayout.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ mFlCreateOptions.setVisibility(View.GONE);
|
|
|
+ mCsMainLayout.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void openPreViewMode() {
|
|
|
+ if (presenter != null) {
|
|
|
+ switchMainUI();
|
|
|
+ presenter.startLocalPreview(mVideoView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void enterLiveRoomError() {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ToastUtil.getInstance().show(this, "加入直播房间失败,请退出重试");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void showInputDialog() {
|
|
|
+ if (mRoomInfoBean == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mInputBarDialog == null) {
|
|
|
+ mInputBarDialog = new InputBarDialog(TCTeacherLiveRoomActivity.this, new InputBar.InputBarListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onClickSend(String message) {
|
|
|
+ //发送消息
|
|
|
+ if (TextUtils.isEmpty(message)) {
|
|
|
+ ToastUtil.getInstance().show(TCTeacherLiveRoomActivity.this, "消息不能为空");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (message.length() > TTLiveConfig.LIVE_MAX_INPUT_TEXT_LENGTH) {
|
|
|
+ ToastUtil.getInstance().show(TCTeacherLiveRoomActivity.this, "聊天消息需在40个字以内哦");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (LiveMessageHelper.isQuickAction()) {
|
|
|
+ ToastUtil.getInstance().show(TCTeacherLiveRoomActivity.this, "您说话太快啦");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ sendTextMessage(message);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @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) {
|
|
|
+ presenter.sendTextMessage(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ @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");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通知(开启/关闭)直播录像
|
|
|
+ *
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+ private void switchOpsLiveVideoMode(String type) {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.notifyOpenOpsLiveVideoAction(mRoomId, type, mUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步点赞数并且
|
|
|
+ */
|
|
|
+ private void syncAddLikeNum() {
|
|
|
+ if (mHandler != null) {
|
|
|
+ mHandler.removeCallbacks(mRunnable);
|
|
|
+ //10S发送一次同步点赞兼心跳
|
|
|
+ mHandler.postDelayed(mRunnable, SYNC_ADD_LIKE_TIME);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getMicUserInfo(String userId) {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.getUserInfoByUserId(userId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGroupAttributeChanged(String groupID, Map<String, String> groupAttributeMap) {
|
|
|
+ if (TextUtils.equals(groupID, mRoomId)) {
|
|
|
+ JSONObject jsonObject = new JSONObject(groupAttributeMap);
|
|
|
+ parseGroupAttribute(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getAllGroupCounterSuccess(Map<String, Long> map) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (map != null && map.size() > 0) {
|
|
|
+ //获取群点赞数
|
|
|
+ if (map.containsKey(TTLiveConfig.LIVE_ROOM_LIKES_KEY)) {
|
|
|
+ Long result = map.get(TTLiveConfig.LIVE_ROOM_LIKES_KEY);
|
|
|
+ if (result != null) {
|
|
|
+ updateAddLikeCountView(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGroupCounterChanged(String groupID, String key, long newValue) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.equals(groupID, mRoomId)) {
|
|
|
+ if (TextUtils.equals(TTLiveConfig.LIVE_ROOM_LIKES_KEY, key)) {
|
|
|
+ //点赞数同步
|
|
|
+ Log.i("pq", "likes newValue:" + newValue);
|
|
|
+ updateAddLikeCountView(newValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserMicStatusChange(TCUserMicStatusChangeMessage micStatusChangeMessage) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (micStatusChangeMessage != null) {
|
|
|
+ String targetUserId = micStatusChangeMessage.getUserId();
|
|
|
+ if (!TextUtils.isEmpty(targetUserId)) {
|
|
|
+ boolean muteMic = micStatusChangeMessage.isMuteMic();
|
|
|
+ Log.i("pq", "onUserMicStatusChange:" + targetUserId + "--isMuteMic:" + muteMic);
|
|
|
+ mRoomMicMemberHelper.refreshUserMicStatus(targetUserId, muteMic);
|
|
|
+ refreshMicData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onUserAudioAvailable(String userId, boolean available) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mRoomMicMemberHelper.refreshUserMicStatus(userId, !available);
|
|
|
+ refreshMicData();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getLiveCourseInfoSuccess(LiveCourseTimeInfo data) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (data != null && data.getCourseScheduleTimes() != null && data.getCourseScheduleTimes().size() > 0) {
|
|
|
+ LiveCourseCountTimeHelper.getInstance().setTimeInfoList(data.getCourseScheduleTimes());
|
|
|
+ long finishLimitTime = data.getAutoCloseNetworkRoomTime() * 60L * 1000;
|
|
|
+ LiveCourseCountTimeHelper.getInstance().setAutoCloseNetworkRoomTime(finishLimitTime);
|
|
|
+ this.serviceTimeStamp = data.getTimestamp();
|
|
|
+ startCountTime();
|
|
|
+ } else {
|
|
|
+ llCountTimeTip.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLiveForceKick(TCLiveForceKickMessage messageContent) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (messageContent != null) {
|
|
|
+ ArrayList<String> targetIds = messageContent.getTargetIds();
|
|
|
+ if (targetIds != null && targetIds.size() > 0) {
|
|
|
+ //判断个人
|
|
|
+// for (int i = 0; i < targetIds.size(); i++) {
|
|
|
+// boolean isContainerOwner = isOwn(targetIds.get(i));
|
|
|
+// if (isContainerOwner) {
|
|
|
+// pauseLive();
|
|
|
+// showLiveCourseStatusChangeTip(messageContent.getReason());
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// }
|
|
|
+ } else {
|
|
|
+ //全体
|
|
|
+ pauseLive();
|
|
|
+ showLiveCourseStatusChangeTip(messageContent.getReason());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLiveCourseTimeChange() {
|
|
|
+ if (presenter != null && !TextUtils.isEmpty(liveCourseId)) {
|
|
|
+ presenter.getLiveCourseInfo(liveCourseId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showLiveCourseStatusChangeTip(String tip) {
|
|
|
+ if (TextUtils.isEmpty(tip)) {
|
|
|
+ tip = "当前课程已调整,请退出直播间";
|
|
|
+ }
|
|
|
+ CommonConfirmDialog confirmDialog = new CommonConfirmDialog(this);
|
|
|
+ confirmDialog.show();
|
|
|
+ confirmDialog.setOnConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ confirmDialog.setContent(tip);
|
|
|
+ confirmDialog.hideCancel();
|
|
|
+ confirmDialog.setCancelable(false);
|
|
|
+ confirmDialog.setCanceledOnTouchOutside(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void refreshMicData() {
|
|
|
+ if (mLiveMicManagerDialog != null) {
|
|
|
+ mLiveMicManagerDialog.setOnMicListData(mRoomMicMemberHelper.getOnMicUsers());
|
|
|
+ }
|
|
|
+ if (llMicContainer != null) {
|
|
|
+ llMicContainer.refreshUIByUser(convertUserInfo(mRoomMicMemberHelper.getOnMicUsers()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getAllGroupAttributesSuccess(Object o) {
|
|
|
+ Log.i("pq", "getAllGroupAttributesSuccess:" + o.toString());
|
|
|
+ if (o == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = new JSONObject(o.toString());
|
|
|
+ parseGroupAttribute(jsonObject);
|
|
|
+ //获取麦克风禁止模式
|
|
|
+ getMuteAllMicStatus(jsonObject);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void parseGroupAttribute(JSONObject groupAttributeJson) {
|
|
|
+ Log.i("pq", "group:" + groupAttributeJson.toString());
|
|
|
+ if (groupAttributeJson != null) {
|
|
|
+// //点赞数
|
|
|
+// getLikesFromAttributes(groupAttributeJson);
|
|
|
+ //人数
|
|
|
+ getMemberCountFromAttributes(groupAttributeJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getMuteAllMicStatus(JSONObject groupAttributeJson) {
|
|
|
+ String muteAllMicStatus = groupAttributeJson.optString(TTLiveConfig.LIVE_ROOM_MIC_STATUS_MODE_KEY);
|
|
|
+ Log.i("pq", "groupAttribute muteAllMicStatus:" + muteAllMicStatus);
|
|
|
+ if (!TextUtils.isEmpty(muteAllMicStatus)) {
|
|
|
+ boolean result = TextUtils.equals(muteAllMicStatus, TTLiveConfig.STATUS_ON);
|
|
|
+ if (result) {
|
|
|
+ TTLiveConfig.MODE_LIVE_IS_CLOSE_MIC = 1;
|
|
|
+ } else {
|
|
|
+ TTLiveConfig.MODE_LIVE_IS_CLOSE_MIC = 0;
|
|
|
+ }
|
|
|
+ if (mLiveMicManagerDialog != null) {
|
|
|
+ mLiveMicManagerDialog.refreshMuteAllMicMode();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getLikesFromAttributes(JSONObject groupAttributeJson) {
|
|
|
+ String likes = groupAttributeJson.optString(TTLiveConfig.LIVE_ROOM_LIKES_KEY);
|
|
|
+ Log.i("pq", "likes:" + likes);
|
|
|
+ if (!TextUtils.isEmpty(likes)) {
|
|
|
+ try {
|
|
|
+ int i = Integer.parseInt(likes);
|
|
|
+ currentAddLikeCount = i;
|
|
|
+ updateAddLikeCountView(i);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getMemberCountFromAttributes(JSONObject groupAttributeMap) {
|
|
|
+ String member_online = groupAttributeMap.optString(TTLiveConfig.LIVE_ROOM_MEMBER_ONLINE_KEY);
|
|
|
+ Log.i("pq", "member_online:" + member_online);
|
|
|
+ if (!TextUtils.isEmpty(member_online)) {
|
|
|
+ try {
|
|
|
+ setPeopleCount(Integer.parseInt(member_online));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
+ if (isLiveMode()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.onKeyDown(keyCode, event);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private boolean isLiveCourse() {
|
|
|
+ return !TextUtils.isEmpty(liveCourseId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.notifyLeaveRoomAction();
|
|
|
+ presenter.notifyLiveRoomStatus(mRoomId, false);
|
|
|
+ presenter.release();
|
|
|
+ }
|
|
|
+ super.onDestroy();
|
|
|
+ if (mHandler != null) {
|
|
|
+ mHandler.removeCallbacksAndMessages(null);
|
|
|
+ }
|
|
|
+ SoftKeyboardUtil.unregisterSoftInputChangedListener(getWindow());
|
|
|
+ TRTCSdkManager.getInstance().release();
|
|
|
+ TCIMSdkManager.getInstance().quitGroup(mRoomId);
|
|
|
+ TCIMSdkManager.getInstance().release(mTIMSDKListener);
|
|
|
+ }
|
|
|
+}
|