package com.bokecc.livemodule.live.multirtc;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.TextView;

import com.bokecc.dwlivedemo.R;
import com.bokecc.livemodule.utils.PopupAnimUtil;
import com.bokecc.livemodule.view.BasePopupWindow;

/**
 * 连麦提示弹出框
 */
public class RtcCommonMsgPopup extends BasePopupWindow {


    public RtcCommonMsgPopup(Context context) {
        super(context);
    }

    TextView tvContent;

    Button btnOk;
    Button btnCancel;

    CommonPopListener mListener;


    @Override
    protected void onViewCreated() {
        tvContent = findViewById(R.id.tv_pop_rtc_common_content);
        btnOk = findViewById(R.id.btn_pop_rtc_common_ok);
        btnCancel = findViewById(R.id.btn_pop_rtc_common_cancel);

        btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mListener!=null){
                    mListener.onOkClick(RtcCommonMsgPopup.this);
                }
            }
        });
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener!=null){
                    mListener.onCancelClick(RtcCommonMsgPopup.this);
                }
            }
        });
    }

    @Override
    protected int getContentView() {
        return R.layout.pop_rtc_common_msg;
    }

    @Override
    protected Animation getEnterAnimation() {
        return PopupAnimUtil.getDefScaleEnterAnim();
    }

    @Override
    protected Animation getExitAnimation() {
        return PopupAnimUtil.getDefScaleExitAnim();
    }


    public RtcCommonMsgPopup setTitle(String title){
        return this;
    }

    public RtcCommonMsgPopup setContent(String content){
        tvContent.setText(content);
        return this;
    }

    public RtcCommonMsgPopup setListener(CommonPopListener listener){
        this.mListener = listener;
        return this;
    }

    public RtcCommonMsgPopup setHideOkBtn(){
        btnOk.setVisibility(View.GONE);
        return this;
    }
    public RtcCommonMsgPopup setHideCancelBtn(){
        btnCancel.setVisibility(View.GONE);
        return this;
    }
    public RtcCommonMsgPopup setOkBtnText(String text){
        btnOk.setText(text);
        return this;
    }
    public RtcCommonMsgPopup setCancelBtnText(String text){
        btnCancel.setText(text);
        return this;
    }

    public RtcCommonMsgPopup setCancelable(boolean cancelable){
        this.setOutsideCancel(cancelable);
        this.setBackPressedCancel(cancelable);
        this.setBackPressCancel(cancelable);
        return this;
    }

    @Override
    public void show(View view) {
        super.show(view);
    }

    @Override
    public void dismiss() {
        super.dismiss();
        if (mContext!=null&&mContext instanceof Activity&&mContext.getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE){
//            ((Activity)mContext).getWindow().getDecorView().setSystemUiVisibility(getSystemUiVisibility(true));
            ((Activity)mContext).getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }

    @TargetApi(19)
    private static int getSystemUiVisibility(boolean isFull) {
        if (isFull) {
            int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            }
            return flags;
        } else {
            return View.SYSTEM_UI_FLAG_VISIBLE;
        }
    }

    public interface CommonPopListener{
        void onOkClick(BasePopupWindow popupWindow);
        void onCancelClick(BasePopupWindow popupWindow);
    }


}