package de.frajul.endlessroll.views;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.StringRes;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import de.frajul.endlessroll.R;
import de.frajul.endlessroll.main.GameActivity;

/**
 * Created by Julian on 31.10.2017.
 */

public class ConfirmDialog extends Dialog implements View.OnClickListener {

    public interface ConfirmDialogListener {
        void onConfirmed(int callId);
    }

    private GameActivity gameActivity;
    private int callId = -1;
    @StringRes
    private int text = -1;
    private ConfirmDialogListener listener;

    private TextView textView;
    private Button yesButton;
    private Button noButton;

    public ConfirmDialog(GameActivity gameActivity, ConfirmDialogListener listener) {
        super(gameActivity);
        this.gameActivity = gameActivity;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.confirm_dialog);
        textView = (TextView) findViewById(R.id.confirm_dialog_textview);
        textView.setTypeface(gameActivity.getTypeface());
        noButton = (Button) findViewById(R.id.confirm_dialog_no_button);
        noButton.setTypeface(gameActivity.getTypeface());
        noButton.setOnClickListener(this);
        yesButton = (Button) findViewById(R.id.confirm_dialog_yes_button);
        yesButton.setTypeface(gameActivity.getTypeface());
        yesButton.setOnClickListener(this);
    }

    public void show(int callId, @StringRes int text) {
        this.callId = callId;
        this.text = text;
        super.show();
        textView.setText(text);
    }

    @Override
    public void onClick(View v) {
        dismiss();
        if (v.equals(yesButton))
            listener.onConfirmed(callId);
    }
}
