package epson.print;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

import androidx.fragment.app.DialogFragment;

import epson.common.Utils;
import epson.print.widgets.CustomTitleAlertDialogBuilder;

public class CustomTitleDialogFragment extends DialogFragment {
    private static final String TAG_DIALOG_ID = "dialog_id";
    private static final String TAG_MESSAGE = "message";
    private static final String TAG_NEGATIVE_BUTTON_STRING_ID = "negative_button_string_id";
    private static final String TAG_POSITIVE_BUTTON_STRING_ID = "positive_button_string_id";
    private static final String TAG_TITLE_ID = "title_id";
    private static final String TAG_TITLE_STRING = "title_string";

    public interface Callback {
        void onLocalNegativeCallback(int i);

        void onLocalPositiveCallback(int i);
    }

    public static CustomTitleDialogFragment newInstance(int i, String str, int i2, int i3, int i4) {
        CustomTitleDialogFragment customTitleDialogFragment = new CustomTitleDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(TAG_DIALOG_ID, i);
        bundle.putString("message", str);
        bundle.putInt(TAG_TITLE_ID, i2);
        bundle.putInt(TAG_POSITIVE_BUTTON_STRING_ID, i3);
        bundle.putInt(TAG_NEGATIVE_BUTTON_STRING_ID, i4);
        customTitleDialogFragment.setArguments(bundle);
        return customTitleDialogFragment;
    }

    public static CustomTitleDialogFragment newInstance(int i, String str, String str2, int i2, int i3) {
        CustomTitleDialogFragment customTitleDialogFragment = new CustomTitleDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(TAG_DIALOG_ID, i);
        bundle.putString("message", str);
        bundle.putString(TAG_TITLE_STRING, str2);
        bundle.putInt(TAG_POSITIVE_BUTTON_STRING_ID, i2);
        bundle.putInt(TAG_NEGATIVE_BUTTON_STRING_ID, i3);
        customTitleDialogFragment.setArguments(bundle);
        return customTitleDialogFragment;
    }

    public Dialog onCreateDialog(Bundle bundle) {
        Bundle arguments = getArguments();
        final int i = arguments.getInt(TAG_DIALOG_ID);
        String string = arguments.getString("message");
        int i2 = arguments.getInt(TAG_TITLE_ID);
        String string2 = arguments.getString(TAG_TITLE_STRING);
        int i3 = arguments.getInt(TAG_POSITIVE_BUTTON_STRING_ID);
        int i4 = arguments.getInt(TAG_NEGATIVE_BUTTON_STRING_ID);
        final Callback callback = (Callback) getActivity();
        CustomTitleAlertDialogBuilder customTitleDialogBuilder = Utils.getCustomTitleDialogBuilder((Activity) callback);
        customTitleDialogBuilder.setMessage(string).setPositiveButton(i3, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                CustomTitleDialogFragment.this.dismiss();
                callback.onLocalPositiveCallback(i);
            }
        });
        if (i4 != 0) {
            customTitleDialogBuilder.setNegativeButton(i4, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    CustomTitleDialogFragment.this.dismiss();
                    callback.onLocalNegativeCallback(i);
                }
            });
        }
        if (i2 != 0) {
            customTitleDialogBuilder.setTitle(i2);
        } else if (string2 != null) {
            customTitleDialogBuilder.setTitle(string2);
        }
        AlertDialog create = customTitleDialogBuilder.create();
        create.setCanceledOnTouchOutside(false);
        return create;
    }
}
