package in.techware.carrefour.dialogs;

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

import in.techware.carrefour.R;

/**
 * Created by Jemsheer K D on 23 June, 2018.
 * Package in.techware.carrefour.dialogs
 * Project Carrefour
 */
public class ConfirmationDialog {

    private final Activity mContext;
    private ConfirmationDialogActionListener confirmationDialogActionListener;
    private Dialog dialogExit;
    private TextView txtMessage;

    public ConfirmationDialog(Activity mContext) {
        this.mContext = mContext;

        setExitDialog();
    }

    public void show(int message) {
        txtMessage.setText(message);
        dialogExit.show();
    }

    public void show(String message) {
        txtMessage.setText(message);
        dialogExit.show();
    }

    private void setExitDialog() {

        dialogExit = new Dialog(mContext, R.style.ThemeDialogCustom_NoBackground);
        dialogExit.setContentView(R.layout.dialog_confirmation);
        dialogExit.setTitle("Exit : ");

        Button btnYes = (Button) dialogExit.findViewById(R.id.btn_dialog_confirmation_yes);
        Button btnNo = (Button) dialogExit.findViewById(R.id.btn_dialog_confirmation_no);
        txtMessage = (TextView) dialogExit.findViewById(R.id.txt_dialog_confirmation_message);

        btnYes.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
//                mVibrator.vibrate(25);
                confirmationDialogActionListener.onYesClicked();
                dialogExit.dismiss();
            }
        });
        btnNo.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
//                mVibrator.vibrate(25);
                confirmationDialogActionListener.onNoClicked();
                dialogExit.dismiss();
            }
        });
    }

    public interface ConfirmationDialogActionListener {

        void onYesClicked();

        void onNoClicked();
    }

    public ConfirmationDialogActionListener getConfirmationDialogActionListener() {
        return confirmationDialogActionListener;
    }


    public void setConfirmationDialogActionListener(ConfirmationDialogActionListener confirmationDialogActionListener) {
        this.confirmationDialogActionListener = confirmationDialogActionListener;
    }
}
