package o;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
import androidx.appcompat.app.AlertController$RecycleListView;
import androidx.core.widget.NestedScrollView;
import com.google.android.gms.common.R;
import java.lang.reflect.InvocationTargetException;
import java.util.WeakHashMap;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.h2, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class DialogInterfaceC1350h2 extends DialogC0269Kj implements DialogInterface, InterfaceC2879x7 {
    public S7 p;
    public final T7 q;
    public final C1158f2 r;

    /* JADX WARN: Type inference failed for: r2v2, types: [o.T7] */
    public DialogInterfaceC1350h2(ContextThemeWrapper contextThemeWrapper, int i) {
        int i2;
        int iE = e(contextThemeWrapper, i);
        if (iE == 0) {
            TypedValue typedValue = new TypedValue();
            contextThemeWrapper.getTheme().resolveAttribute(R.attr.dialogTheme, typedValue, true);
            i2 = typedValue.resourceId;
        } else {
            i2 = iE;
        }
        super(contextThemeWrapper, i2);
        this.q = new HJ() { // from class: o.T7
            @Override // o.HJ
            public final boolean superDispatchKeyEvent(KeyEvent keyEvent) {
                return this.l.g(keyEvent);
            }
        };
        F7 f7C = c();
        if (iE == 0) {
            TypedValue typedValue2 = new TypedValue();
            contextThemeWrapper.getTheme().resolveAttribute(R.attr.dialogTheme, typedValue2, true);
            iE = typedValue2.resourceId;
        }
        ((S7) f7C).e0 = iE;
        f7C.c();
        this.r = new C1158f2(getContext(), this, getWindow());
    }

    public static int e(Context context, int i) {
        if (((i >>> 24) & 255) >= 1) {
            return i;
        }
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.alertDialogTheme, typedValue, true);
        return typedValue.resourceId;
    }

    @Override // o.DialogC0269Kj, android.app.Dialog
    public final void addContentView(View view, ViewGroup.LayoutParams layoutParams) throws IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
        b();
        S7 s7 = (S7) c();
        s7.w();
        ((ViewGroup) s7.L.findViewById(android.R.id.content)).addView(view, layoutParams);
        s7.x.a(s7.w.getCallback());
    }

    public final F7 c() {
        if (this.p == null) {
            E7 e7 = F7.l;
            this.p = new S7(getContext(), getWindow(), this, this);
        }
        return this.p;
    }

    public final void d(Bundle bundle) {
        S7 s7 = (S7) c();
        LayoutInflater layoutInflaterFrom = LayoutInflater.from(s7.v);
        if (layoutInflaterFrom.getFactory() == null) {
            layoutInflaterFrom.setFactory2(s7);
        } else {
            layoutInflaterFrom.getFactory2();
        }
        super.onCreate(bundle);
        c().c();
    }

    @Override // android.app.Dialog, android.content.DialogInterface
    public final void dismiss() {
        super.dismiss();
        c().d();
    }

    @Override // android.app.Dialog, android.view.Window.Callback
    public final boolean dispatchKeyEvent(KeyEvent keyEvent) {
        return YT.u(this.q, getWindow().getDecorView(), this, keyEvent);
    }

    public final void f(CharSequence charSequence) {
        super.setTitle(charSequence);
        c().j(charSequence);
    }

    @Override // android.app.Dialog
    public final View findViewById(int i) throws IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
        S7 s7 = (S7) c();
        s7.w();
        return s7.w.findViewById(i);
    }

    public final boolean g(KeyEvent keyEvent) {
        return super.dispatchKeyEvent(keyEvent);
    }

    @Override // android.app.Dialog
    public final void invalidateOptionsMenu() {
        c().a();
    }

    @Override // o.DialogC0269Kj, android.app.Dialog
    public final void onCreate(Bundle bundle) {
        int i;
        ListAdapter listAdapter;
        View viewFindViewById;
        d(bundle);
        C1158f2 c1158f2 = this.r;
        c1158f2.b.setContentView(c1158f2.x);
        Context context = c1158f2.a;
        Window window = c1158f2.c;
        View viewFindViewById2 = window.findViewById(R.id.parentPanel);
        View viewFindViewById3 = viewFindViewById2.findViewById(R.id.topPanel);
        View viewFindViewById4 = viewFindViewById2.findViewById(R.id.contentPanel);
        View viewFindViewById5 = viewFindViewById2.findViewById(R.id.buttonPanel);
        ViewGroup viewGroup = (ViewGroup) viewFindViewById2.findViewById(R.id.customPanel);
        window.setFlags(131072, 131072);
        viewGroup.setVisibility(8);
        View viewFindViewById6 = viewGroup.findViewById(R.id.topPanel);
        View viewFindViewById7 = viewGroup.findViewById(R.id.contentPanel);
        View viewFindViewById8 = viewGroup.findViewById(R.id.buttonPanel);
        ViewGroup viewGroupA = C1158f2.a(viewFindViewById6, viewFindViewById3);
        ViewGroup viewGroupA2 = C1158f2.a(viewFindViewById7, viewFindViewById4);
        ViewGroup viewGroupA3 = C1158f2.a(viewFindViewById8, viewFindViewById5);
        NestedScrollView nestedScrollView = (NestedScrollView) window.findViewById(R.id.scrollView);
        c1158f2.p = nestedScrollView;
        nestedScrollView.setFocusable(false);
        c1158f2.p.setNestedScrollingEnabled(false);
        TextView textView = (TextView) viewGroupA2.findViewById(android.R.id.message);
        c1158f2.t = textView;
        if (textView != null) {
            String str = c1158f2.e;
            if (str != null) {
                textView.setText(str);
            } else {
                textView.setVisibility(8);
                c1158f2.p.removeView(c1158f2.t);
                if (c1158f2.f != null) {
                    ViewGroup viewGroup2 = (ViewGroup) c1158f2.p.getParent();
                    int iIndexOfChild = viewGroup2.indexOfChild(c1158f2.p);
                    viewGroup2.removeViewAt(iIndexOfChild);
                    viewGroup2.addView(c1158f2.f, iIndexOfChild, new ViewGroup.LayoutParams(-1, -1));
                } else {
                    viewGroupA2.setVisibility(8);
                }
            }
        }
        Button button = (Button) viewGroupA3.findViewById(android.R.id.button1);
        c1158f2.g = button;
        V0 v0 = c1158f2.D;
        button.setOnClickListener(v0);
        if (TextUtils.isEmpty(c1158f2.h)) {
            c1158f2.g.setVisibility(8);
            i = 0;
        } else {
            c1158f2.g.setText(c1158f2.h);
            c1158f2.g.setVisibility(0);
            i = 1;
        }
        Button button2 = (Button) viewGroupA3.findViewById(android.R.id.button2);
        c1158f2.j = button2;
        button2.setOnClickListener(v0);
        if (TextUtils.isEmpty(c1158f2.k)) {
            c1158f2.j.setVisibility(8);
        } else {
            c1158f2.j.setText(c1158f2.k);
            c1158f2.j.setVisibility(0);
            i |= 2;
        }
        Button button3 = (Button) viewGroupA3.findViewById(android.R.id.button3);
        c1158f2.m = button3;
        button3.setOnClickListener(v0);
        if (TextUtils.isEmpty(c1158f2.n)) {
            c1158f2.m.setVisibility(8);
        } else {
            c1158f2.m.setText(c1158f2.n);
            c1158f2.m.setVisibility(0);
            i |= 4;
        }
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.alertDialogCenterButtons, typedValue, true);
        if (typedValue.data != 0) {
            if (i == 1) {
                Button button4 = c1158f2.g;
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) button4.getLayoutParams();
                layoutParams.gravity = 1;
                layoutParams.weight = 0.5f;
                button4.setLayoutParams(layoutParams);
            } else if (i == 2) {
                Button button5 = c1158f2.j;
                LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) button5.getLayoutParams();
                layoutParams2.gravity = 1;
                layoutParams2.weight = 0.5f;
                button5.setLayoutParams(layoutParams2);
            } else if (i == 4) {
                Button button6 = c1158f2.m;
                LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) button6.getLayoutParams();
                layoutParams3.gravity = 1;
                layoutParams3.weight = 0.5f;
                button6.setLayoutParams(layoutParams3);
            }
        }
        if (i == 0) {
            viewGroupA3.setVisibility(8);
        }
        if (c1158f2.u != null) {
            viewGroupA.addView(c1158f2.u, 0, new ViewGroup.LayoutParams(-1, -2));
            window.findViewById(R.id.title_template).setVisibility(8);
        } else {
            c1158f2.r = (ImageView) window.findViewById(android.R.id.icon);
            if (TextUtils.isEmpty(c1158f2.d) || !c1158f2.B) {
                window.findViewById(R.id.title_template).setVisibility(8);
                c1158f2.r.setVisibility(8);
                viewGroupA.setVisibility(8);
            } else {
                TextView textView2 = (TextView) window.findViewById(R.id.alertTitle);
                c1158f2.s = textView2;
                textView2.setText(c1158f2.d);
                Drawable drawable = c1158f2.q;
                if (drawable != null) {
                    c1158f2.r.setImageDrawable(drawable);
                } else {
                    c1158f2.s.setPadding(c1158f2.r.getPaddingLeft(), c1158f2.r.getPaddingTop(), c1158f2.r.getPaddingRight(), c1158f2.r.getPaddingBottom());
                    c1158f2.r.setVisibility(8);
                }
            }
        }
        boolean z = viewGroup.getVisibility() != 8;
        int i2 = (viewGroupA == null || viewGroupA.getVisibility() == 8) ? 0 : 1;
        boolean z2 = viewGroupA3.getVisibility() != 8;
        if (!z2 && (viewFindViewById = viewGroupA2.findViewById(R.id.textSpacerNoButtons)) != null) {
            viewFindViewById.setVisibility(0);
        }
        if (i2 != 0) {
            NestedScrollView nestedScrollView2 = c1158f2.p;
            if (nestedScrollView2 != null) {
                nestedScrollView2.setClipToPadding(true);
            }
            View viewFindViewById9 = (c1158f2.e == null && c1158f2.f == null) ? null : viewGroupA.findViewById(R.id.titleDividerNoCustom);
            if (viewFindViewById9 != null) {
                viewFindViewById9.setVisibility(0);
            }
        } else {
            View viewFindViewById10 = viewGroupA2.findViewById(R.id.textSpacerNoTitle);
            if (viewFindViewById10 != null) {
                viewFindViewById10.setVisibility(0);
            }
        }
        AlertController$RecycleListView alertController$RecycleListView = c1158f2.f;
        if (alertController$RecycleListView != null && (!z2 || i2 == 0)) {
            alertController$RecycleListView.setPadding(alertController$RecycleListView.getPaddingLeft(), i2 != 0 ? alertController$RecycleListView.getPaddingTop() : alertController$RecycleListView.l, alertController$RecycleListView.getPaddingRight(), z2 ? alertController$RecycleListView.getPaddingBottom() : alertController$RecycleListView.m);
        }
        if (!z) {
            View view = c1158f2.f;
            if (view == null) {
                view = c1158f2.p;
            }
            if (view != null) {
                int i3 = z2 ? 2 : 0;
                View viewFindViewById11 = window.findViewById(R.id.scrollIndicatorUp);
                View viewFindViewById12 = window.findViewById(R.id.scrollIndicatorDown);
                WeakHashMap weakHashMap = Oj0.a;
                Hj0.b(view, i2 | i3, 3);
                if (viewFindViewById11 != null) {
                    viewGroupA2.removeView(viewFindViewById11);
                }
                if (viewFindViewById12 != null) {
                    viewGroupA2.removeView(viewFindViewById12);
                }
            }
        }
        AlertController$RecycleListView alertController$RecycleListView2 = c1158f2.f;
        if (alertController$RecycleListView2 == null || (listAdapter = c1158f2.v) == null) {
            return;
        }
        alertController$RecycleListView2.setAdapter(listAdapter);
        int i4 = c1158f2.w;
        if (i4 > -1) {
            alertController$RecycleListView2.setItemChecked(i4, true);
            alertController$RecycleListView2.setSelection(i4);
        }
    }

    @Override // android.app.Dialog, android.view.KeyEvent.Callback
    public final boolean onKeyDown(int i, KeyEvent keyEvent) {
        NestedScrollView nestedScrollView = this.r.p;
        if (nestedScrollView == null || !nestedScrollView.j(keyEvent)) {
            return super.onKeyDown(i, keyEvent);
        }
        return true;
    }

    @Override // android.app.Dialog, android.view.KeyEvent.Callback
    public final boolean onKeyUp(int i, KeyEvent keyEvent) {
        NestedScrollView nestedScrollView = this.r.p;
        if (nestedScrollView == null || !nestedScrollView.j(keyEvent)) {
            return super.onKeyUp(i, keyEvent);
        }
        return true;
    }

    @Override // o.DialogC0269Kj, android.app.Dialog
    public final void onStop() throws IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
        super.onStop();
        S7 s7 = (S7) c();
        s7.A();
        T0 t0 = s7.z;
        if (t0 != null) {
            t0.m(false);
        }
    }

    @Override // o.InterfaceC2879x7
    public final AbstractC1918n1 onWindowStartingSupportActionMode(InterfaceC1823m1 interfaceC1823m1) {
        return null;
    }

    @Override // o.DialogC0269Kj, android.app.Dialog
    public final void setContentView(int i) {
        b();
        c().g(i);
    }

    @Override // android.app.Dialog
    public final void setTitle(int i) {
        super.setTitle(i);
        c().j(getContext().getString(i));
    }

    @Override // o.DialogC0269Kj, android.app.Dialog
    public final void setContentView(View view) {
        b();
        c().h(view);
    }

    @Override // android.app.Dialog
    public final void setTitle(CharSequence charSequence) {
        f(charSequence);
        C1158f2 c1158f2 = this.r;
        c1158f2.d = charSequence;
        TextView textView = c1158f2.s;
        if (textView != null) {
            textView.setText(charSequence);
        }
    }

    @Override // o.DialogC0269Kj, android.app.Dialog
    public final void setContentView(View view, ViewGroup.LayoutParams layoutParams) {
        b();
        c().i(view, layoutParams);
    }

    @Override // o.InterfaceC2879x7
    public final void onSupportActionModeFinished(AbstractC1918n1 abstractC1918n1) {
    }

    @Override // o.InterfaceC2879x7
    public final void onSupportActionModeStarted(AbstractC1918n1 abstractC1918n1) {
    }
}
