package d.b.c;

import android.R;
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.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.AlertController;
import androidx.core.widget.NestedScrollView;
import d.b.g.k0;
import d.h.j.y;
import io.netty.handler.codec.dns.DnsRecord;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public class e extends n implements DialogInterface {

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final AlertController f1557n;

    public static class a {
        public final AlertController.b a;

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

        public a(Context context) {
            int iC = e.c(context, 0);
            this.a = new AlertController.b(new ContextThemeWrapper(context, e.c(context, iC)));
            this.f1558b = iC;
        }

        public e a() {
            e eVar = new e(this.a.a, this.f1558b);
            AlertController.b bVar = this.a;
            AlertController alertController = eVar.f1557n;
            View view = bVar.f426e;
            if (view != null) {
                alertController.G = view;
            } else {
                CharSequence charSequence = bVar.f425d;
                if (charSequence != null) {
                    alertController.f398e = charSequence;
                    TextView textView = alertController.E;
                    if (textView != null) {
                        textView.setText(charSequence);
                    }
                }
                Drawable drawable = bVar.f424c;
                if (drawable != null) {
                    alertController.C = drawable;
                    alertController.B = 0;
                    ImageView imageView = alertController.D;
                    if (imageView != null) {
                        imageView.setVisibility(0);
                        alertController.D.setImageDrawable(drawable);
                    }
                }
            }
            if (bVar.f428g != null) {
                AlertController.RecycleListView recycleListView = (AlertController.RecycleListView) bVar.f423b.inflate(alertController.L, (ViewGroup) null);
                int i2 = bVar.f430i ? alertController.N : alertController.O;
                ListAdapter dVar = bVar.f428g;
                if (dVar == null) {
                    dVar = new AlertController.d(bVar.a, i2, R.id.text1, null);
                }
                alertController.H = dVar;
                alertController.I = bVar.f431j;
                if (bVar.f429h != null) {
                    recycleListView.setOnItemClickListener(new d(bVar, alertController));
                }
                if (bVar.f430i) {
                    recycleListView.setChoiceMode(1);
                }
                alertController.f400g = recycleListView;
            }
            Objects.requireNonNull(this.a);
            eVar.setCancelable(true);
            Objects.requireNonNull(this.a);
            eVar.setCanceledOnTouchOutside(true);
            Objects.requireNonNull(this.a);
            eVar.setOnCancelListener(null);
            Objects.requireNonNull(this.a);
            eVar.setOnDismissListener(null);
            DialogInterface.OnKeyListener onKeyListener = this.a.f427f;
            if (onKeyListener != null) {
                eVar.setOnKeyListener(onKeyListener);
            }
            return eVar;
        }
    }

    public e(Context context, int i2) {
        super(context, c(context, i2));
        this.f1557n = new AlertController(getContext(), this, getWindow());
    }

    public static int c(Context context, int i2) {
        if (((i2 >>> 24) & DnsRecord.CLASS_ANY) >= 1) {
            return i2;
        }
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(com.ifpdos.udi.service.core.pc.R.attr.alertDialogTheme, typedValue, true);
        return typedValue.resourceId;
    }

    @Override // d.b.c.n, android.app.Dialog
    public void onCreate(Bundle bundle) {
        int i2;
        View view;
        ListAdapter listAdapter;
        View viewFindViewById;
        Button button;
        super.onCreate(bundle);
        AlertController alertController = this.f1557n;
        int i3 = alertController.K;
        alertController.f395b.setContentView(alertController.J);
        View viewFindViewById2 = alertController.f396c.findViewById(com.ifpdos.udi.service.core.pc.R.id.parentPanel);
        View viewFindViewById3 = viewFindViewById2.findViewById(com.ifpdos.udi.service.core.pc.R.id.topPanel);
        View viewFindViewById4 = viewFindViewById2.findViewById(com.ifpdos.udi.service.core.pc.R.id.contentPanel);
        View viewFindViewById5 = viewFindViewById2.findViewById(com.ifpdos.udi.service.core.pc.R.id.buttonPanel);
        ViewGroup viewGroup = (ViewGroup) viewFindViewById2.findViewById(com.ifpdos.udi.service.core.pc.R.id.customPanel);
        View viewInflate = alertController.f401h;
        if (viewInflate == null) {
            viewInflate = alertController.f402i != 0 ? LayoutInflater.from(alertController.a).inflate(alertController.f402i, viewGroup, false) : null;
        }
        boolean z2 = viewInflate != null;
        if (!z2 || !AlertController.a(viewInflate)) {
            alertController.f396c.setFlags(131072, 131072);
        }
        if (z2) {
            FrameLayout frameLayout = (FrameLayout) alertController.f396c.findViewById(com.ifpdos.udi.service.core.pc.R.id.custom);
            frameLayout.addView(viewInflate, new ViewGroup.LayoutParams(-1, -1));
            if (alertController.f407n) {
                frameLayout.setPadding(alertController.f403j, alertController.f404k, alertController.f405l, alertController.f406m);
            }
            if (alertController.f400g != null) {
                ((LinearLayout.LayoutParams) ((k0.a) viewGroup.getLayoutParams())).weight = 0.0f;
            }
        } else {
            viewGroup.setVisibility(8);
        }
        View viewFindViewById6 = viewGroup.findViewById(com.ifpdos.udi.service.core.pc.R.id.topPanel);
        View viewFindViewById7 = viewGroup.findViewById(com.ifpdos.udi.service.core.pc.R.id.contentPanel);
        View viewFindViewById8 = viewGroup.findViewById(com.ifpdos.udi.service.core.pc.R.id.buttonPanel);
        ViewGroup viewGroupD = alertController.d(viewFindViewById6, viewFindViewById3);
        ViewGroup viewGroupD2 = alertController.d(viewFindViewById7, viewFindViewById4);
        ViewGroup viewGroupD3 = alertController.d(viewFindViewById8, viewFindViewById5);
        NestedScrollView nestedScrollView = (NestedScrollView) alertController.f396c.findViewById(com.ifpdos.udi.service.core.pc.R.id.scrollView);
        alertController.A = nestedScrollView;
        nestedScrollView.setFocusable(false);
        alertController.A.setNestedScrollingEnabled(false);
        TextView textView = (TextView) viewGroupD2.findViewById(R.id.message);
        alertController.F = textView;
        if (textView != null) {
            CharSequence charSequence = alertController.f399f;
            if (charSequence != null) {
                textView.setText(charSequence);
            } else {
                textView.setVisibility(8);
                alertController.A.removeView(alertController.F);
                if (alertController.f400g != null) {
                    ViewGroup viewGroup2 = (ViewGroup) alertController.A.getParent();
                    int iIndexOfChild = viewGroup2.indexOfChild(alertController.A);
                    viewGroup2.removeViewAt(iIndexOfChild);
                    viewGroup2.addView(alertController.f400g, iIndexOfChild, new ViewGroup.LayoutParams(-1, -1));
                } else {
                    viewGroupD2.setVisibility(8);
                }
            }
        }
        Button button2 = (Button) viewGroupD3.findViewById(R.id.button1);
        alertController.f408o = button2;
        button2.setOnClickListener(alertController.R);
        if (TextUtils.isEmpty(alertController.f409p) && alertController.f411r == null) {
            alertController.f408o.setVisibility(8);
            i2 = 0;
        } else {
            alertController.f408o.setText(alertController.f409p);
            Drawable drawable = alertController.f411r;
            if (drawable != null) {
                int i4 = alertController.f397d;
                drawable.setBounds(0, 0, i4, i4);
                alertController.f408o.setCompoundDrawables(alertController.f411r, null, null, null);
            }
            alertController.f408o.setVisibility(0);
            i2 = 1;
        }
        Button button3 = (Button) viewGroupD3.findViewById(R.id.button2);
        alertController.f412s = button3;
        button3.setOnClickListener(alertController.R);
        if (TextUtils.isEmpty(alertController.f413t) && alertController.f415v == null) {
            alertController.f412s.setVisibility(8);
        } else {
            alertController.f412s.setText(alertController.f413t);
            Drawable drawable2 = alertController.f415v;
            if (drawable2 != null) {
                int i5 = alertController.f397d;
                drawable2.setBounds(0, 0, i5, i5);
                alertController.f412s.setCompoundDrawables(alertController.f415v, null, null, null);
            }
            alertController.f412s.setVisibility(0);
            i2 |= 2;
        }
        Button button4 = (Button) viewGroupD3.findViewById(R.id.button3);
        alertController.f416w = button4;
        button4.setOnClickListener(alertController.R);
        if (TextUtils.isEmpty(alertController.f417x) && alertController.f419z == null) {
            alertController.f416w.setVisibility(8);
            view = null;
        } else {
            alertController.f416w.setText(alertController.f417x);
            Drawable drawable3 = alertController.f419z;
            if (drawable3 != null) {
                int i6 = alertController.f397d;
                drawable3.setBounds(0, 0, i6, i6);
                view = null;
                alertController.f416w.setCompoundDrawables(alertController.f419z, null, null, null);
            } else {
                view = null;
            }
            alertController.f416w.setVisibility(0);
            i2 |= 4;
        }
        Context context = alertController.a;
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(com.ifpdos.udi.service.core.pc.R.attr.alertDialogCenterButtons, typedValue, true);
        if (typedValue.data != 0) {
            if (i2 == 1) {
                button = alertController.f408o;
            } else if (i2 == 2) {
                button = alertController.f412s;
            } else if (i2 == 4) {
                button = alertController.f416w;
            }
            alertController.b(button);
        }
        if (!(i2 != 0)) {
            viewGroupD3.setVisibility(8);
        }
        if (alertController.G != null) {
            viewGroupD.addView(alertController.G, 0, new ViewGroup.LayoutParams(-1, -2));
            alertController.f396c.findViewById(com.ifpdos.udi.service.core.pc.R.id.title_template).setVisibility(8);
        } else {
            alertController.D = (ImageView) alertController.f396c.findViewById(R.id.icon);
            if ((!TextUtils.isEmpty(alertController.f398e)) && alertController.P) {
                TextView textView2 = (TextView) alertController.f396c.findViewById(com.ifpdos.udi.service.core.pc.R.id.alertTitle);
                alertController.E = textView2;
                textView2.setText(alertController.f398e);
                int i7 = alertController.B;
                if (i7 != 0) {
                    alertController.D.setImageResource(i7);
                } else {
                    Drawable drawable4 = alertController.C;
                    if (drawable4 != null) {
                        alertController.D.setImageDrawable(drawable4);
                    } else {
                        alertController.E.setPadding(alertController.D.getPaddingLeft(), alertController.D.getPaddingTop(), alertController.D.getPaddingRight(), alertController.D.getPaddingBottom());
                        alertController.D.setVisibility(8);
                    }
                }
            } else {
                alertController.f396c.findViewById(com.ifpdos.udi.service.core.pc.R.id.title_template).setVisibility(8);
                alertController.D.setVisibility(8);
                viewGroupD.setVisibility(8);
            }
        }
        boolean z3 = viewGroup.getVisibility() != 8;
        int i8 = (viewGroupD == null || viewGroupD.getVisibility() == 8) ? 0 : 1;
        boolean z4 = viewGroupD3.getVisibility() != 8;
        if (!z4 && (viewFindViewById = viewGroupD2.findViewById(com.ifpdos.udi.service.core.pc.R.id.textSpacerNoButtons)) != null) {
            viewFindViewById.setVisibility(0);
        }
        if (i8 != 0) {
            NestedScrollView nestedScrollView2 = alertController.A;
            if (nestedScrollView2 != null) {
                nestedScrollView2.setClipToPadding(true);
            }
            View viewFindViewById9 = (alertController.f399f == null && alertController.f400g == null) ? view : viewGroupD.findViewById(com.ifpdos.udi.service.core.pc.R.id.titleDividerNoCustom);
            if (viewFindViewById9 != null) {
                viewFindViewById9.setVisibility(0);
            }
        } else {
            View viewFindViewById10 = viewGroupD2.findViewById(com.ifpdos.udi.service.core.pc.R.id.textSpacerNoTitle);
            if (viewFindViewById10 != null) {
                viewFindViewById10.setVisibility(0);
            }
        }
        ListView listView = alertController.f400g;
        if (listView instanceof AlertController.RecycleListView) {
            AlertController.RecycleListView recycleListView = (AlertController.RecycleListView) listView;
            Objects.requireNonNull(recycleListView);
            if (!z4 || i8 == 0) {
                recycleListView.setPadding(recycleListView.getPaddingLeft(), i8 != 0 ? recycleListView.getPaddingTop() : recycleListView.f420f, recycleListView.getPaddingRight(), z4 ? recycleListView.getPaddingBottom() : recycleListView.f421m);
            }
        }
        if (!z3) {
            View view2 = alertController.f400g;
            if (view2 == null) {
                view2 = alertController.A;
            }
            if (view2 != null) {
                int i9 = z4 ? 2 : 0;
                View viewFindViewById11 = alertController.f396c.findViewById(com.ifpdos.udi.service.core.pc.R.id.scrollIndicatorUp);
                View viewFindViewById12 = alertController.f396c.findViewById(com.ifpdos.udi.service.core.pc.R.id.scrollIndicatorDown);
                AtomicInteger atomicInteger = y.a;
                y.i.d(view2, i8 | i9, 3);
                if (viewFindViewById11 != null) {
                    viewGroupD2.removeView(viewFindViewById11);
                }
                if (viewFindViewById12 != null) {
                    viewGroupD2.removeView(viewFindViewById12);
                }
            }
        }
        ListView listView2 = alertController.f400g;
        if (listView2 == null || (listAdapter = alertController.H) == null) {
            return;
        }
        listView2.setAdapter(listAdapter);
        int i10 = alertController.I;
        if (i10 > -1) {
            listView2.setItemChecked(i10, true);
            listView2.setSelection(i10);
        }
    }

    @Override // android.app.Dialog, android.view.KeyEvent.Callback
    public boolean onKeyDown(int i2, KeyEvent keyEvent) {
        NestedScrollView nestedScrollView = this.f1557n.A;
        if (nestedScrollView != null && nestedScrollView.h(keyEvent)) {
            return true;
        }
        return super.onKeyDown(i2, keyEvent);
    }

    @Override // android.app.Dialog, android.view.KeyEvent.Callback
    public boolean onKeyUp(int i2, KeyEvent keyEvent) {
        NestedScrollView nestedScrollView = this.f1557n.A;
        if (nestedScrollView != null && nestedScrollView.h(keyEvent)) {
            return true;
        }
        return super.onKeyUp(i2, keyEvent);
    }

    @Override // d.b.c.n, android.app.Dialog
    public void setTitle(CharSequence charSequence) {
        super.setTitle(charSequence);
        AlertController alertController = this.f1557n;
        alertController.f398e = charSequence;
        TextView textView = alertController.E;
        if (textView != null) {
            textView.setText(charSequence);
        }
    }
}
