package com.ycgis.macall.personalcenter.v.custom;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.rs.macall.androidx.basemodel.callback.CustomClickListener;
import com.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.databinding.DialogInputBinding;

/**
 * created by:   Macall
 * create time:  2023/11/22 9:27
 * copyright:    @ruansee.com
 * Describe:
 */
public class InputDialog extends Dialog {
    private DialogInputBinding binding;

    public InputDialog(@NonNull Context context) {
        super(context);
    }

    public InputDialog(@NonNull Context context,@NonNull int themeResId){
        super(context,themeResId);
    }

    public void setSubmitListener(CustomClickListener submitListener) {
        binding.btnSubmit.setOnClickListener(submitListener);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DialogInputBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
    }

    public String getInputEditText(){
        return binding.editInput.getText().toString();
    }

    public void setInputEdit(String content){
        binding.editInput.setText(content);
    }

    public void setInputType(int inputType){
        binding.editInput.setInputType(inputType);
    }

    public void setInputEdit(CharSequence content){
        binding.editInput.setText(content);
    }

    public void setInputTitle(String title){
        binding.tvTitle.setText(title);
    }

    public void setInputTitle(int resTitleId){
        binding.tvTitle.setText(resTitleId);
    }

    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity= Gravity.CENTER;
//        DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
//        layoutParams.width = (int)(dm.widthPixels - dm.density * horizontalMargin);
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(layoutParams);
    }

}

