package com.sybotan.android.demo.view;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sybotan.android.demo.R;

/**
 * 选择设备列表
 */

public class EquipListDialog extends Dialog {

    private Submit submit;
    private EditText searchEdt;

    public EquipListDialog(@NonNull Context context) {
        super(context, R.style.style_dialog);
        setDisplay(context);
        init(context);
    }

    private void init(Context context) {
        findViewById(R.id.search_delete).setOnClickListener(v -> {
            searchEdt.setText("");
        });
        searchEdt = findViewById(R.id.search_edt);
        searchEdt.setOnEditorActionListener((textView, actionId, keyEvent) -> {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {//修改回车键功能
                if (!TextUtils.isEmpty(searchEdt.getText().toString().trim())) {

                }
            }
            return false;
        });
        RecyclerView recycler = findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(context));
    }

    public void setDisplay(Context context) {
        setContentView(R.layout.dialog_equip_list);
        setProperty();
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                dialog.dismiss();
            }
        });
    }

    public void setProperty() {
        Window window = getWindow();//得到对话框的窗口．
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;// 设置对话框的位置．0为中间
        wl.y = 0;
        wl.alpha = 1;// 设置对话框的透明度
        wl.gravity = Gravity.CENTER;
        window.setAttributes(wl);
    }


    public interface Submit {
        void onSubmit();
    }

    public void setOnSubmit(Submit submit) {
        this.submit = submit;
    }

}