package androidx.fragment.app;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.lifecycle.e0;
import androidx.lifecycle.f0;

/* JADX INFO: compiled from: DialogFragment.java */
/* JADX INFO: loaded from: classes.dex */
public class d extends Fragment implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    private Handler f2270c0;

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    private boolean f2279l0;

    /* JADX INFO: renamed from: n0, reason: collision with root package name */
    private Dialog f2281n0;

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    private boolean f2282o0;

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    private boolean f2283p0;

    /* JADX INFO: renamed from: q0, reason: collision with root package name */
    private boolean f2284q0;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    private Runnable f2271d0 = new a();

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    private DialogInterface.OnCancelListener f2272e0 = new b();

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    private DialogInterface.OnDismissListener f2273f0 = new c();

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    private int f2274g0 = 0;

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    private int f2275h0 = 0;

    /* JADX INFO: renamed from: i0, reason: collision with root package name */
    private boolean f2276i0 = true;

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    private boolean f2277j0 = true;

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    private int f2278k0 = -1;

    /* JADX INFO: renamed from: m0, reason: collision with root package name */
    private androidx.lifecycle.q<androidx.lifecycle.k> f2280m0 = new C0031d();

    /* JADX INFO: renamed from: r0, reason: collision with root package name */
    private boolean f2285r0 = false;

    /* JADX INFO: compiled from: DialogFragment.java */
    class a implements Runnable {
        a() {
        }

        @Override // java.lang.Runnable
        @SuppressLint({"SyntheticAccessor"})
        public void run() {
            d.this.f2273f0.onDismiss(d.this.f2281n0);
        }
    }

    /* JADX INFO: compiled from: DialogFragment.java */
    class b implements DialogInterface.OnCancelListener {
        b() {
        }

        @Override // android.content.DialogInterface.OnCancelListener
        @SuppressLint({"SyntheticAccessor"})
        public void onCancel(DialogInterface dialogInterface) {
            if (d.this.f2281n0 != null) {
                d dVar = d.this;
                dVar.onCancel(dVar.f2281n0);
            }
        }
    }

    /* JADX INFO: compiled from: DialogFragment.java */
    class c implements DialogInterface.OnDismissListener {
        c() {
        }

        @Override // android.content.DialogInterface.OnDismissListener
        @SuppressLint({"SyntheticAccessor"})
        public void onDismiss(DialogInterface dialogInterface) {
            if (d.this.f2281n0 != null) {
                d dVar = d.this;
                dVar.onDismiss(dVar.f2281n0);
            }
        }
    }

    /* JADX INFO: renamed from: androidx.fragment.app.d$d, reason: collision with other inner class name */
    /* JADX INFO: compiled from: DialogFragment.java */
    class C0031d implements androidx.lifecycle.q<androidx.lifecycle.k> {
        C0031d() {
        }

        @Override // androidx.lifecycle.q
        @SuppressLint({"SyntheticAccessor"})
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public void a(androidx.lifecycle.k kVar) {
            if (kVar == null || !d.this.f2277j0) {
                return;
            }
            View viewM1 = d.this.m1();
            if (viewM1.getParent() != null) {
                throw new IllegalStateException("DialogFragment can not be attached to a container view");
            }
            if (d.this.f2281n0 != null) {
                if (m.E0(3)) {
                    Log.d("FragmentManager", "DialogFragment " + this + " setting the content view on " + d.this.f2281n0);
                }
                d.this.f2281n0.setContentView(viewM1);
            }
        }
    }

    /* JADX INFO: compiled from: DialogFragment.java */
    class e extends g {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ g f2290a;

        e(g gVar) {
            this.f2290a = gVar;
        }

        @Override // androidx.fragment.app.g
        public View g(int i3) {
            return this.f2290a.h() ? this.f2290a.g(i3) : d.this.K1(i3);
        }

        @Override // androidx.fragment.app.g
        public boolean h() {
            return this.f2290a.h() || d.this.L1();
        }
    }

    private void G1(boolean z2, boolean z3) {
        if (this.f2283p0) {
            return;
        }
        this.f2283p0 = true;
        this.f2284q0 = false;
        Dialog dialog = this.f2281n0;
        if (dialog != null) {
            dialog.setOnDismissListener(null);
            this.f2281n0.dismiss();
            if (!z3) {
                if (Looper.myLooper() == this.f2270c0.getLooper()) {
                    onDismiss(this.f2281n0);
                } else {
                    this.f2270c0.post(this.f2271d0);
                }
            }
        }
        this.f2282o0 = true;
        if (this.f2278k0 >= 0) {
            E().S0(this.f2278k0, 1);
            this.f2278k0 = -1;
            return;
        }
        v vVarL = E().l();
        vVarL.k(this);
        if (z2) {
            vVarL.f();
        } else {
            vVarL.e();
        }
    }

    private void M1(Bundle bundle) {
        if (this.f2277j0 && !this.f2285r0) {
            try {
                this.f2279l0 = true;
                Dialog dialogJ1 = J1(bundle);
                this.f2281n0 = dialogJ1;
                if (this.f2277j0) {
                    O1(dialogJ1, this.f2274g0);
                    Context contextR = r();
                    if (contextR instanceof Activity) {
                        this.f2281n0.setOwnerActivity((Activity) contextR);
                    }
                    this.f2281n0.setCancelable(this.f2276i0);
                    this.f2281n0.setOnCancelListener(this.f2272e0);
                    this.f2281n0.setOnDismissListener(this.f2273f0);
                    this.f2285r0 = true;
                } else {
                    this.f2281n0 = null;
                }
            } finally {
                this.f2279l0 = false;
            }
        }
    }

    public void F1() {
        G1(false, false);
    }

    @Override // androidx.fragment.app.Fragment
    public void H0(Bundle bundle) {
        super.H0(bundle);
        Dialog dialog = this.f2281n0;
        if (dialog != null) {
            Bundle bundleOnSaveInstanceState = dialog.onSaveInstanceState();
            bundleOnSaveInstanceState.putBoolean("android:dialogShowing", false);
            bundle.putBundle("android:savedDialogState", bundleOnSaveInstanceState);
        }
        int i3 = this.f2274g0;
        if (i3 != 0) {
            bundle.putInt("android:style", i3);
        }
        int i4 = this.f2275h0;
        if (i4 != 0) {
            bundle.putInt("android:theme", i4);
        }
        boolean z2 = this.f2276i0;
        if (!z2) {
            bundle.putBoolean("android:cancelable", z2);
        }
        boolean z3 = this.f2277j0;
        if (!z3) {
            bundle.putBoolean("android:showsDialog", z3);
        }
        int i5 = this.f2278k0;
        if (i5 != -1) {
            bundle.putInt("android:backStackId", i5);
        }
    }

    public Dialog H1() {
        return this.f2281n0;
    }

    @Override // androidx.fragment.app.Fragment
    public void I0() {
        super.I0();
        Dialog dialog = this.f2281n0;
        if (dialog != null) {
            this.f2282o0 = false;
            dialog.show();
            View decorView = this.f2281n0.getWindow().getDecorView();
            e0.a(decorView, this);
            f0.a(decorView, this);
            g0.f.a(decorView, this);
        }
    }

    public int I1() {
        return this.f2275h0;
    }

    @Override // androidx.fragment.app.Fragment
    public void J0() {
        super.J0();
        Dialog dialog = this.f2281n0;
        if (dialog != null) {
            dialog.hide();
        }
    }

    public Dialog J1(Bundle bundle) {
        if (m.E0(3)) {
            Log.d("FragmentManager", "onCreateDialog called for DialogFragment " + this);
        }
        return new Dialog(l1(), I1());
    }

    View K1(int i3) {
        Dialog dialog = this.f2281n0;
        if (dialog != null) {
            return dialog.findViewById(i3);
        }
        return null;
    }

    @Override // androidx.fragment.app.Fragment
    public void L0(Bundle bundle) {
        Bundle bundle2;
        super.L0(bundle);
        if (this.f2281n0 == null || bundle == null || (bundle2 = bundle.getBundle("android:savedDialogState")) == null) {
            return;
        }
        this.f2281n0.onRestoreInstanceState(bundle2);
    }

    boolean L1() {
        return this.f2285r0;
    }

    public final Dialog N1() {
        Dialog dialogH1 = H1();
        if (dialogH1 != null) {
            return dialogH1;
        }
        throw new IllegalStateException("DialogFragment " + this + " does not have a Dialog.");
    }

    public void O1(Dialog dialog, int i3) {
        if (i3 != 1 && i3 != 2) {
            if (i3 != 3) {
                return;
            }
            Window window = dialog.getWindow();
            if (window != null) {
                window.addFlags(24);
            }
        }
        dialog.requestWindowFeature(1);
    }

    @Override // androidx.fragment.app.Fragment
    void S0(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        Bundle bundle2;
        super.S0(layoutInflater, viewGroup, bundle);
        if (this.L != null || this.f2281n0 == null || bundle == null || (bundle2 = bundle.getBundle("android:savedDialogState")) == null) {
            return;
        }
        this.f2281n0.onRestoreInstanceState(bundle2);
    }

    @Override // androidx.fragment.app.Fragment
    g f() {
        return new e(super.f());
    }

    @Override // androidx.fragment.app.Fragment
    public void i0(Context context) {
        super.i0(context);
        T().e(this.f2280m0);
        if (this.f2284q0) {
            return;
        }
        this.f2283p0 = false;
    }

    @Override // androidx.fragment.app.Fragment
    public void l0(Bundle bundle) {
        super.l0(bundle);
        this.f2270c0 = new Handler();
        this.f2277j0 = this.B == 0;
        if (bundle != null) {
            this.f2274g0 = bundle.getInt("android:style", 0);
            this.f2275h0 = bundle.getInt("android:theme", 0);
            this.f2276i0 = bundle.getBoolean("android:cancelable", true);
            this.f2277j0 = bundle.getBoolean("android:showsDialog", this.f2277j0);
            this.f2278k0 = bundle.getInt("android:backStackId", -1);
        }
    }

    @Override // android.content.DialogInterface.OnCancelListener
    public void onCancel(DialogInterface dialogInterface) {
    }

    @Override // android.content.DialogInterface.OnDismissListener
    public void onDismiss(DialogInterface dialogInterface) {
        if (this.f2282o0) {
            return;
        }
        if (m.E0(3)) {
            Log.d("FragmentManager", "onDismiss called for DialogFragment " + this);
        }
        G1(true, true);
    }

    @Override // androidx.fragment.app.Fragment
    public void s0() {
        super.s0();
        Dialog dialog = this.f2281n0;
        if (dialog != null) {
            this.f2282o0 = true;
            dialog.setOnDismissListener(null);
            this.f2281n0.dismiss();
            if (!this.f2283p0) {
                onDismiss(this.f2281n0);
            }
            this.f2281n0 = null;
            this.f2285r0 = false;
        }
    }

    @Override // androidx.fragment.app.Fragment
    public void t0() {
        super.t0();
        if (!this.f2284q0 && !this.f2283p0) {
            this.f2283p0 = true;
        }
        T().h(this.f2280m0);
    }

    @Override // androidx.fragment.app.Fragment
    public LayoutInflater u0(Bundle bundle) {
        LayoutInflater layoutInflaterU0 = super.u0(bundle);
        if (this.f2277j0 && !this.f2279l0) {
            M1(bundle);
            if (m.E0(2)) {
                Log.d("FragmentManager", "get layout inflater for DialogFragment " + this + " from dialog context");
            }
            Dialog dialog = this.f2281n0;
            return dialog != null ? layoutInflaterU0.cloneInContext(dialog.getContext()) : layoutInflaterU0;
        }
        if (m.E0(2)) {
            String str = "getting layout inflater for DialogFragment " + this;
            if (this.f2277j0) {
                Log.d("FragmentManager", "mCreatingDialog = true: " + str);
            } else {
                Log.d("FragmentManager", "mShowsDialog = false: " + str);
            }
        }
        return layoutInflaterU0;
    }
}
