package com.mytatvarnsdk.myView.popupwindow;

/**
 * 报警类型选取窗口
 */

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.mytatvarnsdk.R;


public class TransmitterConnectPopWindow extends BPopupWindow {

    private TextView connectTransmitterName;
    private TextView notice;

    private TextView cancel;

    private TextView skip;

    private TextView ok;

    public TransmitterConnectPopWindow(Activity activity, int viewId, String transmitterName, String info) {
        super(activity, viewId);
        setFocusable(false);
        setOutsideTouchable(false);
        connectTransmitterName = mView.findViewById(R.id.popup_window_connect_transmitter_name);
        notice = mView.findViewById(R.id.popup_window_connect_transmitter_notice);
        connectTransmitterName.setText(transmitterName);
        notice.setText(info);
        //初始化设备适配器
        cancel = mView.findViewById(R.id.popup_transmitter_connect_cancel);
        cancel.setOnClickListener(v -> {
            PopupWindowManagement.getInstance().dismiss();
            if (mOnChooseListener != null) {
                mOnChooseListener.cancel(v);
            }
            if (mOnSelectListener != null) {
                mOnSelectListener.cancel(v);
            }
        });

        skip = mView.findViewById(R.id.popup_transmitter_connect_skip);
        skip.setOnClickListener(v -> {
            if (mOnChooseListener != null) {
                mOnChooseListener.skip(v);
            }
        });

        //初始化设备适配器
        ok = mView.findViewById(R.id.popup_transmitter_connect_ok);
        ok.setOnClickListener(v -> {
            if (mOnChooseListener != null) {
                mOnChooseListener.confirm(v);
            }
            if (mOnSelectListener != null) {
                mOnSelectListener.confirm(v);
            }
            if (mOnConfirmListener != null) {
                mOnConfirmListener.confirm(v);
            }
        });
    }

    @Override
    public void showAtLocation(View parent, int gravity, int x, int y) {
        super.showAtLocation(parent, gravity, x, y);
        if (mOnConfirmListener != null) {
            ok.setVisibility(View.VISIBLE);
            skip.setVisibility(View.GONE);
            cancel.setVisibility(View.GONE);
        } else if (mOnSelectListener != null) {
            ok.setVisibility(View.VISIBLE);
            skip.setVisibility(View.GONE);
            cancel.setVisibility(View.VISIBLE);
        } else if (mOnChooseListener != null) {
            ok.setVisibility(View.VISIBLE);
            skip.setVisibility(View.VISIBLE);
            cancel.setVisibility(View.VISIBLE);
        } else {
            ok.setVisibility(View.GONE);
            skip.setVisibility(View.GONE);
            cancel.setVisibility(View.VISIBLE);
        }
    }
}
