package com.duben.microtribe.ui.widgets;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;

import com.duben.microtribe.R;


/**
 * 支付返回弹窗
 */
public class CancelOrderDialog extends Dialog {
    private LayoutParams lp;
    private DialogListener listener;

    private TextView tv_go;
    private TextView tv_cancel;

    public CancelOrderDialog(Context context, DialogListener listener) {
        super(context, R.style.dialog);
        this.listener = listener;
        setContentView(R.layout.dialog_cancel_order);
        // 设置window属性
        lp = getWindow().getAttributes();
        lp.gravity = Gravity.CENTER;
        lp.width = LayoutParams.MATCH_PARENT;
        lp.windowAnimations = R.style.DialogAnimBottom;
        getWindow().setAttributes(lp);

        // 设置外部不可关闭
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        setOnKeyListener((dialogInterface, i, keyEvent) -> {
            if (i == KeyEvent.KEYCODE_BACK) {
                return true;
            }
            return false;
        });

        // 查找View
        tv_go = (TextView) findViewById(R.id.tv_go);
        tv_cancel = (TextView) findViewById(R.id.tv_cancel);
        listener.setDialog(this);
        tv_cancel.setOnClickListener(listener);
        tv_go.setOnClickListener(v -> dismiss());
    }

}
