package com.mytatvarnsdk.myView.popupwindow;

/**
 * Created by LeXunSW on 2016/1/12.
 * 权限类型的类框图
 */

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

import com.mytatvarnsdk.R;

public class PermissionRequestPopWindow extends BPopupWindow {

    private Button cancel;

    private Button ok;

    private TextView mTextView;

    public PermissionRequestPopWindow(Activity activity, int viewId, String message) {
        super(activity,viewId);
        setFocusable(false);
        setOutsideTouchable(false);
        //初始化设备适配器
        mTextView = mView.findViewById(R.id.popup_request_permission_message);
        mTextView.setText(message);
        cancel = mView.findViewById(R.id.popup_request_permission_cancel);
        cancel.setOnClickListener(v -> {
            PopupWindowManagement.getInstance().dismiss();
            if (mOnSelectListener != null){
                mOnSelectListener.cancel(v);
            }
        });
        //初始化设备适配器
        ok = mView.findViewById(R.id.popup_request_permission_ok);
        ok.setOnClickListener(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 (mOnSelectListener != null){
            ok.setVisibility(View.VISIBLE);
            cancel.setVisibility(View.VISIBLE);
        } else if (mOnConfirmListener != null){
            ok.setVisibility(View.VISIBLE);
            cancel.setVisibility(View.GONE);
        } else {
            ok.setVisibility(View.GONE);
            cancel.setVisibility(View.GONE);
        }
    }

}
