package com.example.iot_controlhost.ui.dialog;

import android.content.Context;
import android.text.InputType;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.iot_controlhost.R;
import com.example.iot_controlhost.base.BaseDialog;
import com.example.iot_controlhost.databinding.DialogCustomBinding;
import com.example.iot_controlhost.databinding.DialogSetBinding;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;

/**
 * @Description 文本输入弹窗
 * @Author DuanKaiji
 * @CreateTime 2024年03月12日 15:54
 */
public class TextViewDialog extends BaseDialog<DialogCustomBinding> {
    public TextViewDialog(@NonNull Context context, String title, String inputText,  CustomString  listener,boolean isNumber) {
        super(context,true);
        binding.tilInput.setVisibility(View.VISIBLE);
        binding.tvMessage.setVisibility(View.GONE);
        binding.btnNo.setVisibility(View.GONE);
        binding.tvTitle.setText(title);
        binding.tiInput.setText(inputText);
        binding.tiInput.setInputType(isNumber?InputType.TYPE_CLASS_NUMBER:InputType.TYPE_CLASS_TEXT);
        binding.btnYes.setOnClickListener(view -> {
            InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            listener.listener(binding.tiInput.getText().toString());
            dismiss();
        });
    }
}
