package com.yyrh.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import cn.yyxx.support.DensityUtils;
import cn.yyxx.support.ResUtils;

/**
 * 提示框dialog
 * 样式如下：
 * -------------------------
 * |                       |
 * |                       |
 * ｜         内容          ｜
 * ｜                      ｜
 * -------------------------
 * ｜    取消    ｜   确定   ｜
 * -------------------------
 *
 * @author #Suyghur.
 * Created on 2021/10/21
 */
public class TipsDialog extends Dialog {

    private TextView textView;
    private Button leftButton;
    private Button rightButton;

    public TipsDialog(Context context, boolean doubleButton) {
        super(context);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        initView(context, doubleButton);
    }

    private void initView(Context context, boolean doubleButton) {
        View view = LayoutInflater.from(context).inflate(ResUtils.getResId(context, "hnyy_tips_dialog", "layout"), null);
        setContentView(view);

        WindowManager.LayoutParams attr = getWindow().getAttributes();
        attr.gravity = Gravity.CENTER;
        attr.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        attr.width = DensityUtils.dip2px(context, 300f);

        textView = view.findViewById(ResUtils.getResId(context, "hnyy_tv_content", "id"));

        leftButton = view.findViewById(ResUtils.getResId(context, "hnyy_btn_left", "id"));
        rightButton = view.findViewById(ResUtils.getResId(context, "hnyy_btn_right", "id"));
        if (doubleButton) {
            rightButton.setVisibility(View.VISIBLE);
        } else {
            rightButton.setVisibility(View.GONE);
        }
    }

    public TextView getTextView() {
        return textView;
    }

    public Button getLeftButton() {
        return leftButton;
    }

    public Button getRightButton() {
        return rightButton;
    }
}
