package com.epson.mobilephone.common.wifidirect;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;

import epson.print.R;

public class DialogProgressWiFiDirect extends DialogFragment {
    public static final int MESSAGE_BOTTOM = 1;
    public static final int MESSAGE_ONLY = 2;
    public static final int MESSAGE_RIGHT = 0;
    private static final String TAG_DIALOG = "tag";
    private static final String TAG_MESSAGE = "message";
    private static final String TAG_NEGATIVE_MESSAGE = "negative_dialog_message";
    private static final String TAG_NEUTRAL_MESSAGE = "neutral_dialog_message";
    private static final String TAG_POSITION = "position";
    private static final String TAG_POSITIVE_MESSAGE = "positive_dialog_message";
    private static final String TAG_TITLE_MESSAGE = "title_message";
    private DialogButtonClick mActivity;
    private String mTag;

    public interface DialogButtonClick {
        void onCancelDialog(String str);

        void onNegativeClick(String str);

        void onNeutralClick(String str);

        void onPositiveClick(String str);
    }

    public static DialogProgressWiFiDirect newInstance(String str, int i, @Nullable String str2) {
        return newInstance(str, i, str2, (String) null, (String) null, (String) null, (String) null);
    }

    public static DialogProgressWiFiDirect newInstance(String str, int i, @Nullable String str2, @Nullable String str3, @Nullable String str4, @Nullable String str5, @Nullable String str6) {
        DialogProgressWiFiDirect dialogProgressWiFiDirect = new DialogProgressWiFiDirect();
        Bundle bundle = new Bundle();
        bundle.putString(TAG_DIALOG, str);
        bundle.putInt("position", i);
        bundle.putString("message", str2);
        bundle.putString(TAG_TITLE_MESSAGE, str3);
        bundle.putString(TAG_POSITIVE_MESSAGE, str4);
        bundle.putString(TAG_NEUTRAL_MESSAGE, str5);
        bundle.putString(TAG_NEGATIVE_MESSAGE, str6);
        setArguments(bundle);
        return dialogProgressWiFiDirect;
    }

    private void deleteFragment(FragmentManager fragmentManager, String str) {
        Dialog dialog;
        DialogProgressWiFiDirect dialogProgressWiFiDirect = (DialogProgressWiFiDirect) fragmentManager.findFragmentByTag(str);
        if (dialogProgressWiFiDirect != null && (dialog = getDialog()) != null && dialog.isShowing()) {
            dismiss();
        }
    }

    @NonNull
    public Dialog onCreateDialog(@Nullable Bundle bundle) {
        mTag = getArguments().getString(TAG_DIALOG);
        int i = getArguments().getInt("position");
        String string = getArguments().getString("message");
        String string2 = getArguments().getString(TAG_TITLE_MESSAGE);
        String string3 = getArguments().getString(TAG_POSITIVE_MESSAGE);
        String string4 = getArguments().getString(TAG_NEUTRAL_MESSAGE);
        String string5 = getArguments().getString(TAG_NEGATIVE_MESSAGE);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        View inflate = getActivity().getLayoutInflater().inflate(R.layout.dialog_progress_wifi_direct, (ViewGroup) null);
        try {
            mActivity = (DialogButtonClick) getActivity();
        } catch (ClassCastException unused) {
            mActivity = null;
        }
        if (string2 != null) {
            builder.setTitle(string2);
        }
        if (string3 != null) {
            builder.setPositiveButton(string3, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    dismiss();
                    if (mActivity != null) {
                        mActivity.onPositiveClick(mTag);
                    }
                }
            });
        }
        if (string4 != null) {
            builder.setNeutralButton(string4, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    dismiss();
                    if (mActivity != null) {
                        mActivity.onNeutralClick(mTag);
                    }
                }
            });
        }
        if (string5 != null) {
            builder.setNegativeButton(string5, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    dismiss();
                    if (mActivity != null) {
                        mActivity.onNegativeClick(mTag);
                    }
                }
            });
        }
        ProgressBar progressBar = (ProgressBar) inflate.findViewById(R.id.dialog_progress_id);
        if (i == 1) {
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) progressBar.getLayoutParams();
            layoutParams.addRule(14);
            progressBar.setLayoutParams(layoutParams);
            TextView textView = (TextView) inflate.findViewById(R.id.dialog_progress_text_bottom);
            textView.setText(string);
            progressBar.setVisibility(View.VISIBLE);
            textView.setVisibility(View.VISIBLE);
        } else if (i == 0) {
            TextView textView2 = (TextView) inflate.findViewById(R.id.dialog_progress_text_right);
            textView2.setText(string);
            progressBar.setVisibility(View.VISIBLE);
            textView2.setVisibility(View.VISIBLE);
        } else {
            TextView textView3 = (TextView) inflate.findViewById(R.id.dialog_progress_text_right);
            textView3.setText(string);
            textView3.setVisibility(View.VISIBLE);
        }
        builder.setView(inflate);
        return builder.create();
    }

    public void onCancel(DialogInterface dialogInterface) {
        DialogButtonClick dialogButtonClick = mActivity;
        if (dialogButtonClick != null) {
            dialogButtonClick.onCancelDialog(mTag);
        }
        super.onCancel(dialogInterface);
    }

    public void show(FragmentManager fragmentManager, String str) {
        deleteFragment(fragmentManager, str);
        super.showNow(fragmentManager, str);
    }
}
