package com.tjzhxx.union.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.tjzhxx.union.R;


/**
 * 描述:
 *
 * @author yanghuaxiong
 * @create 2018/6/8  下午4:29
 */
public class DialogNoMemberDialog extends Dialog {
    private Context context;
    private OnSureListener onSureListener;

    public void setOnSureListener(OnSureListener onSureListener) {
        this.onSureListener = onSureListener;
    }

    public DialogNoMemberDialog(@NonNull final Context context) {
        super(context, R.style.cp_dialogNoTitle);
        this.context = context;
        super.setContentView(R.layout.dialog_no_member_prompt);
        findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        findViewById(R.id.sure).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onSureListener != null) {
                    onSureListener.onSureListener();
                }
                dismiss();
            }
        });
        setCancelAble(false);
    }

    public DialogNoMemberDialog setCancelAble(boolean cancelAble) {
        setCancelable(cancelAble);
        return this;
    }


    @SuppressWarnings("deprecation")
    @Override
    public void show() {
        Window dialogWindow = this.getWindow();
//        dialogWindow.setWindowAnimations(R.style.cp_dialogWindowAnim);
        WindowManager windowManager = dialogWindow.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL
                | Gravity.CENTER_VERTICAL);
        lp.width = (display.getWidth() * 1);
        int height = lp.height;
        if (height > display.getWidth() * 0.9) {
            lp.height = (int) (display.getWidth() * 0.9);
        }
        dialogWindow.setAttributes(lp);
        super.show();
    }

    public interface OnSureListener {
        void onSureListener();
    }
}
