package com.seewo.libvui.vdialog;

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;
import com.seewo.libmyousdk.model.DubboResponseInfo;
import com.seewo.libvui.c;
import com.seewo.libvui.e;
import com.seewo.libvui.f;
import com.seewo.libvui.g;
import i.a.a.a;
import i.a.b.b.b;

/* 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(e.button_panel).setVisibility(8);
            }
            if (this.mNegativeButton.getVisibility() == 8) {
                this.mBaseLayout.findViewById(e.button_divider).setVisibility(8);
            }
            if (this.mNeutralButton.getVisibility() == 8 || this.mPositiveButton.getVisibility() == 8) {
                this.mBaseLayout.findViewById(e.button_divider_neutral).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 t = (T) createInstance(cls, this.mContext, g.SeewoDialog);
            View viewInflate = layoutInflater.inflate(f.v_dialog_layout, (ViewGroup) null);
            this.mBaseLayout = viewInflate;
            this.mPositiveButton = (TextView) viewInflate.findViewById(e.btn_positive);
            this.mNegativeButton = (TextView) this.mBaseLayout.findViewById(e.btn_negative);
            this.mNeutralButton = (TextView) this.mBaseLayout.findViewById(e.btn_neutral);
            init(this.mBaseLayout, t);
            return t;
        }

        public abstract View getContentView();

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

        protected void initContentPanel(View view) {
            View contentView = getContentView();
            ScrollView scrollView = (ScrollView) view.findViewById(e.content);
            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
                private static final /* synthetic */ a.InterfaceC0131a ajc$tjp_0 = null;

                /* JADX INFO: renamed from: com.seewo.libvui.vdialog.VBaseDialog$Builder$2$AjcClosure1 */
                public class AjcClosure1 extends i.a.b.a.a {
                    public AjcClosure1(Object[] objArr) {
                        super(objArr);
                    }

                    @Override // i.a.b.a.a
                    public Object run(Object[] objArr) {
                        Object[] objArr2 = this.state;
                        AnonymousClass2.onClick_aroundBody0((AnonymousClass2) objArr2[0], (View) objArr2[1], (a) objArr2[2]);
                        return null;
                    }
                }

                static {
                    ajc$preClinit();
                }

                private static /* synthetic */ void ajc$preClinit() {
                    b bVar = new b("VBaseDialog.java", AnonymousClass2.class);
                    ajc$tjp_0 = bVar.f("method-execution", bVar.e(DubboResponseInfo.STATUS_OK, "onClick", "com.seewo.libvui.vdialog.VBaseDialog$Builder$2", "android.view.View", "view", "", "void"), 303);
                }

                static final /* synthetic */ void onClick_aroundBody0(AnonymousClass2 anonymousClass2, View view, a aVar) {
                    DialogInterface.OnClickListener onClickListener = Builder.this.mNegativeButtonClickListener;
                    if (onClickListener != null) {
                        onClickListener.onClick(dialog, -2);
                    }
                    dialog.dismiss();
                }

                @Override // android.view.View.OnClickListener
                public void onClick(View view) throws Throwable {
                    d.e.h.d.a.a.b.k().m(new AjcClosure1(new Object[]{this, view, b.c(ajc$tjp_0, this, this, view)}).linkClosureAndJoinPoint(69648));
                }
            });
            ColorStateList colorStateList = this.mNegativeButtonTextColor;
            if (colorStateList != null) {
                this.mNegativeButton.setTextColor(colorStateList);
            } else {
                this.mNegativeButton.setTextColor(this.mContext.getResources().getColorStateList(com.seewo.libvui.b.edu_dialog_cancel_btn_color));
            }
        }

        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
                private static final /* synthetic */ a.InterfaceC0131a ajc$tjp_0 = null;

                /* JADX INFO: renamed from: com.seewo.libvui.vdialog.VBaseDialog$Builder$3$AjcClosure1 */
                public class AjcClosure1 extends i.a.b.a.a {
                    public AjcClosure1(Object[] objArr) {
                        super(objArr);
                    }

                    @Override // i.a.b.a.a
                    public Object run(Object[] objArr) {
                        Object[] objArr2 = this.state;
                        AnonymousClass3.onClick_aroundBody0((AnonymousClass3) objArr2[0], (View) objArr2[1], (a) objArr2[2]);
                        return null;
                    }
                }

                static {
                    ajc$preClinit();
                }

                private static /* synthetic */ void ajc$preClinit() {
                    b bVar = new b("VBaseDialog.java", AnonymousClass3.class);
                    ajc$tjp_0 = bVar.f("method-execution", bVar.e(DubboResponseInfo.STATUS_OK, "onClick", "com.seewo.libvui.vdialog.VBaseDialog$Builder$3", "android.view.View", "view", "", "void"), 327);
                }

                static final /* synthetic */ void onClick_aroundBody0(AnonymousClass3 anonymousClass3, View view, a aVar) {
                    DialogInterface.OnClickListener onClickListener = Builder.this.mNeutralButtonClickListener;
                    if (onClickListener != null) {
                        onClickListener.onClick(dialog, -3);
                    }
                }

                @Override // android.view.View.OnClickListener
                public void onClick(View view) throws Throwable {
                    d.e.h.d.a.a.b.k().m(new AjcClosure1(new Object[]{this, view, b.c(ajc$tjp_0, this, this, view)}).linkClosureAndJoinPoint(69648));
                }
            });
            ColorStateList colorStateList = this.mNeutralButtonTextColor;
            if (colorStateList != null) {
                this.mNeutralButton.setTextColor(colorStateList);
            } else {
                this.mNeutralButton.setTextColor(this.mContext.getResources().getColorStateList(com.seewo.libvui.b.edu_dialog_cancel_btn_color));
            }
        }

        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
                    private static final /* synthetic */ a.InterfaceC0131a ajc$tjp_0 = null;

                    /* JADX INFO: renamed from: com.seewo.libvui.vdialog.VBaseDialog$Builder$1$AjcClosure1 */
                    public class AjcClosure1 extends i.a.b.a.a {
                        public AjcClosure1(Object[] objArr) {
                            super(objArr);
                        }

                        @Override // i.a.b.a.a
                        public Object run(Object[] objArr) {
                            Object[] objArr2 = this.state;
                            AnonymousClass1.onClick_aroundBody0((AnonymousClass1) objArr2[0], (View) objArr2[1], (a) objArr2[2]);
                            return null;
                        }
                    }

                    static {
                        ajc$preClinit();
                    }

                    private static /* synthetic */ void ajc$preClinit() {
                        b bVar = new b("VBaseDialog.java", AnonymousClass1.class);
                        ajc$tjp_0 = bVar.f("method-execution", bVar.e(DubboResponseInfo.STATUS_OK, "onClick", "com.seewo.libvui.vdialog.VBaseDialog$Builder$1", "android.view.View", "view", "", "void"), 280);
                    }

                    static final /* synthetic */ void onClick_aroundBody0(AnonymousClass1 anonymousClass1, View view, a aVar) {
                        Builder.this.mPositiveButtonClickListener.onClick(dialog, -1);
                    }

                    @Override // android.view.View.OnClickListener
                    public void onClick(View view) throws Throwable {
                        d.e.h.d.a.a.b.k().m(new AjcClosure1(new Object[]{this, view, b.c(ajc$tjp_0, this, this, view)}).linkClosureAndJoinPoint(69648));
                    }
                });
            } else {
                this.mPositiveButton.setVisibility(8);
            }
            ColorStateList colorStateList = this.mPositiveButtonTextColor;
            if (colorStateList != null) {
                this.mPositiveButton.setTextColor(colorStateList);
            } else {
                this.mPositiveButton.setTextColor(this.mContext.getResources().getColorStateList(com.seewo.libvui.b.v_dialog_confirm_btn_color));
            }
        }

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

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

        public Builder setForbidKeyEvent(boolean z) {
            this.mForbidKeyEvent = z;
            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(c.v_dialog_width);
        attributes.height = -2;
        getWindow().setAttributes(attributes);
    }

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