package com.example.mynotepad.Dialogs.AddTxtToPicsDialog;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.example.mynotepad.R;

public class AddTextToPicDialog {

    private OnSavePicListenerClick onSavePicListenerClick;
    private ImageView imageView;
    private EditText editText;
    private Button save, back;

    public void showAddTxtDialog(Activity activity, Bitmap bitmap) {
        final Dialog dialog = new Dialog(activity);
        dialog.setCancelable(true);
        dialog.setContentView(R.layout.dialog_add_text_to_pic);
        save = dialog.findViewById(R.id.save_button);
        back = dialog.findViewById(R.id.back_button);
        imageView = dialog.findViewById(R.id.imageView);
        imageView.setImageBitmap(bitmap);
        editText = dialog.findViewById(R.id.editText);
        addListener(dialog);

        dialog.show();
    }

    private void addListener(final Dialog dialog) {
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onSavePicListenerClick.saveClicked(editText.getText().toString() );
                dialog.dismiss();
            }
        });
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }


    public void setOnSavePicListenerClick(OnSavePicListenerClick onSavePicListenerClick) {
        this.onSavePicListenerClick = onSavePicListenerClick;
    }
}
