package com.seewo.libvui.vdialog;

import D0.a;
import D0.b;
import D0.c;
import D0.d;
import D0.e;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

/* JADX INFO: loaded from: classes.dex */
public class VBaseDialog extends Dialog {
    private static final String TAG = "VBaseDialog";

    public static abstract class Builder {
        protected View mBaseLayout;
        boolean mCancelable;
        protected Context mContext;
        protected Dialog mDialog;
        CharSequence mDialogTitle;
        boolean mForbidKeyEvent;
        protected TextView mNegativeButton;
        DialogInterface.OnClickListener mNegativeButtonClickListener;
        String mNegativeButtonText;
        ColorStateList mNegativeButtonTextColor;
        protected TextView mNeutralButton;
        DialogInterface.OnClickListener mNeutralButtonClickListener;
        String mNeutralButtonText;
        ColorStateList mNeutralButtonTextColor;
        DialogInterface.OnCancelListener mOnCancelListener;
        DialogInterface.OnDismissListener mOnDismissListener;
        protected TextView mPositiveButton;
        DialogInterface.OnClickListener mPositiveButtonClickListener;
        String mPositiveButtonText;
        ColorStateList mPositiveButtonTextColor;
        int mPaddingLeft = -1;
        int mPaddingRight = -1;
        int mPaddingTop = -1;
        int mPaddingBottom = -1;
        int mWindowType = -1;

        public Builder(Context context) {
            this.mContext = context;
        }

        private void checkBottomView() {
            if (this.mPositiveButtonText == null && this.mNegativeButtonText == null && this.mNeutralButtonText == null) {
                this.mBaseLayout.findViewById(c.f479g).setVisibility(8);
            }
            if (this.mNegativeButton.getVisibility() == 8) {
                this.mBaseLayout.findViewById(c.f477e).setVisibility(8);
            }
            if (this.mNeutralButton.getVisibility() == 8 || this.mPositiveButton.getVisibility() == 8) {
                this.mBaseLayout.findViewById(c.f478f).setVisibility(8);
            }
        }

        private <T extends VBaseDialog> T createInstance(Class<T> cls, Context context, int i2) {
            try {
                return cls.getConstructor(Context.class, Integer.TYPE).newInstance(context, Integer.valueOf(i2));
            } catch (Exception e2) {
                Log.e(VBaseDialog.TAG, e2.getMessage(), e2);
                throw new IllegalArgumentException("Base dialog newInstance error!");
            }
        }

        private void init(View view, Dialog dialog) {
            this.mDialog = dialog;
            initDialogWindow(dialog);
            initTopPanel(view);
            initContentPanel(view);
            initButtonPanel(dialog);
            dialog.setCancelable(this.mCancelable);
            DialogInterface.OnCancelListener onCancelListener = this.mOnCancelListener;
            if (onCancelListener != null) {
                dialog.setOnCancelListener(onCancelListener);
            }
            DialogInterface.OnDismissListener onDismissListener = this.mOnDismissListener;
            if (onDismissListener != null) {
                dialog.setOnDismissListener(onDismissListener);
            }
            dialog.setContentView(view);
        }

        private void initButtonPanel(Dialog dialog) {
            initPositiveButton(dialog);
            initNegativeButton(dialog);
            initNeutralButton(dialog);
            checkBottomView();
        }

        public <T extends VBaseDialog> T create(Class<T> cls) {
            LayoutInflater layoutInflater = (LayoutInflater) this.mContext.getSystemService("layout_inflater");
            T t2 = (T) createInstance(cls, this.mContext, e.f498a);
            View viewInflate = layoutInflater.inflate(d.f496f, (ViewGroup) null);
            this.mBaseLayout = viewInflate;
            this.mPositiveButton = (TextView) viewInflate.findViewById(c.f476d);
            this.mNegativeButton = (TextView) this.mBaseLayout.findViewById(c.f474b);
            this.mNeutralButton = (TextView) this.mBaseLayout.findViewById(c.f475c);
            init(this.mBaseLayout, t2);
            return t2;
        }

        public abstract View getContentView();

        public String getPositiveButtonText() {
            return this.mPositiveButtonText;
        }

        protected void initContentPanel(View view) {
            View contentView = getContentView();
            ScrollView scrollView = (ScrollView) view.findViewById(c.f480h);
            scrollView.removeAllViews();
            if (this.mPaddingLeft == -1) {
                this.mPaddingLeft = scrollView.getPaddingLeft();
            }
            if (this.mPaddingRight == -1) {
                this.mPaddingRight = scrollView.getPaddingRight();
            }
            if (this.mPaddingTop == -1) {
                this.mPaddingTop = scrollView.getPaddingTop();
            }
            if (this.mPaddingBottom == -1) {
                this.mPaddingBottom = scrollView.getPaddingBottom();
            }
            scrollView.setPadding(this.mPaddingLeft, this.mPaddingTop, this.mPaddingRight, this.mPaddingBottom);
            scrollView.addView(contentView, new ViewGroup.LayoutParams(-1, -2));
        }

        protected void initDialogWindow(Dialog dialog) {
            Window window = dialog.getWindow();
            window.requestFeature(1);
            int i2 = this.mWindowType;
            if (i2 != -1) {
                window.setType(i2);
            }
        }

        protected void initNegativeButton(final Dialog dialog) {
            if (this.mNegativeButtonText == null) {
                this.mNegativeButton.setVisibility(8);
                return;
            }
            this.mNegativeButton.setVisibility(0);
            this.mNegativeButton.setText(this.mNegativeButtonText);
            this.mNegativeButton.setOnClickListener(new View.OnClickListener() { // from class: com.seewo.libvui.vdialog.VBaseDialog.Builder.2
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    DialogInterface.OnClickListener onClickListener = Builder.this.mNegativeButtonClickListener;
                    if (onClickListener != null) {
                        onClickListener.onClick(dialog, -2);
                    }
                    dialog.dismiss();
                }
            });
            ColorStateList colorStateList = this.mNegativeButtonTextColor;
            if (colorStateList != null) {
                this.mNegativeButton.setTextColor(colorStateList);
            } else {
                this.mNegativeButton.setTextColor(this.mContext.getResources().getColorStateList(a.f465a));
            }
        }

        protected void initNeutralButton(final Dialog dialog) {
            if (this.mNeutralButtonText == null) {
                this.mNeutralButton.setVisibility(8);
                return;
            }
            this.mNeutralButton.setVisibility(0);
            this.mNeutralButton.setText(this.mNeutralButtonText);
            this.mNeutralButton.setOnClickListener(new View.OnClickListener() { // from class: com.seewo.libvui.vdialog.VBaseDialog.Builder.3
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    DialogInterface.OnClickListener onClickListener = Builder.this.mNeutralButtonClickListener;
                    if (onClickListener != null) {
                        onClickListener.onClick(dialog, -3);
                    }
                }
            });
            ColorStateList colorStateList = this.mNeutralButtonTextColor;
            if (colorStateList != null) {
                this.mNeutralButton.setTextColor(colorStateList);
            } else {
                this.mNeutralButton.setTextColor(this.mContext.getResources().getColorStateList(a.f465a));
            }
        }

        protected void initPositiveButton(final Dialog dialog) {
            if (this.mPositiveButtonText == null) {
                this.mPositiveButton.setVisibility(8);
                return;
            }
            this.mPositiveButton.setVisibility(0);
            this.mPositiveButton.setText(this.mPositiveButtonText);
            if (this.mPositiveButtonClickListener != null) {
                this.mPositiveButton.setOnClickListener(new View.OnClickListener() { // from class: com.seewo.libvui.vdialog.VBaseDialog.Builder.1
                    @Override // android.view.View.OnClickListener
                    public void onClick(View view) {
                        Builder.this.mPositiveButtonClickListener.onClick(dialog, -1);
                    }
                });
            } else {
                this.mPositiveButton.setVisibility(8);
            }
            ColorStateList colorStateList = this.mPositiveButtonTextColor;
            if (colorStateList != null) {
                this.mPositiveButton.setTextColor(colorStateList);
            } else {
                this.mPositiveButton.setTextColor(this.mContext.getResources().getColorStateList(a.f467c));
            }
        }

        protected void initTopPanel(View view) {
            ((TextView) view.findViewById(c.f482j)).setText(this.mDialogTitle);
        }

        public Builder setCancelable(boolean z2) {
            this.mCancelable = z2;
            return this;
        }

        public Builder setForbidKeyEvent(boolean z2) {
            this.mForbidKeyEvent = z2;
            return this;
        }

        public void setListViewHeightBasedOnChildren(ListView listView) {
            ListAdapter adapter = listView.getAdapter();
            if (adapter == null) {
                return;
            }
            int count = adapter.getCount();
            int measuredHeight = 0;
            for (int i2 = 0; i2 < count; i2++) {
                View view = adapter.getView(i2, null, listView);
                view.measure(0, 0);
                measuredHeight += view.getMeasuredHeight();
            }
            ViewGroup.LayoutParams layoutParams = listView.getLayoutParams();
            layoutParams.height = measuredHeight + (listView.getDividerHeight() * (count - 1));
            listView.setLayoutParams(layoutParams);
        }

        public Builder setNegativeButton(int i2, DialogInterface.OnClickListener onClickListener) {
            setNegativeButton((String) this.mContext.getText(i2), onClickListener);
            return this;
        }

        public Builder setNegativeButtonColorSelector(ColorStateList colorStateList) {
            this.mNegativeButtonTextColor = colorStateList;
            return this;
        }

        public Builder setNeutralButton(int i2, DialogInterface.OnClickListener onClickListener) {
            setNeutralButton((String) this.mContext.getText(i2), onClickListener);
            return this;
        }

        public Builder setNeutralButtonColorSelector(int i2) {
            this.mNeutralButtonTextColor = this.mContext.getResources().getColorStateList(i2);
            return this;
        }

        public Builder setOnCancelListener(DialogInterface.OnCancelListener onCancelListener) {
            this.mOnCancelListener = onCancelListener;
            return this;
        }

        public Builder setOnDissmissListener(DialogInterface.OnDismissListener onDismissListener) {
            this.mOnDismissListener = onDismissListener;
            return this;
        }

        public Builder setPaddingBottom(int i2) {
            this.mPaddingBottom = i2;
            return this;
        }

        public Builder setPaddingLeft(int i2) {
            this.mPaddingLeft = i2;
            return this;
        }

        public Builder setPaddingRight(int i2) {
            this.mPaddingRight = i2;
            return this;
        }

        public Builder setPaddingTop(int i2) {
            this.mPaddingTop = i2;
            return this;
        }

        public Builder setPositiveButton(int i2, DialogInterface.OnClickListener onClickListener) {
            setPositiveButton((String) this.mContext.getText(i2), onClickListener);
            return this;
        }

        public Builder setPositiveButtonColorSelector(ColorStateList colorStateList) {
            this.mPositiveButtonTextColor = colorStateList;
            return this;
        }

        public Builder setTitle(int i2) {
            this.mDialogTitle = (String) this.mContext.getText(i2);
            return this;
        }

        public Builder setWindowType(int i2) {
            this.mWindowType = i2;
            return this;
        }

        public Builder setNegativeButton(String str, DialogInterface.OnClickListener onClickListener) {
            this.mNegativeButtonText = str;
            this.mNegativeButtonClickListener = onClickListener;
            return this;
        }

        public Builder setNegativeButtonColorSelector(int i2) {
            this.mNegativeButtonTextColor = this.mContext.getResources().getColorStateList(i2);
            return this;
        }

        public Builder setNeutralButton(String str, DialogInterface.OnClickListener onClickListener) {
            this.mNeutralButtonText = str;
            this.mNeutralButtonClickListener = onClickListener;
            return this;
        }

        public Builder setNeutralButtonColorSelector(ColorStateList colorStateList) {
            this.mNeutralButtonTextColor = colorStateList;
            return this;
        }

        public Builder setPositiveButton(String str, DialogInterface.OnClickListener onClickListener) {
            this.mPositiveButtonText = str;
            this.mPositiveButtonClickListener = onClickListener;
            return this;
        }

        public Builder setPositiveButtonColorSelector(int i2) {
            this.mPositiveButtonTextColor = this.mContext.getResources().getColorStateList(i2);
            return this;
        }

        public Builder setTitle(CharSequence charSequence) {
            this.mDialogTitle = charSequence;
            return this;
        }
    }

    public VBaseDialog(Context context, int i2) {
        super(context, i2);
    }

    @Override // android.app.Dialog
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.gravity = 17;
        attributes.width = getContext().getResources().getDimensionPixelOffset(b.f472e);
        attributes.height = -2;
        getWindow().setAttributes(attributes);
    }

    public VBaseDialog(Context context) {
        super(context);
    }
}
