package com.bokecc.dwlivedemo.activity;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static com.bokecc.livemodule.live.chat.adapter.LivePublicChatAdapter.CONTENT_IMAGE_COMPONENT;
import static com.bokecc.livemodule.live.chat.adapter.LivePublicChatAdapter.CONTENT_ULR_COMPONET;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bokecc.chatroom.pojo.bean.CCInteractionViewBean;
import com.bokecc.chatroom.pojo.bean.ChatConfig;
import com.bokecc.chatroom.pojo.bean.RoleConstrant;
import com.bokecc.chatroom.ui.CCChatView;
import com.bokecc.chatroom.ui.ChatBaseLayout;
import com.bokecc.chatroom.ui.listener.IEmojiLayoutListener;
import com.bokecc.commerce.CommerceUiListener;
import com.bokecc.commerce.pojo.CCGoodsModel;
import com.bokecc.commerce.view.CCGoodsListView;
import com.bokecc.commerce.view.CCRecommendGoodsView;
import com.bokecc.common.utils.Tools;
import com.bokecc.dwlivedemo.DWApplication;
import com.bokecc.dwlivedemo.R;
import com.bokecc.dwlivedemo.base.BaseActivity;
import com.bokecc.dwlivedemo.popup.ExitPopupWindow;
import com.bokecc.gson.Gson;
import com.bokecc.livemodule.live.DWLiveCoreHandler;
import com.bokecc.livemodule.live.DWLiveMoreFunctionListener;
import com.bokecc.livemodule.live.DWLiveRoomListener;
import com.bokecc.livemodule.live.chat.KeyboardHeightObserver;
import com.bokecc.livemodule.live.chat.KeyboardHeightProvider;
import com.bokecc.livemodule.live.intro.VerticalLiveIntroComponent;
import com.bokecc.livemodule.live.morefunction.announce.VerticalAnnounceLayout;
import com.bokecc.livemodule.live.video.LiveVideoView;
import com.bokecc.livemodule.utils.GlideCircleTransform;
import com.bokecc.livemodule.view.SizeUtils;
import com.bokecc.livemodule.view.VerticalChangeLineTextView;
import com.bokecc.livemodule.view.VerticalPortraitQualityTextView;
import com.bokecc.livemodule.view.WarpLinearLayout;
import com.bokecc.livemodule.view.like.HintLikeView;
import com.bokecc.livemodule.view.timer.DigitalTimerView;
import com.bokecc.livemodule.view.timer.TextViewUpdater;
import com.bokecc.sdk.mobile.live.BaseCallback;
import com.bokecc.sdk.mobile.live.DWLive;
import com.bokecc.sdk.mobile.live.listener.LiveChangeSourceListener;
import com.bokecc.sdk.mobile.live.pojo.InteractionOngoing;
import com.bokecc.sdk.mobile.live.pojo.LiveDigestBean;
import com.bokecc.sdk.mobile.live.pojo.LiveLineInfo;
import com.bokecc.sdk.mobile.live.pojo.LiveQualityInfo;
import com.bokecc.sdk.mobile.live.pojo.PrivateChatInfo;
import com.bokecc.sdk.mobile.live.pojo.RoomInfo;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

/**
 * Copyright (C), 20105-2021, 创盛视联数码科技（北京）有限公司
 * FileName:
 * Author:
 * Date: 2022/12/19
 * Description:
 */
public class VerticalLiveActivity extends BaseActivity implements KeyboardHeightObserver, DWLiveRoomListener, DWLiveMoreFunctionListener {

    private static final String TAG = "VerticalLiveActivity";

    /**
     * 直播带货商品列表
     */
    private final static int INTERACT_GOODS_LIST = 0;

    private Handler mHandler = new Handler(Looper.getMainLooper());

    View mRoot;

    private ImageView ivVerticalLogo;
    private TextView tvVerticalLiveTitle;
    private TextView tvVerticalLiveCount;
    private TextView tvVerticalLiveTips;

    private LiveVideoView mLiveVideoView;

    private boolean isDestroyed = false;
    private LinearLayout llVerticalVideoCon;

    // 聊天组件
//    VerticalLiveChatComponent mChatLayout;
    CCChatView ccChatView;
    private LinearLayout llVerticalChatCon;
    private ImageView ivVerticalLiveClose;

    private ExitPopupWindow mExitPopupWindow;

    // 软键盘控制
    private KeyboardHeightProvider keyboardHeightProvider;
    private HintLikeView hintLikeView;
    private RelativeLayout rlLiveInteractCon;
    private CCGoodsListView recommerceGoodslistView;
    private CCRecommendGoodsView recommerceGoodsView;
    private RelativeLayout rlVerticalMoreCon;
    private LinearLayout llVerticalMoreLine;
    private LinearLayout llVerticalMoreMute;
    private LinearLayout llVerticalMoreClear;
    private VerticalLiveIntroComponent mIntroComponent;
    private RelativeLayout rlVerticalIntroCon;
    private RelativeLayout rlVerticalTitleCon;
    private RelativeLayout rlVerticalTipsCon;
    private DigitalTimerView timerVerticalLive;
    private ImageView ivVerticalVideoBg;
    private TextView tvVerticalVideoTips;
    private LinearLayout llVerticalLiveCountdownCon;
    private RelativeLayout rlVerticalLiveBgLayoutCon;
    private LinearLayout llVerticalMoreHds;

    private List<LiveQualityInfo> videoQuality;
    private LiveQualityInfo currentQuality;
    private RelativeLayout rlVerticalHdsCon;
    private WarpLinearLayout llVerticalHdsList;
    private RelativeLayout rlVerticalLineCon;
    private WarpLinearLayout llVerticalLinesList;


    private ImageView ivVerticalMoreMute;
    private TextView tvVerticalMoreMute;
    private WarpLinearLayout llVerticalPanelCon;

    //静音模式开关
    private boolean isMute = false;
    //清屏模式开关
    private boolean isClearMode = false;
    private LinearLayout llVerticalClearBtn;
    private ImageView ivVerticalClearBtn;
    private RelativeLayout rlVerticalClearBtn;
    private DigitalTimerView timerVerticalLiveBig;
    private RelativeLayout rlVerticalTimerCoverCon;
    private VerticalAnnounceLayout announceLayout;
    private View viewVerticalTimerCover;
    private RelativeLayout rlVerticalTipsTextCon;
    private LinearLayout llVerticalMoreSensor;
    private TextView tvVerticalSensorTitle;

    private boolean isSensorOn = true;
    private ImageView ivVerticalSensor;
    private Gson gson;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.i(TAG, "onCreate");

//        requestFullScreenFeature();

        setStatusBarTransparent();
        setKeepScreenOn();




        setContentView(R.layout.activity_vertical_live);


        initView();

        keyboardHeightProvider = new KeyboardHeightProvider(this);
        mRoot.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                keyboardHeightProvider.start();
            }
        });

        initData();

        initListener();

        mLiveVideoView.start();

        boolean isDisAllowScreenShot = getIntent().getBooleanExtra("isDisAllowScreenShot",false);
        if (isDisAllowScreenShot){
            DWLive.getInstance().setAntiRecordScreen(this);
        }

    }



    private void initView() {
        mRoot = getWindow().getDecorView().findViewById(android.R.id.content);


        rlVerticalTitleCon = findViewById(R.id.rl_vertical_title_con);
        //logo
        ivVerticalLogo = findViewById(R.id.iv_vertical_logo);
        //直播间标题
        tvVerticalLiveTitle = findViewById(R.id.tv_vertical_live_title);
        //直播间人数
        tvVerticalLiveCount = findViewById(R.id.tv_vertical_live_count);
        //直播间公告
        tvVerticalLiveTips = findViewById(R.id.tv_vertical_live_tips);
        //公告文字容器
        rlVerticalTipsTextCon = findViewById(R.id.rl_vertical_tips_text_con);
        //视频容器
        llVerticalVideoCon = findViewById(R.id.ll_vertical_video_con);
        //聊天消息list
        llVerticalChatCon = findViewById(R.id.ll_vertical_chat_con);
        //倒计时和提示语的容器
        rlVerticalTimerCoverCon = findViewById(R.id.rl_vertical_timer_cover_con);
        //倒计时
        timerVerticalLive = findViewById(R.id.timer_vertical_live);
        //倒计时-大
        timerVerticalLiveBig = findViewById(R.id.timer_vertical_live_big);
        //视频背景图
        ivVerticalVideoBg = findViewById(R.id.iv_vertical_video_bg);
        //视频提示语
        tvVerticalVideoTips = findViewById(R.id.tv_vertical_video_tips);
        //倒计时容器
        llVerticalLiveCountdownCon = findViewById(R.id.ll_vertical_live_countdown_con);
        //半透明这招
        viewVerticalTimerCover = findViewById(R.id.view_vertical_timer_cover);
        //视频背景图容器，未开始直播显示
        rlVerticalLiveBgLayoutCon = findViewById(R.id.rl_vertical_live_bg_layout_con);


        //清屏按钮容器
        rlVerticalClearBtn = findViewById(R.id.rl_vertical_clear_btn);
        //清屏按钮-带文字
        llVerticalClearBtn = findViewById(R.id.ll_vertical_clear_btn);
        //清屏按钮-不带文字
        ivVerticalClearBtn = findViewById(R.id.iv_vertical_clear_btn);

        //推出直播
        ivVerticalLiveClose = findViewById(R.id.iv_vertical_live_close);
        // 弹出框界面
        mExitPopupWindow = new ExitPopupWindow(this);

        hintLikeView = findViewById(R.id.hint_like_view);

        //互动组件直播带货商品列表
        recommerceGoodslistView = findViewById(R.id.recommerce_goodslist_view);
        recommerceGoodsView = findViewById(R.id.recommerce_goods_view);

        //互动组件面板-展示直播带货列表、投票等互动组件界面
        rlLiveInteractCon = findViewById(R.id.rl_live_interact_con);
        //更多菜单
        rlVerticalMoreCon = findViewById(R.id.rl_vertical_more_con);
        //更多按钮容器
        llVerticalPanelCon = findViewById(R.id.ll_vertical_panel_con);
        //清晰度列表
        llVerticalHdsList = findViewById(R.id.ll_vertical_hds_list);
        //清晰度面板
        rlVerticalHdsCon = findViewById(R.id.rl_vertical_hds_con);
        //线路面板
        rlVerticalLineCon = findViewById(R.id.rl_vertical_line_con);
        //vr直播陀螺仪开关容器
        llVerticalMoreSensor = findViewById(R.id.ll_vertical_more_sensor);
        //陀螺仪图标
        ivVerticalSensor = findViewById(R.id.iv_vertical_sensor);
        //vr直播陀螺仪标题
        tvVerticalSensorTitle = findViewById(R.id.tv_vertical_sensor_title);
        //线路列表
        llVerticalLinesList = findViewById(R.id.ll_vertical_lines_list);
        //简介容器
        rlVerticalIntroCon = findViewById(R.id.rl_vertical_intro_con);
        //公告容器
        rlVerticalTipsCon = findViewById(R.id.rl_vertical_tips_con);
        //线路入口
        llVerticalMoreLine = findViewById(R.id.ll_vertical_more_line);
        //清晰度入口
        llVerticalMoreHds = findViewById(R.id.ll_vertical_more_hds);
        //静音入口
        llVerticalMoreMute = findViewById(R.id.ll_vertical_more_mute);
        //静音图片
        ivVerticalMoreMute = findViewById(R.id.iv_vertical_more_mute);
        //静音文字
        tvVerticalMoreMute = findViewById(R.id.tv_vertical_more_mute);

        //清屏入口
        llVerticalMoreClear = findViewById(R.id.ll_vertical_more_clear);
    }


    private void initData() {
        //初始化基本信息
        initLiveInfo();
        //初始化简介
        initIntroLayout();
        //初始化视频组件
        initVideoComponent();
        //初始化聊天
        initChatComponent();
        //初始化点赞
        initLikeComponent();
        //初始化直播带货
        initLiveCommerce();
        //初始化直播倒计时与背景图
        initLiveBackground(false);
        //重置更多菜单
        resetMorePanel();
        //初始化 vr 直播
        initVr();
    }

    private void initVr() {
        if (DWLiveCoreHandler.getInstance().isVrLive()){
            llVerticalMoreSensor.setVisibility(VISIBLE);
        }else {
            llVerticalMoreSensor.setVisibility(GONE);
        }

    }

    private void resetMorePanel() {
        //隐藏线路，清晰度，静音按钮
        llVerticalMoreLine.setVisibility(GONE);
        llVerticalMoreHds.setVisibility(GONE);
        llVerticalMoreMute.setVisibility(GONE);
        llVerticalMoreSensor.setVisibility(GONE);
    }

    private void initLiveBackground(boolean isEndStream) {

        llVerticalLiveCountdownCon.setVisibility(GONE);
        rlVerticalTimerCoverCon.setVisibility(GONE);
        timerVerticalLive.setVisibility(GONE);
        timerVerticalLiveBig.setVisibility(GONE);

        if (DWLiveCoreHandler.getInstance().getRoomInfo()!=null){
            RoomInfo roomInfo = DWLiveCoreHandler.getInstance().getRoomInfo();
            boolean hasBg = false;
            String bgUrl = roomInfo.getPlayerBackgroundImageUri();
            if (!TextUtils.isEmpty(bgUrl)){
                hasBg = true;
                Glide.with(this).load(bgUrl).into(ivVerticalVideoBg);
            }

            boolean hasTips = false;
            String videoTips = roomInfo.getPlayerBackgroundHint();
            if (!TextUtils.isEmpty(videoTips)){
                hasTips = true;
                rlVerticalTimerCoverCon.setVisibility(VISIBLE);
                tvVerticalVideoTips.setText(videoTips);
            }
            int openCountDown = roomInfo.getOpenLiveCountdown();
            if (openCountDown==1&&!isEndStream){
                long time = roomInfo.getLiveCountdown()*1000L;
                if (time>0){
                    rlVerticalTimerCoverCon.setVisibility(VISIBLE);
                    viewVerticalTimerCover.setVisibility(VISIBLE);
                    if (hasBg){
                        if (!hasTips){
                            //展示 距开播
                            tvVerticalVideoTips.setText("");
                            //移除遮罩
                            viewVerticalTimerCover.setVisibility(GONE);
                        }
                        llVerticalLiveCountdownCon.setVisibility(VISIBLE);
                        timerVerticalLive.setVisibility(VISIBLE);
                        timerVerticalLive.setSuffixView(R.layout.item_group_buy_timer_spliter,null);
                        timerVerticalLive.setDayTimeView(R.layout.item_vertical_timer_day_text,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,SizeUtils.dp2px(this,18)));
                        timerVerticalLive.setHourTimeView(R.layout.item_vertical_timer_hour_text,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,SizeUtils.dp2px(this,18)));
                        timerVerticalLive.setMinTimeView(R.layout.item_vertical_timer_min_text,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,SizeUtils.dp2px(this,18)));
                        timerVerticalLive.setSecTimeView(R.layout.item_vertical_timer_sec_text,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,SizeUtils.dp2px(this,18)));

                        timerVerticalLive.setViewUpdater(new TextViewUpdater(R.id.text1,R.id.text2));
                        timerVerticalLive.setEndListener(new DigitalTimerView.EndListener() {
                            @Override
                            public void onCall(boolean end) {

                            }
                        });
                        timerVerticalLive.start(time);

                    }else {
                        if (!hasTips){
                            //展示 距开播
                            tvVerticalVideoTips.setText("距开播");
                        }
                        timerVerticalLiveBig.setVisibility(VISIBLE);
                        timerVerticalLiveBig.setSuffixView(R.layout.item_vertical_timer_spliter_big,new ViewGroup.LayoutParams(SizeUtils.dp2px(this,20),SizeUtils.dp2px(this,40)));
                        timerVerticalLiveBig.setDayTimeView(R.layout.item_vertical_timer_day_text_big,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
                        timerVerticalLiveBig.setHourTimeView(R.layout.item_vertical_timer_hour_text_big,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
                        timerVerticalLiveBig.setMinTimeView(R.layout.item_vertical_timer_min_text_big,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
                        timerVerticalLiveBig.setSecTimeView(R.layout.item_vertical_timer_sec_text_big,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));

                        timerVerticalLiveBig.setViewUpdater(new TextViewUpdater(R.id.text1,R.id.text2));
                        timerVerticalLiveBig.setEndListener(new DigitalTimerView.EndListener() {
                            @Override
                            public void onCall(boolean end) {

                            }
                        });
                        timerVerticalLiveBig.start(time);
                    }

                }else {
                    if (!hasTips){
                        rlVerticalTimerCoverCon.setVisibility(VISIBLE);
                        //展示 距开播
                        tvVerticalVideoTips.setText(isEndStream?"直播已结束":"直播等待中");
                    }
                }

            }else {
                if (!hasTips){
                    rlVerticalTimerCoverCon.setVisibility(VISIBLE);
                    //展示 距开播
                    tvVerticalVideoTips.setText(isEndStream?"直播已结束":"直播等待中");
                }
            }


        }

    }


    // <editor-fold defaultstate="collapsed" desc="生命周期">

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(TAG, "onPause");
        keyboardHeightProvider.clearObserver();
        if (isFinishing()) {
            selfDestroy();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
//        keyboardHeightProvider.addKeyboardHeightObserver(mChatLayout);
        keyboardHeightProvider.addKeyboardHeightObserver(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy");

        selfDestroy();
    }


    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="私有方法">

    //添加清晰度textview
    private void addQualityTextView(VerticalPortraitQualityTextView qualityTextView) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(SizeUtils.dp2px(this,105), SizeUtils.dp2px(this,35));
        llVerticalHdsList.addView(qualityTextView, params);

        // 设置Item点击监听
        qualityTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                handleQualityItemClick(v);
            }
        });
    }
    // 处理清晰度的点击事件
    private void handleQualityItemClick(View v) {
        final VerticalPortraitQualityTextView qualityTextView = (VerticalPortraitQualityTextView) v;
        showQualityPanel(false);
        if (qualityTextView.isChecked()) {
            return;
        }
        setQualityCheckView(qualityTextView);
        DWLiveCoreHandler instance = DWLiveCoreHandler.getInstance();
        if (instance != null) {
            instance.changeQuality(qualityTextView.getQuality(), new LiveChangeSourceListener() {
                @Override
                public void onChange(int success) {
                    if (success == 0) {
                        toastOnUiThread("清晰度已切换至"+qualityTextView.getDesc());
                        setQuality(1);
                    }
                    if (success == 0) {
                        qualityCheckedView = qualityTextView;
                    } else {
                        setQualityCheckView(qualityCheckedView);
                        toastOnUiThread("切换清晰度失败，请重试");
                    }
                }
            });
        }
    }

    //动态设置清晰度
    private void setQuality(int quality) {
        for (int i = 0; i < llVerticalHdsList.getChildCount(); i++) {
            VerticalPortraitQualityTextView childAt = (VerticalPortraitQualityTextView) llVerticalHdsList.getChildAt(i);
            if (childAt.getQuality() == quality) {
                childAt.setChecked(true);
                qualityCheckedView = childAt;
            } else {
                childAt.setChecked(false);
            }

        }
    }

    // 设置默认选项
    private void setQualityCheckView(VerticalPortraitQualityTextView qualityTextView) {
        for (int i = 0; i < llVerticalHdsList.getChildCount(); i++) {
            VerticalPortraitQualityTextView childAt = (VerticalPortraitQualityTextView) llVerticalHdsList.getChildAt(i);
            childAt.setChecked(childAt.getQuality() == qualityTextView.getQuality());
        }
    }

    private VerticalChangeLineTextView lineCheckedView;

    //添加线路
    private void addLineView(int length, int indexNum) {
        if (length <= 0) {
            return;
        }
        for (int i = 0; i < length; i++) {
            VerticalChangeLineTextView changeLineTextView = new VerticalChangeLineTextView(this, i);
            // 设置选中
            if (indexNum == i) {
                changeLineTextView.setChecked(true, true);
                lineCheckedView = changeLineTextView;
            } else {
                changeLineTextView.setChecked(false, true);
            }

            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(SizeUtils.dp2px(this,105), SizeUtils.dp2px(this,35));
            llVerticalLinesList.addView(changeLineTextView, params);
            // 设置点击监听
            changeLineTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    handleLineItemClick(v);
                }
            });
        }

    }

    //处理线路点击事件
    private void handleLineItemClick(View v) {
        final VerticalChangeLineTextView changeLineTextView = (VerticalChangeLineTextView) v;
        if (changeLineTextView.isChecked()) {
            return;
        }
        setLineCheckView(changeLineTextView);
        DWLiveCoreHandler instance = DWLiveCoreHandler.getInstance();
        if (instance != null) {
            final int line =  changeLineTextView.getLine();
            instance.changeLine(line, new LiveChangeSourceListener() {
                @Override
                public void onChange(int success) {
                    if (success == 0) {
                        setLine(line);
                    }
                    if (success == LiveChangeSourceListener.SUCCESS) {
                        lineCheckedView = changeLineTextView;
                        toastOnUiThread("线路切换成功");
                        if (isMute){
                            isMute = false;
                            ivVerticalMoreMute.setImageResource(R.drawable.icon_vertical_live_volume_disable);
                            tvVerticalMoreMute.setText("静音");
                        }
                    } else {
                        setLineCheckView(lineCheckedView);
                        toastOnUiThread("线路切换失败");

                    }
                }
            });
        }
        showLinePanel(false);
    }

    // 设置默认选项
    private void setLineCheckView(VerticalChangeLineTextView changeLineTextView) {
        if (changeLineTextView == null) {return;}
        for (int i = 0; i < llVerticalLinesList.getChildCount(); i++) {
            VerticalChangeLineTextView childAt = (VerticalChangeLineTextView) llVerticalLinesList.getChildAt(i);
            childAt.setChecked(childAt.getLine() == changeLineTextView.getLine(), true);
        }
    }

    //添加直播线路
    public void addLines(List<LiveLineInfo> lines, int indexNum) {
        if (lines == null){
            return;
        }
        llVerticalLinesList.removeAllViews();
        addLineView(lines.size(), indexNum);
    }


    //设置当前线路
    public void setLine(int line) {
        for (int i = 0; i < llVerticalLinesList.getChildCount(); i++) {
            VerticalChangeLineTextView childAt = (VerticalChangeLineTextView) llVerticalLinesList.getChildAt(i);
            if (childAt.getLine() == line) {
                childAt.setChecked(true, true);
                lineCheckedView = childAt;
            } else {
                childAt.setChecked(false, true);
            }
        }
    }
    private void selfDestroy() {
        if (isDestroyed) {
            return;
        }
        Log.i(TAG, "selfDestroy");
        // 回收资源
        isDestroyed = true;

        mHandler.removeCallbacksAndMessages(null);


        if (keyboardHeightProvider != null) {
            keyboardHeightProvider.close();
        }
        if (hintLikeView != null) {
            hintLikeView.destroy();
        }
        if (ccChatView!=null){
            ccChatView.onDestroy();
        }

        if (timerVerticalLive!=null){
            timerVerticalLive.onDestroy();
        }

        if (mLiveVideoView!=null){
            mLiveVideoView.stop();
        }
        if (mLiveVideoView!=null){
            mLiveVideoView.destroy();
        }

        //注销互动组件直播带货浮窗
        if (recommerceGoodsView!=null){
            recommerceGoodsView.release();
        }
        //注销互动组件直播带货列表
        if (recommerceGoodslistView!=null){
            recommerceGoodslistView.release();
        }

    }

    private void showExitDialog() {
        if (mExitPopupWindow != null) {
            mExitPopupWindow.setConfirmExitRoomListener(new ExitPopupWindow.ConfirmExitRoomListener() {
                @Override
                public void onConfirmExitRoom() {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            exit();
                        }
                    });
                }
            });
            mExitPopupWindow.show(mRoot);
        }
    }


    // 退出房间
    private void exit() {
        mExitPopupWindow.dismiss();
        finish();
    }
    private void setKeepScreenOn() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    private void setStatusBarTransparent() {
        //设置状态栏透明
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        } else {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

    // 初始化简介布局区域
    private void initIntroLayout() {
        mIntroComponent = new VerticalLiveIntroComponent(this);
        rlVerticalIntroCon.addView(mIntroComponent);
    }

    private void showMorePanel(boolean show){
        if (show){
            hideAllMenu();
            rlVerticalMoreCon.setVisibility(VISIBLE);
            //计算排版
            int width = getResources().getConfiguration().screenWidthDp;
            for (int i = 0; i < llVerticalPanelCon.getChildCount(); i++) {
                View view = llVerticalPanelCon.getChildAt(i);
                ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                int dp = width/4;
                layoutParams.width = SizeUtils.dp2px(this,dp);
                view.setLayoutParams(layoutParams);
            }
        }else {
            rlVerticalMoreCon.setVisibility(GONE);
        }
    }

    private void showIntro(boolean show){
        if (show){
            hideAllMenu();
            rlVerticalIntroCon.setVisibility(VISIBLE);
        }else {
            rlVerticalIntroCon.setVisibility(GONE);
        }
    }

    private void hideAllMenu(){
        //隐藏简介
        rlVerticalIntroCon.setVisibility(GONE);
        //隐藏公告
        rlVerticalTipsCon.setVisibility(GONE);
        //隐藏更多
        rlVerticalMoreCon.setVisibility(GONE);
    }

    private void initLiveCommerce() {

        if (DWLiveCoreHandler.getInstance().getInteractionConfigure() != null && DWLiveCoreHandler.getInstance().getInteractionConfigure().getLiveCommerce() > 0) {
            //获取token
            DWLiveCoreHandler.getInstance().getInteractionToken(new BaseCallback<String>() {
                @Override
                public void onError(String error) {

                }

                @Override
                public void onSuccess(final String token) {
                    //初始化商品列表
                    Intent intent = getIntent();
                    if (intent != null) {
                        String userId = "";
                        try {
                            //从登录信息中获取（上个界面传入）
                            userId = intent.getStringExtra("userId");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        String roomId = "";
                        try {
                            roomId = intent.getStringExtra("roomId");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        String viewerId = "";
                        try {
                            viewerId = DWLiveCoreHandler.getInstance().getViewer().getId();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        String nickName = "";
                        try {
                            //从登录信息中获取（上个界面传入）
                            nickName = getIntent().getStringExtra("nickName");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (!TextUtils.isEmpty(userId) && !TextUtils.isEmpty(roomId)) {
                            recommerceGoodslistView.initialize(token, userId, roomId, viewerId, nickName, new CommerceUiListener() {
                                @Override
                                public void onClose() {
                                    recommerceGoodslistView.setVisibility(GONE);
                                    rlLiveInteractCon.setVisibility(GONE);
                                }

                                @Override
                                public void onCommercePush(String s) {

                                }

                                @Override
                                public void onProductLink(String s) {
                                    if (DWApplication.getInstance().getChannelMessageListener()==null){
                                        Tools.openSystemBrowser(VerticalLiveActivity.this, s);
                                    }
                                }

                                @Override
                                public void onGoodsInfo(CCGoodsModel ccGoodsModel) {
                                    if (ccGoodsModel==null){
                                        return;
                                    }
                                    if (gson==null){
                                        gson = new Gson();
                                    }
                                    DWApplication.getInstance().onMessage(gson.toJson(ccGoodsModel));
                                }
                            });
                        }


                    }


                    //初始化悬浮窗
                    DWLive.getInstance().getInteractiveOngoing(new BaseCallback<List<InteractionOngoing>>() {
                        @Override
                        public void onError(String error) {

                        }

                        @Override
                        public void onSuccess(List<InteractionOngoing> ongoingList) {
                            //是否正在进行
                            boolean isOngoing = false;
                            String ongoingId = "";
                            if (ongoingList != null) {
                                for (int i = 0; i < ongoingList.size(); i++) {
                                    if (ongoingList.get(i).getType() == InteractionOngoing.TYPE_INTERACT_LIVE_COMMERCE) {
                                        isOngoing = true;
                                        ongoingId = ongoingList.get(i).getId();
                                        break;
                                    }
                                }
                            }
                            String userId = getIntent().getStringExtra("userId");
                            String roomId = getIntent().getStringExtra("roomId");

                            String viewerId = "";
                            try {
                                viewerId = DWLiveCoreHandler.getInstance().getViewer().getId();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                            String nickName = "";
                            try {
                                //从登录信息中获取（上个界面传入）
                                nickName = getIntent().getStringExtra("nickName");
                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                            recommerceGoodsView.initialize(token, userId, roomId, viewerId, nickName, new CommerceUiListener() {
                                @Override
                                public void onClose() {
                                    recommerceGoodsView.setVisibility(GONE);
                                }

                                @Override
                                public void onCommercePush(String s) {
                                    recommerceGoodsView.setVisibility(VISIBLE);
                                    recommerceGoodsView.show(s);
                                }

                                @Override
                                public void onProductLink(String s) {
                                    if (DWApplication.getInstance().getChannelMessageListener()==null){
                                        Tools.openSystemBrowser(VerticalLiveActivity.this, s);
                                    }
                                }

                                @Override
                                public void onGoodsInfo(CCGoodsModel ccGoodsModel) {
                                    if (ccGoodsModel==null){
                                        return;
                                    }
                                    if (gson==null){
                                        gson = new Gson();
                                    }
                                    DWApplication.getInstance().onMessage(gson.toJson(ccGoodsModel));
                                }
                            });
                            if (isOngoing) {
                                if (ongoingId != null && ongoingId.length() > 0) {
                                    recommerceGoodsView.show(ongoingId);
                                }
                                recommerceGoodsView.setVisibility(VISIBLE);
                            } else {
                                recommerceGoodsView.setVisibility(GONE);
                            }
                        }
                    });

                }
            });


        }
    }

    private void initLikeComponent() {
        if (DWLiveCoreHandler.getInstance().getInteractionConfigure() != null && DWLiveCoreHandler.getInstance().getInteractionConfigure().getLikeSwitch() > 0) {
            hintLikeView.initConfig();
        } else {
            hintLikeView.setVisibility(GONE);
        }
    }

    private void initChatComponent() {
//        mChatLayout = new VerticalLiveChatComponent(this);
        ccChatView = new CCChatView(this, ChatBaseLayout.STYLE_DARK);
//        mChatLayout.setOnClickBottomStatusListener(onClickBottomStatusListener);
//        mChatLayout.setPopView(mRoot);
        //initChatView();
        llVerticalChatCon.addView(ccChatView);

        String accountId = "";
        String userId = "";
        String roomId = "";
        String nickName = "";
        String avatar = "";
        String sessionId = "";
        try {
            //从登录信息中获取（上个界面传入）
            accountId = getIntent().getStringExtra("userId");
            userId = DWLiveCoreHandler.getInstance().getViewer().getId();
            roomId = getIntent().getStringExtra("roomId");
            nickName = DWLiveCoreHandler.getInstance().getViewer().getName();
            avatar = DWLiveCoreHandler.getInstance().getViewer().getAvatar();
            sessionId = DWLiveCoreHandler.getInstance().getViewer().getKey();
        } catch (Exception e) {
            e.printStackTrace();
        }

        String business = "2001";
        if (DWLiveCoreHandler.getInstance().getLiveSceneMode() == LiveDigestBean.SCENE_SEMINAR) {
            business = "3001";
        }
        int isSeminar = DWLiveCoreHandler.getInstance().getLiveSceneMode();

        ccChatView.showPrivateChatButton(false);

        ccChatView.initialize(new ChatConfig()
                .setAccountId(accountId)
                .setRoomId(roomId)
                .setUserId(userId)
                .setBusinessLine(business)
                .setRole(RoleConstrant.student)
                .setNickName(nickName)
                .setAvatar(avatar)
                .setIsSeminar(isSeminar)
                .setSessionId(sessionId)
                .setChatClient(DWLive.getInstance())
        );
        int commerceSwitch = DWLiveCoreHandler.getInstance().getInteractSwitch(DWLiveCoreHandler.INTERACT_COMMERCE);
        List<CCInteractionViewBean> ccInteractionViewBeanList = new ArrayList<>();

        if (commerceSwitch > 0) {
            CCInteractionViewBean ccInteractionViewBean = new CCInteractionViewBean("", R.drawable.icon_vertical_live_shop_circle, R.drawable.icon_vertical_live_shop_circle, false);
            ccInteractionViewBean.setOnClickListener(new CCInteractionViewBean.OnClickListener() {
                @Override
                public void onClick(CCInteractionViewBean ccInteractionViewBean) {
                    showInteractPanel(INTERACT_GOODS_LIST);
                }
            });
            ccInteractionViewBeanList.add(ccInteractionViewBean);
        }

        CCInteractionViewBean moreBtn = new CCInteractionViewBean("", R.drawable.icon_vertical_live_more_circle, R.drawable.icon_vertical_live_more_circle, false);
        moreBtn.setOnClickListener(new CCInteractionViewBean.OnClickListener() {
            @Override
            public void onClick(CCInteractionViewBean ccInteractionViewBean) {
                showMorePanel(true);
            }
        });
        ccInteractionViewBeanList.add(moreBtn);

        ccChatView.addInteractionView(ccInteractionViewBeanList);


        ccChatView.showMoreButton(false);

        List<CCInteractionViewBean> moreViewList = new ArrayList<>();
        //添加图标到聊天室更多按钮: 礼物、红包记录、投票记录、问卷
        int giftSwitch = DWLiveCoreHandler.getInstance().getInteractSwitch(DWLiveCoreHandler.INTERACT_GIFT);

        if (giftSwitch > 0) {
            CCInteractionViewBean ccInteractionViewBean = new CCInteractionViewBean(" 礼物", R.drawable.icon_interact_gift_enter, R.drawable.icon_interact_gift_enter, false);
            ccInteractionViewBean.setOnClickListener(new CCInteractionViewBean.OnClickListener() {
                @Override
                public void onClick(CCInteractionViewBean ccInteractionViewBean) {
//                    if (giftListView != null) {
//                        giftListView.setVisibility(VISIBLE);
//                    }
                }
            });
            moreViewList.add(ccInteractionViewBean);
        }
        if (DWLiveCoreHandler.getInstance().getInteractSwitch(DWLiveCoreHandler.INTERACT_RED_PACKET) > 0) {
            CCInteractionViewBean ccInteractionViewBean = new CCInteractionViewBean("红包记录", R.drawable.icon_interact_red_enter, R.drawable.icon_interact_red_enter, false);
            ccInteractionViewBean.setOnClickListener(new CCInteractionViewBean.OnClickListener() {
                @Override
                public void onClick(CCInteractionViewBean ccInteractionViewBean) {
//                    showRed();
                }
            });
            moreViewList.add(ccInteractionViewBean);
        }
        if (DWLiveCoreHandler.getInstance().getInteractSwitch(DWLiveCoreHandler.INTERACT_VOTE) > 0) {
            CCInteractionViewBean ccInteractionViewBean = new CCInteractionViewBean("投票记录", R.drawable.icon_interact_vote_enter, R.drawable.icon_interact_vote_enter, false);
            ccInteractionViewBean.setOnClickListener(new CCInteractionViewBean.OnClickListener() {
                @Override
                public void onClick(CCInteractionViewBean ccInteractionViewBean) {
//                    showVote();
                }
            });
            moreViewList.add(ccInteractionViewBean);
        }
        if (DWLiveCoreHandler.getInstance().getInteractSwitch(DWLiveCoreHandler.INTERACT_QUESTIONNAIRE) > 0) {
            CCInteractionViewBean ccInteractionViewBean = new CCInteractionViewBean("问卷", R.drawable.icon_interact_questionnaire_enter, R.drawable.icon_interact_questionnaire_enter, false);
            ccInteractionViewBean.setOnClickListener(new CCInteractionViewBean.OnClickListener() {
                @Override
                public void onClick(CCInteractionViewBean ccInteractionViewBean) {
//                    showQuestionnaire(false);
                }
            });
            moreViewList.add(ccInteractionViewBean);
        }
        ccChatView.setInteractionDialogData(moreViewList);

        ccChatView.setEmojiClickListener(new IEmojiLayoutListener() {
            @Override
            public void change(boolean b) {
                if (b) {
                    //如果有点赞开关，暂时隐藏点赞按钮
                    hintLikeView.setVisibility(GONE);
                } else {
                    showLikeView(true);
                }
            }

        });




//        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mChatLayout.getLayoutParams();
//        layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
//        layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
//        mChatLayout.setLayoutParams(layoutParams);
//        mChatLayout.setGravity(Gravity.BOTTOM);
//        mChatLayout.setOnClickBottomStatusListener(new VerticalLiveChatComponent.ClickListener() {
//            @Override
//            public void onShopClick() {
//                showInteractPanel(INTERACT_GOODS_LIST);
//                recommerceGoodslistView.flushList();
//            }
//
//            @Override
//            public void onMoreClick() {
//                showMorePanel(true);
//            }
//
//        });
//        mChatLayout.setBarrageLayout(mLiveRoomLayout.getLiveBarrageLayout());
//        mChatLayout.setOnChatComponentClickListener(new OnChatComponentClickListener() {
//            @Override
//            public void onClickChatComponent(Bundle bundle) {
//                if (bundle == null) {
//                    return;
//                }
//                String type = bundle.getString("type");
//                if (CONTENT_IMAGE_COMPONENT.equals(type)) {
//                    Intent intent = new Intent(VerticalLiveActivity.this, ImageDetailsActivity.class);
//                    intent.putExtra("imageUrl", bundle.getString("url"));
//                    startActivity(intent);
//                } else if (CONTENT_ULR_COMPONET.equals(type)) {
//                    Uri uri = Uri.parse(bundle.getString("url"));
//                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//                    startActivity(intent);
//                }
//
//
//            }
//        });
    }

    private void initVideoComponent() {
        mLiveVideoView = new LiveVideoView(this);
        mLiveVideoView.setVerticalMode();
        llVerticalVideoCon.addView(mLiveVideoView);
    }


    private void initListener() {
        // 设置监听
        DWLiveCoreHandler dwLiveCoreHandler = DWLiveCoreHandler.getInstance();


        if (dwLiveCoreHandler != null) {
            dwLiveCoreHandler.setDwLiveRoomListener(this);
            dwLiveCoreHandler.setDwLiveMoreFunctionListener(this);
        }

        rlLiveInteractCon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rlLiveInteractCon.setVisibility(GONE);
            }
        });

        rlVerticalMoreCon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showMorePanel(false);
            }
        });

        rlVerticalIntroCon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showIntro(false);
            }
        });

        rlVerticalTitleCon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showIntro(true);
            }
        });

        llVerticalMoreHds.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showMorePanel(false);
                showQualityPanel(true);
            }
        });

        rlVerticalHdsCon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showQualityPanel(false);
            }
        });

        llVerticalMoreLine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showMorePanel(false);
                showLinePanel(true);
            }
        });
        rlVerticalLineCon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showLinePanel(false);
            }
        });


        ivVerticalLiveClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showExitDialog();
            }
        });

        rlVerticalTipsCon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showTips(false);
            }
        });

        rlVerticalTipsTextCon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showTips(true);
            }
        });

        llVerticalMoreMute.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isMute = !isMute;
                if (isMute){
                    ivVerticalMoreMute.setImageResource(R.drawable.icon_vertical_live_volume_enable);
                    tvVerticalMoreMute.setText("解除静音");
                    DWLiveCoreHandler.getInstance().setVolume(0f);
                    toastOnUiThread("解除静音");

                }else {
                    ivVerticalMoreMute.setImageResource(R.drawable.icon_vertical_live_volume_disable);
                    tvVerticalMoreMute.setText("静音");
                    //静音
                    DWLiveCoreHandler.getInstance().setVolume(1f);
                    toastOnUiThread("静音");

                }
            }
        });
        llVerticalMoreClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showMorePanel(false);
                showClearMode(true);
            }
        });

        rlVerticalClearBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showClearMode(false);
            }
        });

        //vr直播陀螺仪按钮事件
        llVerticalMoreSensor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isSensorOn = !isSensorOn;
                DWLiveCoreHandler.getInstance().enableVrSensorControl(isSensorOn);
                toastOnUiThread(isSensorOn?"陀螺仪已开启，可晃动手机或手势拖动改变视角":"陀螺仪已关闭，可手势拖动改变视角");
                tvVerticalSensorTitle.setText(isSensorOn?"陀螺仪开启":"陀螺仪关闭");
                ivVerticalSensor.setImageResource(isSensorOn?R.drawable.icon_vr_sensor_on_vertical:R.drawable.icon_vr_sensor_off_vertical);
            }
        });

    }


    private boolean isInAnim = false;
    private void showClearMode(boolean show){
        if (show){
            isClearMode = true;
            toastOnUiThread("已进入清屏模式");
            //开启清屏模式
            //隐藏header
            rlVerticalTitleCon.setVisibility(GONE);
            //隐藏公告
            showHeadTips(false);
            //隐藏点赞
            showLikeView(false);
            //隐藏聊天区
            llVerticalChatCon.setVisibility(GONE);
            //隐藏退出按钮
            ivVerticalLiveClose.setVisibility(GONE);
            //显示清屏按钮
            rlVerticalClearBtn.setVisibility(VISIBLE);
            //显示清屏按钮状态1
            llVerticalClearBtn.setVisibility(VISIBLE);
            //隐藏清屏按钮状态2
            ivVerticalClearBtn.setVisibility(GONE);
            //2s后显示清屏按钮状态2
            //动画
            TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0.6f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f);
            translateAnimation.setDuration(500);
            translateAnimation.setStartOffset(3000);

            translateAnimation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    Log.i(TAG, "onAnimationStart: 1");
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    Log.i(TAG, "onAnimationEnd: 2");
                    if (isClearMode) {
                        llVerticalClearBtn.setVisibility(GONE);
                        ivVerticalClearBtn.setVisibility(VISIBLE);
                    }
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    Log.i(TAG, "onAnimationRepeat: 3");

                }
            });
            llVerticalClearBtn.setAnimation(translateAnimation);
            translateAnimation.start();



        }else {
            isClearMode = false;
            toastOnUiThread("已退出清屏模式");
            //关闭清屏
            //显示header
            rlVerticalTitleCon.setVisibility(VISIBLE);
            //显示公告-存在公告显示
            showHeadTips(true);
            //显示点赞
            showLikeView(true);
            //显示聊天区
            llVerticalChatCon.setVisibility(VISIBLE);
            //显示退出按钮
            ivVerticalLiveClose.setVisibility(VISIBLE);
            //隐藏清屏按钮
            rlVerticalClearBtn.setVisibility(GONE);
        }
    }

    private void showLikeView(boolean show) {
        if (show&&(DWLiveCoreHandler.getInstance().getInteractionConfigure() != null && DWLiveCoreHandler.getInstance().getInteractionConfigure().getLikeSwitch() > 0)){
            hintLikeView.setVisibility(VISIBLE);

        }else {
            hintLikeView.setVisibility(GONE);
        }
    }

    private void showQualityPanel(boolean show) {
        if (show){
            rlVerticalHdsCon.setVisibility(VISIBLE);
        }else {
            rlVerticalHdsCon.setVisibility(GONE);
        }
    }
    private void showLinePanel(boolean show) {
        if (show){
            rlVerticalLineCon.setVisibility(VISIBLE);
        }else {
            rlVerticalLineCon.setVisibility(GONE);
        }
    }


    private void initLiveInfo() {

        //是否展示直播人数
        boolean showCount = DWLiveCoreHandler.getInstance().isShowUserCount();
        if (showCount) {
            tvVerticalLiveCount.setVisibility(View.VISIBLE);
        } else {
            tvVerticalLiveCount.setVisibility(GONE);
        }
        announceLayout = new VerticalAnnounceLayout(this);
        announceLayout.setClickListener(new VerticalAnnounceLayout.ClickListener() {
            @Override
            public void onCloseClick() {
                showTips(false);
            }
        });
        rlVerticalTipsCon.addView(announceLayout);
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) announceLayout.getLayoutParams();
        layoutParams.height = SizeUtils.dp2px(this,300);
        announceLayout.setLayoutParams(layoutParams);

        if (DWLive.getInstance() != null && !TextUtils.isEmpty(DWLive.getInstance().getAnnouncement())) {
            tvVerticalLiveTips.setText(DWLive.getInstance().getAnnouncement());
            tvVerticalLiveTips.setSelected(true);
            showHeadTips(true);
        }else {
            showHeadTips(false);
        }

        String iconUrl = DWLiveCoreHandler.getInstance().getLiveIcon();
        if (!TextUtils.isEmpty(iconUrl)){
            ivVerticalLogo.setVisibility(VISIBLE);
            Glide.with(this).load(iconUrl).transform(new GlideCircleTransform()).into(ivVerticalLogo);
        }else {
            ivVerticalLogo.setVisibility(GONE);
        }



    }

    private void showHeadTips(boolean show){
        if (show&&(DWLive.getInstance() != null && !TextUtils.isEmpty(DWLive.getInstance().getAnnouncement()))){
            tvVerticalLiveTips.setVisibility(VISIBLE);
            rlVerticalTipsTextCon.setVisibility(VISIBLE);
        }else {
            tvVerticalLiveTips.setVisibility(GONE);
            rlVerticalTipsTextCon.setVisibility(GONE);
        }
    }

    private void showCloseBtn(boolean show){
        if (show){
            ivVerticalLiveClose.setVisibility(VISIBLE);
        }else {
            ivVerticalLiveClose.setVisibility(GONE);

        }
    }

    private void showTitle(boolean show){
        if (show){
            rlVerticalTitleCon.setVisibility(VISIBLE);
        }else {
            rlVerticalTitleCon.setVisibility(GONE);

        }
    }



    private void showTips(boolean show) {
        if (show){
            hideAllMenu();
            rlVerticalTipsCon.setVisibility(VISIBLE);
        }else {
            rlVerticalTipsCon.setVisibility(GONE);
        }
    }


    private void showInteractPanel(int type){
        //横屏状态不处理
        if (isLandScape()){
            hideInteractPanel();
            return;
        }
        hideInteractPanel();
        rlLiveInteractCon.setVisibility(VISIBLE);
        switch (type){
            case INTERACT_GOODS_LIST:
                recommerceGoodslistView.setVisibility(VISIBLE);
                break;
            default:
        }
    }

    private boolean isLandScape() {
        return getResources().getConfiguration().orientation != Configuration.ORIENTATION_PORTRAIT;
    }

    /**
     * 隐藏互动组件面板
     */
    private void hideInteractPanel(){
        rlLiveInteractCon.setVisibility(GONE);
        recommerceGoodslistView.setVisibility(GONE);
    }
    // </editor-fold>


    // <editor-fold defaultstate="collapsed" desc="回调监听">

    @Override
    public void onSwitchVideoDoc(boolean isVideoMain) {
        //切换文档大小窗

    }

    @Override
    public void showRoomTitle(String title) {
        //显示直播间标题
        tvVerticalLiveTitle.setText(title);
    }

    @Override
    public void showRoomUserNum(int number) {
        //显示直播间人数
        tvVerticalLiveCount.setText("" + number);
    }

    @Override
    public void onKickOut() {
        //被踢出
        toastOnUiThread("您被踢出直播间");
        finish();
    }

    @Override
    public void onInformation(String msg) {
        //显示信息
        toastOnUiThread(msg);
    }

    @Override
    public void onStreamEnd(boolean isNormal, String reason) {
        //直播结束
        rlVerticalLiveBgLayoutCon.setVisibility(VISIBLE);
        mLiveVideoView.setVisibility(GONE);

        initLiveBackground(isNormal);

        //重置更多菜单项
        resetMorePanel();
    }

    @Override
    public void onStreamStart() {
        //直播开始
        //隐藏背景布局
        rlVerticalLiveBgLayoutCon.setVisibility(GONE);

        //如果计时器在跑，停止计时器
        timerVerticalLive.reset();
        timerVerticalLiveBig.reset();

        mLiveVideoView.setVisibility(VISIBLE);
        //显示静音按钮
        llVerticalMoreMute.setVisibility(VISIBLE);
        initVr();
    }

    @Override
    public void onEnterRtc() {
        //进入连麦
    }

    @Override
    public void showError(String errMsg) {
        //显示错误
    }

    @Override
    public void onHDAudioMode(DWLive.LiveAudio hasAudio) {

    }

    private VerticalPortraitQualityTextView qualityCheckedView;

    @Override
    public void onHDReceivedVideoQuality(List<LiveQualityInfo> videoQuality, LiveQualityInfo currentQuality) {
        //视频清晰度列表
        //支持多清晰度，展示清晰度切换图标
        boolean isShowQuality = DWLiveCoreHandler.getInstance().isShowQuality();
        llVerticalHdsList.removeAllViews();
        if (isShowQuality){
            this.videoQuality = videoQuality;
            this.currentQuality = currentQuality;
            llVerticalMoreHds.setVisibility(VISIBLE);
            if (videoQuality == null || currentQuality == null) {
                Log.e(TAG, "LiveQualityView setData param is null");
                return;
            }
            int size = videoQuality.size();
            for (int i = 0; i < size; i++) {
                LiveQualityInfo liveLineParams = videoQuality.get(i);
                VerticalPortraitQualityTextView qualityTextView = new VerticalPortraitQualityTextView(this,
                        liveLineParams.getQuality(), liveLineParams.getDesc());
                // 默认显示第一条数据：原画
                if (qualityCheckedView == null) {
                    if (i == 0) {
                        qualityTextView.setChecked(true);
                        qualityCheckedView = qualityTextView;
                    }
                } else {
                    if (qualityCheckedView.getQuality() == liveLineParams.getQuality()) {
                        qualityTextView.setChecked(true);
                    }
                }
                addQualityTextView(qualityTextView);
            }
        }else {
            llVerticalMoreHds.setVisibility(GONE);
        }
    }

    @Override
    public void onHDReceivedVideoAudioLines(List<LiveLineInfo> lines, int indexNum) {
        //视频线路
        if (lines!=null&&lines.size()>0){
            Log.i(TAG, "onHDReceivedVideoAudioLines: "+lines.size()+",indexNum:"+indexNum);
            llVerticalMoreLine.setVisibility(VISIBLE);
            addLines(lines,indexNum);

        }else {
            llVerticalMoreLine.setVisibility(GONE);

        }
    }


    @Override
    public void onAnnouncement(final boolean isRemove, final String announcement) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (isRemove) {
                    tvVerticalLiveTips.setVisibility(GONE);
                    tvVerticalLiveTips.setText("");
                    rlVerticalTipsTextCon.setVisibility(GONE);

                    announceLayout.removeAnnounce();
                } else {
                    tvVerticalLiveTips.setText(announcement);
                    announceLayout.setAnnounce(announcement);
                    tvVerticalLiveTips.setSelected(true);
                    tvVerticalLiveTips.setVisibility(VISIBLE);
                    rlVerticalTipsTextCon.setVisibility(VISIBLE);
                }
            }
        });
    }



    @Override
    public void onBackPressed() {
        if (!isPortrait()) {
//            if (!mLiveRoomLayout.onBackPressed()) {
//                quitFullScreen();
//            }
            return;
        } else {
            if (ccChatView!=null){
                ccChatView.onBackPressed();
            }
//            if (mChatLayout != null && mChatLayout.onBackPressed()) {
//                return;
//            }
        }
        // 弹出退出提示
        showExitDialog();
    }

    // </editor-fold>


    /**
     * 启动直播界面
     *
     * @param activity    activity
     * @param isVideoMain 是否是以大屏为主
     * @param userId      客户id，互动组件需要
     */
    public static void openActivity(Activity activity, boolean isVideoMain, String userId, String nickName, String roomId, boolean isDisAllowScreenShot) {
        Intent intent = new Intent(activity, VerticalLiveActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("isVideoMain", isVideoMain);
        intent.putExtra("userId", userId);
        intent.putExtra("nickName", nickName);
        intent.putExtra("roomId", roomId);
        intent.putExtra("isDisAllowScreenShot", isDisAllowScreenShot);
        activity.startActivity(intent);
    }


    @Override
    public void onKeyboardHeightChanged(int height, int orientation) {
        if (ccChatView!=null){
            ccChatView.onKeyboardHeightChanged(height,orientation);
        }
        //键盘弹起，隐藏title、公告和关闭
        if (height>0){
            showTitle(false);
            showHeadTips(false);
            showCloseBtn(false);
        }else {
            showTitle(true);
            showHeadTips(true);
            showCloseBtn(true);


        }
    }
}
