package com.example.mynotepad.Dialogs.FoldersCustomDialog;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.mynotepad.R;

public class CreateNewFolderDialog {
    private TextView cancel , done;
    private EditText folderName;
    private OnCreateNewFolderDialogClickListener onCreateNewFolderDialogClickListener;

    public void showDialog(Activity activity){
        Dialog dialog = new Dialog(activity);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.setCancelable(true);
        dialog.setContentView(R.layout.dialog_create_new_folder);
        cancel = dialog.findViewById(R.id.cancel);
        done = dialog.findViewById(R.id.done);
        folderName = dialog.findViewById(R.id.folderName);
        addListener(dialog);
        dialog.show();
    }

    private void addListener(final Dialog dialog) {
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        done.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!folderName.getText().toString().equals(""))
                onCreateNewFolderDialogClickListener.onDoneClicked(folderName.getText().toString());
                dialog.dismiss();
            }
        });
    }

    public void setOnCreateNewFolderDialogClickListener(OnCreateNewFolderDialogClickListener onCreateNewFolderDialogClickListener) {
        this.onCreateNewFolderDialogClickListener = onCreateNewFolderDialogClickListener;
    }
}
