package e;

import android.R;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Message;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewStub;
import android.view.Window;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertController$RecycleListView;
import androidx.core.view.j1;
import androidx.core.view.s1;
import androidx.core.widget.NestedScrollView;
import java.util.WeakHashMap;
import l.z1;

/* JADX INFO: loaded from: classes.dex */
public final class k {
    public TextView A;
    public TextView B;
    public View C;
    public ListAdapter D;
    public final int F;
    public final int G;
    public final int H;
    public final int I;
    public final boolean J;
    public final i K;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f25228a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final o0 f25229b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Window f25230c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final int f25231d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public CharSequence f25232e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public CharSequence f25233f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public AlertController$RecycleListView f25234g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public View f25235h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public int f25236i;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public Button f25238k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public CharSequence f25239l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public Message f25240m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public Drawable f25241n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public Button f25242o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public CharSequence f25243p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public Message f25244q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public Drawable f25245r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Button f25246s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public CharSequence f25247t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public Message f25248u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public Drawable f25249v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public NestedScrollView f25250w;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public Drawable f25252y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public ImageView f25253z;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f25237j = false;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public int f25251x = 0;
    public int E = -1;
    public final f L = new f(this, 0);

    public k(Context context, o0 o0Var, Window window) {
        this.f25228a = context;
        this.f25229b = o0Var;
        this.f25230c = window;
        this.K = new i(o0Var);
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(null, d.j.AlertDialog, d.a.alertDialogStyle, 0);
        this.F = typedArrayObtainStyledAttributes.getResourceId(d.j.AlertDialog_android_layout, 0);
        typedArrayObtainStyledAttributes.getResourceId(d.j.AlertDialog_buttonPanelSideLayout, 0);
        this.G = typedArrayObtainStyledAttributes.getResourceId(d.j.AlertDialog_listLayout, 0);
        typedArrayObtainStyledAttributes.getResourceId(d.j.AlertDialog_multiChoiceItemLayout, 0);
        this.H = typedArrayObtainStyledAttributes.getResourceId(d.j.AlertDialog_singleChoiceItemLayout, 0);
        this.I = typedArrayObtainStyledAttributes.getResourceId(d.j.AlertDialog_listItemLayout, 0);
        this.J = typedArrayObtainStyledAttributes.getBoolean(d.j.AlertDialog_showTitle, true);
        this.f25231d = typedArrayObtainStyledAttributes.getDimensionPixelSize(d.j.AlertDialog_buttonIconDimen, 0);
        typedArrayObtainStyledAttributes.recycle();
        o0Var.d().h(1);
    }

    public static boolean a(View view) {
        if (view.onCheckIsTextEditor()) {
            return true;
        }
        if (!(view instanceof ViewGroup)) {
            return false;
        }
        ViewGroup viewGroup = (ViewGroup) view;
        int childCount = viewGroup.getChildCount();
        while (childCount > 0) {
            childCount--;
            if (a(viewGroup.getChildAt(childCount))) {
                return true;
            }
        }
        return false;
    }

    public static void c(View view, View view2, View view3) {
        if (view2 != null) {
            view2.setVisibility(view.canScrollVertically(-1) ? 0 : 4);
        }
        if (view3 != null) {
            view3.setVisibility(view.canScrollVertically(1) ? 0 : 4);
        }
    }

    @Nullable
    private ViewGroup resolvePanel(@Nullable View view, @Nullable View view2) {
        if (view == null) {
            if (view2 instanceof ViewStub) {
                view2 = ((ViewStub) view2).inflate();
            }
            return (ViewGroup) view2;
        }
        if (view2 != null) {
            ViewParent parent = view2.getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(view2);
            }
        }
        if (view instanceof ViewStub) {
            view = ((ViewStub) view).inflate();
        }
        return (ViewGroup) view;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    public final void b() {
        int i10;
        View view;
        ListAdapter listAdapter;
        View viewFindViewById;
        this.f25229b.setContentView(this.F);
        int i11 = d.f.parentPanel;
        Window window = this.f25230c;
        View viewFindViewById2 = window.findViewById(i11);
        int i12 = d.f.topPanel;
        View viewFindViewById3 = viewFindViewById2.findViewById(i12);
        int i13 = d.f.contentPanel;
        View viewFindViewById4 = viewFindViewById2.findViewById(i13);
        int i14 = d.f.buttonPanel;
        View viewFindViewById5 = viewFindViewById2.findViewById(i14);
        ViewGroup viewGroup = (ViewGroup) viewFindViewById2.findViewById(d.f.customPanel);
        View viewInflate = this.f25235h;
        Context context = this.f25228a;
        if (viewInflate == null) {
            viewInflate = this.f25236i != 0 ? LayoutInflater.from(context).inflate(this.f25236i, viewGroup, false) : null;
        }
        boolean z10 = viewInflate != null;
        if (!z10 || !a(viewInflate)) {
            window.setFlags(131072, 131072);
        }
        if (z10) {
            FrameLayout frameLayout = (FrameLayout) window.findViewById(d.f.custom);
            frameLayout.addView(viewInflate, new ViewGroup.LayoutParams(-1, -1));
            if (this.f25237j) {
                frameLayout.setPadding(0, 0, 0, 0);
            }
            if (this.f25234g != null) {
                ((LinearLayout.LayoutParams) ((z1) viewGroup.getLayoutParams())).weight = 0.0f;
            }
        } else {
            viewGroup.setVisibility(8);
        }
        View viewFindViewById6 = viewGroup.findViewById(i12);
        View viewFindViewById7 = viewGroup.findViewById(i13);
        View viewFindViewById8 = viewGroup.findViewById(i14);
        ViewGroup viewGroupResolvePanel = resolvePanel(viewFindViewById6, viewFindViewById3);
        ViewGroup viewGroupResolvePanel2 = resolvePanel(viewFindViewById7, viewFindViewById4);
        ViewGroup viewGroupResolvePanel3 = resolvePanel(viewFindViewById8, viewFindViewById5);
        NestedScrollView nestedScrollView = (NestedScrollView) window.findViewById(d.f.scrollView);
        this.f25250w = nestedScrollView;
        nestedScrollView.setFocusable(false);
        this.f25250w.setNestedScrollingEnabled(false);
        TextView textView = (TextView) viewGroupResolvePanel2.findViewById(R.id.message);
        this.B = textView;
        if (textView != null) {
            CharSequence charSequence = this.f25233f;
            if (charSequence != null) {
                textView.setText(charSequence);
            } else {
                textView.setVisibility(8);
                this.f25250w.removeView(this.B);
                if (this.f25234g != null) {
                    ViewGroup viewGroup2 = (ViewGroup) this.f25250w.getParent();
                    int iIndexOfChild = viewGroup2.indexOfChild(this.f25250w);
                    viewGroup2.removeViewAt(iIndexOfChild);
                    viewGroup2.addView(this.f25234g, iIndexOfChild, new ViewGroup.LayoutParams(-1, -1));
                } else {
                    viewGroupResolvePanel2.setVisibility(8);
                }
            }
        }
        Button button = (Button) viewGroupResolvePanel3.findViewById(R.id.button1);
        this.f25238k = button;
        f fVar = this.L;
        button.setOnClickListener(fVar);
        boolean zIsEmpty = TextUtils.isEmpty(this.f25239l);
        int i15 = this.f25231d;
        if (zIsEmpty && this.f25241n == null) {
            this.f25238k.setVisibility(8);
            i10 = 0;
        } else {
            this.f25238k.setText(this.f25239l);
            Drawable drawable = this.f25241n;
            if (drawable != null) {
                drawable.setBounds(0, 0, i15, i15);
                this.f25238k.setCompoundDrawables(this.f25241n, null, null, null);
            }
            this.f25238k.setVisibility(0);
            i10 = 1;
        }
        Button button2 = (Button) viewGroupResolvePanel3.findViewById(R.id.button2);
        this.f25242o = button2;
        button2.setOnClickListener(fVar);
        if (TextUtils.isEmpty(this.f25243p) && this.f25245r == null) {
            this.f25242o.setVisibility(8);
        } else {
            this.f25242o.setText(this.f25243p);
            Drawable drawable2 = this.f25245r;
            if (drawable2 != null) {
                drawable2.setBounds(0, 0, i15, i15);
                this.f25242o.setCompoundDrawables(this.f25245r, null, null, null);
            }
            this.f25242o.setVisibility(0);
            i10 |= 2;
        }
        Button button3 = (Button) viewGroupResolvePanel3.findViewById(R.id.button3);
        this.f25246s = button3;
        button3.setOnClickListener(fVar);
        if (TextUtils.isEmpty(this.f25247t) && this.f25249v == null) {
            this.f25246s.setVisibility(8);
            view = null;
        } else {
            this.f25246s.setText(this.f25247t);
            Drawable drawable3 = this.f25249v;
            if (drawable3 != null) {
                drawable3.setBounds(0, 0, i15, i15);
                view = null;
                this.f25246s.setCompoundDrawables(this.f25249v, null, null, null);
            } else {
                view = null;
            }
            this.f25246s.setVisibility(0);
            i10 |= 4;
        }
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(d.a.alertDialogCenterButtons, typedValue, true);
        if (typedValue.data != 0) {
            if (i10 == 1) {
                Button button4 = this.f25238k;
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) button4.getLayoutParams();
                layoutParams.gravity = 1;
                layoutParams.weight = 0.5f;
                button4.setLayoutParams(layoutParams);
            } else if (i10 == 2) {
                Button button5 = this.f25242o;
                LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) button5.getLayoutParams();
                layoutParams2.gravity = 1;
                layoutParams2.weight = 0.5f;
                button5.setLayoutParams(layoutParams2);
            } else if (i10 == 4) {
                Button button6 = this.f25246s;
                LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) button6.getLayoutParams();
                layoutParams3.gravity = 1;
                layoutParams3.weight = 0.5f;
                button6.setLayoutParams(layoutParams3);
            }
        }
        if (i10 == 0) {
            viewGroupResolvePanel3.setVisibility(8);
        }
        if (this.C != null) {
            viewGroupResolvePanel.addView(this.C, 0, new ViewGroup.LayoutParams(-1, -2));
            window.findViewById(d.f.title_template).setVisibility(8);
        } else {
            this.f25253z = (ImageView) window.findViewById(R.id.icon);
            if ((!TextUtils.isEmpty(this.f25232e)) && this.J) {
                TextView textView2 = (TextView) window.findViewById(d.f.alertTitle);
                this.A = textView2;
                textView2.setText(this.f25232e);
                int i16 = this.f25251x;
                if (i16 != 0) {
                    this.f25253z.setImageResource(i16);
                } else {
                    Drawable drawable4 = this.f25252y;
                    if (drawable4 != null) {
                        this.f25253z.setImageDrawable(drawable4);
                    } else {
                        this.A.setPadding(this.f25253z.getPaddingLeft(), this.f25253z.getPaddingTop(), this.f25253z.getPaddingRight(), this.f25253z.getPaddingBottom());
                        this.f25253z.setVisibility(8);
                    }
                }
            } else {
                window.findViewById(d.f.title_template).setVisibility(8);
                this.f25253z.setVisibility(8);
                viewGroupResolvePanel.setVisibility(8);
            }
        }
        boolean z11 = viewGroup.getVisibility() != 8;
        boolean z12 = (viewGroupResolvePanel == null || viewGroupResolvePanel.getVisibility() == 8) ? 0 : 1;
        boolean z13 = viewGroupResolvePanel3.getVisibility() != 8;
        if (!z13 && (viewFindViewById = viewGroupResolvePanel2.findViewById(d.f.textSpacerNoButtons)) != null) {
            viewFindViewById.setVisibility(0);
        }
        if (z12 != 0) {
            NestedScrollView nestedScrollView2 = this.f25250w;
            if (nestedScrollView2 != null) {
                nestedScrollView2.setClipToPadding(true);
            }
            View viewFindViewById9 = (this.f25233f == null && this.f25234g == null) ? view : viewGroupResolvePanel.findViewById(d.f.titleDividerNoCustom);
            if (viewFindViewById9 != null) {
                viewFindViewById9.setVisibility(0);
            }
        } else {
            View viewFindViewById10 = viewGroupResolvePanel2.findViewById(d.f.textSpacerNoTitle);
            if (viewFindViewById10 != null) {
                viewFindViewById10.setVisibility(0);
            }
        }
        AlertController$RecycleListView alertController$RecycleListView = this.f25234g;
        if (alertController$RecycleListView instanceof AlertController$RecycleListView) {
            alertController$RecycleListView.setHasDecor(z12, z13);
        }
        if (!z11) {
            View view2 = this.f25234g;
            if (view2 == null) {
                view2 = this.f25250w;
            }
            if (view2 != null) {
                int i17 = z13 ? 2 : 0;
                View viewFindViewById11 = window.findViewById(d.f.scrollIndicatorUp);
                View viewFindViewById12 = window.findViewById(d.f.scrollIndicatorDown);
                WeakHashMap weakHashMap = s1.f1815a;
                j1.a(view2, z12 | i17, 3);
                if (viewFindViewById11 != null) {
                    viewGroupResolvePanel2.removeView(viewFindViewById11);
                }
                if (viewFindViewById12 != null) {
                    viewGroupResolvePanel2.removeView(viewFindViewById12);
                }
            }
        }
        AlertController$RecycleListView alertController$RecycleListView2 = this.f25234g;
        if (alertController$RecycleListView2 == null || (listAdapter = this.D) == null) {
            return;
        }
        alertController$RecycleListView2.setAdapter(listAdapter);
        int i18 = this.E;
        if (i18 > -1) {
            alertController$RecycleListView2.setItemChecked(i18, true);
            alertController$RecycleListView2.setSelection(i18);
        }
    }

    public final void d(int i10, CharSequence charSequence, DialogInterface.OnClickListener onClickListener) {
        Message messageObtainMessage = onClickListener != null ? this.K.obtainMessage(i10, onClickListener) : null;
        if (i10 == -3) {
            this.f25247t = charSequence;
            this.f25248u = messageObtainMessage;
            this.f25249v = null;
        } else if (i10 == -2) {
            this.f25243p = charSequence;
            this.f25244q = messageObtainMessage;
            this.f25245r = null;
        } else {
            if (i10 != -1) {
                throw new IllegalArgumentException("Button does not exist");
            }
            this.f25239l = charSequence;
            this.f25240m = messageObtainMessage;
            this.f25241n = null;
        }
    }
}
