package com.example.mynotepad.Dialogs;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.mynotepad.R;

public class CustomDialog {
    private Button yes, no ;
    private TextView textView ;
    private onCustomDialogClickListener onCustomDialogClickListener;

    public void showAddTxtDialog(Activity activity,String txt) {
        final Dialog dialog = new Dialog(activity);
        dialog.setCancelable(true);
        dialog.setContentView(R.layout.dialog_custom);
        yes = dialog.findViewById(R.id.yes);
        no = dialog.findViewById(R.id.no);
        textView = dialog.findViewById(R.id.textView2);
        textView.setText(txt);
        addListener(dialog);

        dialog.show();
    }

    private void addListener(final Dialog dialog) {
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onCustomDialogClickListener.yesClicked();
                dialog.dismiss();
            }
        });
        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onCustomDialogClickListener.noClicked();
                dialog.dismiss();
            }
        });
    }

    public void setOnCustomDialogClickListener(com.example.mynotepad.Dialogs.onCustomDialogClickListener onCustomDialogClickListener) {
        this.onCustomDialogClickListener = onCustomDialogClickListener;
    }
}
