package com.cooleshow.teacher.widgets.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.cooleshow.teacher.R;

import androidx.annotation.NonNull;

/**
 * Author by pq, Date on 2022/6/11.
 * 暂停直播或结束直播
 */
public class LiveRoomManagerDialog extends Dialog implements View.OnClickListener {
    private OnEventListener mEventListener;

    public LiveRoomManagerDialog(@NonNull Context context) {
        super(context, R.style.MyBottomDialogStyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_live_manager_layout);
        Window window = getWindow();
        //设置dialog在屏幕底部
        window.setGravity(Gravity.BOTTOM);
        //设置dialog弹出时的动画效果，从屏幕底部向上弹出
        window.setWindowAnimations(com.cooleshow.base.R.style.BottomAnimation);
        window.getDecorView().setPadding(0, 0, 0, 0);
        //获得window窗口的属性
        WindowManager.LayoutParams lp = window.getAttributes();
        //设置窗口宽度为充满全屏
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        //设置窗口高度为包裹内容
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.horizontalMargin = 0;
        lp.verticalMargin = 0;
        //将设置好的属性set回去
        window.setAttributes(lp);
        findViewById(R.id.view_pause_live).setOnClickListener(this);
        findViewById(R.id.view_pause_finish).setOnClickListener(this);
        initListener();
    }

    private void initListener() {
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.view_pause_live) {
            //暂停直播
            if (mEventListener != null) {
                mEventListener.onPauseLive();
            }
            return;
        }

        if (id == R.id.view_pause_finish) {
            //结束直播
            if (mEventListener != null) {
                mEventListener.onFinishLive();
            }
            return;
        }
    }

    public void setOnEventListener(OnEventListener listener) {
        this.mEventListener = listener;
    }

    public interface OnEventListener {
        //同意连麦申请
        void onPauseLive();

        //拒绝全部连麦申请
        void onFinishLive();
    }
}
