package com.ez.ertc.meeting.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.ez.ertc.meeting.R;
import com.ez.ertc.meeting.R2;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author xiezuoyuan
 * @time 2018/11/21 19:28
 */
public class MtMoreDialog extends Dialog {

    @BindView(R2.id.tvPip)
    TextView tvPip;
    @BindView(R2.id.cvBeauty)
    View cvBeauty;
    private boolean selected = true;
    private OnClickListener onClickListener;

    public MtMoreDialog(@NonNull Context context, OnClickListener onClickListener) {
        super(context , R.style.ezmBottomDialogDimFalse);
        this.onClickListener = onClickListener;
        getWindow().setGravity(Gravity.BOTTOM);
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(lp);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ys_mt_dialog_sets_more);
        ButterKnife.bind(this);
        tvPip.setSelected(selected);
    }

    public void setPipOn(){
        Drawable drawable= getContext().getResources().getDrawable(R.drawable.ys_mt_svg_share_bg_pip_on);
        // 这一步必须要做,否则不会显示.
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvPip.setCompoundDrawables(null,drawable,null,null);
        tvPip.setText(R.string.ys_mt_room_more_pic_in_pic_open);
        tvPip.setSelected(selected);
    }
    public void setPipOff(){
        Drawable drawable= getContext().getResources().getDrawable(R.drawable.ys_mt_svg_share_bg_pip_off);
        // 这一步必须要做,否则不会显示.
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvPip.setCompoundDrawables(null,drawable,null,null);
        tvPip.setText(R.string.ys_mt_room_more_pic_in_pic_close);
        tvPip.setSelected(selected);
    }
    public void enableClick(){
        selected = true;
        tvPip.setSelected(selected);
    }
    public void disableClick(){
        selected = false;
        tvPip.setSelected(selected);
    }

    @OnClick({R2.id.cvPip,R2.id.cvMore,R2.id.llRoot,R2.id.cvBeauty})
    public void onClick(View v){
        int id = v.getId();
        if (id ==R.id.cvPip){
            if (!selected){
                return;
            }
            dismiss();
            onClickListener.onPip();
        } else if (id == R.id.cvMore){
            dismiss();
            onClickListener.onMore();
        } else if (id == R.id.llRoot){
            dismiss();
        } else if (id == R.id.cvBeauty){
            onClickListener.onBeauty();
            dismiss();
        }
    }

    public interface OnClickListener {
        void onPip();
        void onBeauty();
        void onMore();
    }

}
