package com.cooleshow.base.widgets.dialog;

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

import com.cooleshow.base.R;
import com.cooleshow.base.widgets.InputBar;


/**
 * 底部编辑弹框
 */
public class InputBarDialog extends Dialog {
    InputBar.InputBarListener inputBarListener;
    InputBar inputBar;

    public InputBarDialog(Context context, InputBar.InputBarListener inputBarListener) {
        super(context, R.style.InputBar_Dialog_Style);
        this.inputBarListener = inputBarListener;
        inputBar = new InputBar(context);
        inputBar.setInputBarListener(new InputBar.InputBarListener() {
            @Override
            public boolean onClickSend(String message) {
                if (inputBarListener != null) {
                    boolean isSuccess = inputBarListener.onClickSend(message);
                    if (isSuccess) {
                        dismiss();
                    }
                    return isSuccess;
                }
                return false;
            }

            @Override
            public boolean onClickEmoji() {
                if (inputBarListener != null) {
                    return inputBarListener.onClickEmoji();
                }
                return false;
            }
        });
        setContentView(inputBar);
        Window window = getWindow();
        if (window != null) {
            //获取对话框当前的参数值
            WindowManager.LayoutParams params = window.getAttributes();
            params.gravity = Gravity.BOTTOM;
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            window.setAttributes(params);
        }
    }

    @Override
    public void dismiss() {
        if (inputBar != null) {
            inputBar.hideInputBar();
        }
        super.dismiss();
    }

    public void showInput() {
        if (inputBar != null) {
            inputBar.showInputBar();
        }
    }

    @Override
    public void show() {
        super.show();
    }
}