package com.bbitcn.silk.ui.dialog;

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

import androidx.annotation.NonNull;

import com.bbitcn.silk.base.BaseDialog;
import com.bbitcn.silk.databinding.DialogCustomBinding;

/**
 * @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();
        });
    }
}
