package androidx.fragment.app;

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.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
public class u extends e0 implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
    public Handler D0;
    public boolean M0;
    public boolean O0;
    public boolean P0;
    public boolean Q0;

    @Nullable
    private Dialog mDialog;
    public final e.s0 E0 = new e.s0(this, 8);
    public final q F0 = new q(this);
    public final r G0 = new r(this);
    public int H0 = 0;
    public int I0 = 0;
    public boolean J0 = true;
    public boolean K0 = true;
    public int L0 = -1;
    public final s N0 = new s(this);
    public boolean R0 = false;

    /* JADX WARN: Removed duplicated region for block: B:23:0x0038 A[Catch: all -> 0x0040, TryCatch #0 {all -> 0x0040, blocks: (B:8:0x000b, B:10:0x0017, B:21:0x0030, B:23:0x0038, B:26:0x0042, B:17:0x0022, B:19:0x0028, B:20:0x002d, B:27:0x005a), top: B:32:0x000b }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void prepareDialog(@Nullable Bundle bundle) {
        Context context;
        if (this.K0 && !this.R0) {
            try {
                this.M0 = true;
                Dialog dialogOnCreateDialog = onCreateDialog(bundle);
                this.mDialog = dialogOnCreateDialog;
                if (this.K0) {
                    int i10 = this.H0;
                    if (i10 == 1 || i10 == 2) {
                        dialogOnCreateDialog.requestWindowFeature(1);
                        context = getContext();
                        if (context instanceof Activity) {
                            this.mDialog.setOwnerActivity((Activity) context);
                        }
                        this.mDialog.setCancelable(this.J0);
                        this.mDialog.setOnCancelListener(this.F0);
                        this.mDialog.setOnDismissListener(this.G0);
                        this.R0 = true;
                    } else if (i10 == 3) {
                        Window window = dialogOnCreateDialog.getWindow();
                        if (window != null) {
                            window.addFlags(24);
                        }
                        dialogOnCreateDialog.requestWindowFeature(1);
                        context = getContext();
                        if (context instanceof Activity) {
                        }
                        this.mDialog.setCancelable(this.J0);
                        this.mDialog.setOnCancelListener(this.F0);
                        this.mDialog.setOnDismissListener(this.G0);
                        this.R0 = true;
                    } else {
                        context = getContext();
                        if (context instanceof Activity) {
                        }
                        this.mDialog.setCancelable(this.J0);
                        this.mDialog.setOnCancelListener(this.F0);
                        this.mDialog.setOnDismissListener(this.G0);
                        this.R0 = true;
                    }
                } else {
                    this.mDialog = null;
                }
                this.M0 = false;
            } catch (Throwable th) {
                this.M0 = false;
                throw th;
            }
        }
    }

    public final void K(boolean z10, boolean z11) {
        if (this.P0) {
            return;
        }
        this.P0 = true;
        this.Q0 = false;
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            dialog.setOnDismissListener(null);
            this.mDialog.dismiss();
            if (!z11) {
                if (Looper.myLooper() == this.D0.getLooper()) {
                    onDismiss(this.mDialog);
                } else {
                    this.D0.post(this.E0);
                }
            }
        }
        this.O0 = true;
        if (this.L0 >= 0) {
            d1 parentFragmentManager = getParentFragmentManager();
            int i10 = this.L0;
            parentFragmentManager.getClass();
            if (i10 < 0) {
                throw new IllegalArgumentException(com.google.android.gms.measurement.internal.u1.g("Bad id: ", i10));
            }
            parentFragmentManager.v(new b1(parentFragmentManager, null, i10, 1), z10);
            this.L0 = -1;
            return;
        }
        d1 parentFragmentManager2 = getParentFragmentManager();
        parentFragmentManager2.getClass();
        a aVar = new a(parentFragmentManager2);
        aVar.f2577q = true;
        aVar.g(this);
        if (z10) {
            aVar.i(true);
        } else {
            aVar.i(false);
        }
    }

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

    @Nullable
    public Dialog getDialog() {
        return this.mDialog;
    }

    @Override // androidx.fragment.app.e0
    @MainThread
    @Deprecated
    public void onActivityCreated(@Nullable Bundle bundle) {
        super.onActivityCreated(bundle);
    }

    @Override // androidx.fragment.app.e0
    public final void onAttach(Context context) {
        super.onAttach(context);
        getViewLifecycleOwnerLiveData().d(this.N0);
        if (this.Q0) {
            return;
        }
        this.P0 = false;
    }

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

    @Override // androidx.fragment.app.e0
    @MainThread
    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        this.D0 = new Handler();
        this.K0 = this.f2399a0 == 0;
        if (bundle != null) {
            this.H0 = bundle.getInt("android:style", 0);
            this.I0 = bundle.getInt("android:theme", 0);
            this.J0 = bundle.getBoolean("android:cancelable", true);
            this.K0 = bundle.getBoolean("android:showsDialog", this.K0);
            this.L0 = bundle.getInt("android:backStackId", -1);
        }
    }

    @NonNull
    @MainThread
    public Dialog onCreateDialog(@Nullable Bundle bundle) {
        if (Log.isLoggable("FragmentManager", 3)) {
            toString();
        }
        return new androidx.activity.r(requireContext(), this.I0);
    }

    @Override // androidx.fragment.app.e0
    public final void onDestroyView() {
        this.f2415i0 = true;
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            this.O0 = true;
            dialog.setOnDismissListener(null);
            this.mDialog.dismiss();
            if (!this.P0) {
                onDismiss(this.mDialog);
            }
            this.mDialog = null;
            this.R0 = false;
        }
    }

    @Override // androidx.fragment.app.e0
    public final void onDetach() {
        super.onDetach();
        if (!this.Q0 && !this.P0) {
            this.P0 = true;
        }
        getViewLifecycleOwnerLiveData().g(this.N0);
    }

    @Override // android.content.DialogInterface.OnDismissListener
    public void onDismiss(DialogInterface dialogInterface) {
        if (this.O0) {
            return;
        }
        if (Log.isLoggable("FragmentManager", 3)) {
            toString();
        }
        K(true, true);
    }

    @Nullable
    public View onFindViewById(int i10) {
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            return dialog.findViewById(i10);
        }
        return null;
    }

    @Override // androidx.fragment.app.e0
    @NonNull
    public LayoutInflater onGetLayoutInflater(@Nullable Bundle bundle) {
        LayoutInflater layoutInflaterOnGetLayoutInflater = super.onGetLayoutInflater(bundle);
        if (!this.K0 || this.M0) {
            if (Log.isLoggable("FragmentManager", 2)) {
                new StringBuilder("getting layout inflater for DialogFragment ").append(this);
            }
            return layoutInflaterOnGetLayoutInflater;
        }
        prepareDialog(bundle);
        if (Log.isLoggable("FragmentManager", 2)) {
            toString();
        }
        Dialog dialog = this.mDialog;
        return dialog != null ? layoutInflaterOnGetLayoutInflater.cloneInContext(dialog.getContext()) : layoutInflaterOnGetLayoutInflater;
    }

    @Override // androidx.fragment.app.e0
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            Bundle bundleOnSaveInstanceState = dialog.onSaveInstanceState();
            bundleOnSaveInstanceState.putBoolean("android:dialogShowing", false);
            bundle.putBundle("android:savedDialogState", bundleOnSaveInstanceState);
        }
        int i10 = this.H0;
        if (i10 != 0) {
            bundle.putInt("android:style", i10);
        }
        int i11 = this.I0;
        if (i11 != 0) {
            bundle.putInt("android:theme", i11);
        }
        boolean z10 = this.J0;
        if (!z10) {
            bundle.putBoolean("android:cancelable", z10);
        }
        boolean z11 = this.K0;
        if (!z11) {
            bundle.putBoolean("android:showsDialog", z11);
        }
        int i12 = this.L0;
        if (i12 != -1) {
            bundle.putInt("android:backStackId", i12);
        }
    }

    @Override // androidx.fragment.app.e0
    public void onStart() {
        super.onStart();
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            this.O0 = false;
            dialog.show();
            View decorView = this.mDialog.getWindow().getDecorView();
            nb.g.i(decorView, "<this>");
            decorView.setTag(m1.a.view_tree_lifecycle_owner, this);
            decorView.setTag(n1.d.view_tree_view_model_store_owner, this);
            decorView.setTag(i3.a.view_tree_saved_state_registry_owner, this);
        }
    }

    @Override // androidx.fragment.app.e0
    public void onStop() {
        super.onStop();
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            dialog.hide();
        }
    }

    @Override // androidx.fragment.app.e0
    @MainThread
    public void onViewStateRestored(@Nullable Bundle bundle) {
        Bundle bundle2;
        super.onViewStateRestored(bundle);
        if (this.mDialog == null || bundle == null || (bundle2 = bundle.getBundle("android:savedDialogState")) == null) {
            return;
        }
        this.mDialog.onRestoreInstanceState(bundle2);
    }

    @Override // androidx.fragment.app.e0
    public void performCreateView(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
        Bundle bundle2;
        super.performCreateView(layoutInflater, viewGroup, bundle);
        if (this.f2419k0 != null || this.mDialog == null || bundle == null || (bundle2 = bundle.getBundle("android:savedDialogState")) == null) {
            return;
        }
        this.mDialog.onRestoreInstanceState(bundle2);
    }

    public void show(@NonNull d1 d1Var, @Nullable String str) {
        this.P0 = false;
        this.Q0 = true;
        d1Var.getClass();
        a aVar = new a(d1Var);
        aVar.f2577q = true;
        aVar.add(this, str);
        aVar.i(false);
    }

    public void showNow(@NonNull d1 d1Var, @Nullable String str) {
        this.P0 = false;
        this.Q0 = true;
        d1Var.getClass();
        a aVar = new a(d1Var);
        aVar.f2577q = true;
        aVar.add(this, str);
        if (aVar.f2569i) {
            throw new IllegalStateException("This transaction is already being added to the back stack");
        }
        aVar.f2570j = false;
        aVar.f2310r.y(aVar, false);
    }

    @Override // androidx.fragment.app.e0
    public final k0 z() {
        return new t(this, new y(this));
    }

    public int show(@NonNull r1 r1Var, @Nullable String str) {
        this.P0 = false;
        this.Q0 = true;
        r1Var.add(this, str);
        this.O0 = false;
        int iC = r1Var.c();
        this.L0 = iC;
        return iC;
    }
}
