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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.fragment.app.ab.n;
import com.strmr.ps.R;
import defpackage.hl3;
import defpackage.i85;
import defpackage.m38;
import defpackage.n41;
import defpackage.or0;
import defpackage.p91;
import defpackage.rq6;
import defpackage.savedstate_release;
import defpackage.sla;
import defpackage.vm5;
import defpackage.vo6;
import defpackage.y99;
import defpackage.zs6;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class l extends o implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
    private static final String SAVED_BACK_STACK_ID = "android:backStackId";
    private static final String SAVED_CANCELABLE = "android:cancelable";
    private static final String SAVED_DIALOG_STATE_TAG = "android:savedDialogState";
    private static final String SAVED_INTERNAL_DIALOG_SHOWING = "android:dialogShowing";
    private static final String SAVED_SHOWS_DIALOG = "android:showsDialog";
    private static final String SAVED_STYLE = "android:style";
    private static final String SAVED_THEME = "android:theme";
    public static final int STYLE_NORMAL = 0;
    public static final int STYLE_NO_FRAME = 2;
    public static final int STYLE_NO_INPUT = 3;
    public static final int STYLE_NO_TITLE = 1;
    private int mBackStackId;
    private boolean mCancelable;
    private boolean mCreatingDialog;

    @rq6
    private Dialog mDialog;
    private boolean mDialogCreated;
    private Runnable mDismissRunnable;
    private boolean mDismissed;
    private Handler mHandler;
    private zs6<i85> mObserver;
    private DialogInterface.OnCancelListener mOnCancelListener;
    private DialogInterface.OnDismissListener mOnDismissListener;
    private boolean mShownByMe;
    private boolean mShowsDialog;
    private int mStyle;
    private int mTheme;
    private boolean mViewDestroyed;

    public class a implements Runnable {
        public a() {
        }

        @Override // java.lang.Runnable
        public final void run() {
            l lVar = l.this;
            lVar.mOnDismissListener.onDismiss(lVar.mDialog);
        }
    }

    public class b implements DialogInterface.OnCancelListener {
        public b() {
        }

        @Override // android.content.DialogInterface.OnCancelListener
        public final void onCancel(DialogInterface dialogInterface) {
            l lVar = l.this;
            if (lVar.mDialog != null) {
                lVar.onCancel(lVar.mDialog);
            }
        }
    }

    public class c implements DialogInterface.OnDismissListener {
        public c() {
        }

        @Override // android.content.DialogInterface.OnDismissListener
        public final void onDismiss(DialogInterface dialogInterface) {
            l lVar = l.this;
            if (lVar.mDialog != null) {
                lVar.onDismiss(lVar.mDialog);
            }
        }
    }

    public class d implements zs6<i85> {
        public d() {
        }

        @Override // defpackage.zs6
        public final void a(Object obj) {
            if (((i85) obj) != null) {
                l lVar = l.this;
                if (lVar.mShowsDialog) {
                    View viewRequireView = lVar.requireView();
                    if (viewRequireView.getParent() != null) {
                        throw new IllegalStateException("DialogFragment can not be attached to a container view");
                    }
                    if (lVar.mDialog != null) {
                        if (ab.am(3)) {
                            toString();
                            Objects.toString(lVar.mDialog);
                        }
                        lVar.mDialog.setContentView(viewRequireView);
                    }
                }
            }
        }
    }

    public class e extends hl3 {
        public final /* synthetic */ hl3 a;

        public e(hl3 hl3Var) {
            this.a = hl3Var;
        }

        @Override // defpackage.hl3
        public final View b(int i) {
            hl3 hl3Var = this.a;
            return hl3Var.c() ? hl3Var.b(i) : l.this.onFindViewById(i);
        }

        @Override // defpackage.hl3
        public final boolean c() {
            return this.a.c() || l.this.onHasView();
        }
    }

    public l() {
        this.mDismissRunnable = new a();
        this.mOnCancelListener = new b();
        this.mOnDismissListener = new c();
        this.mStyle = 0;
        this.mTheme = 0;
        this.mCancelable = true;
        this.mShowsDialog = true;
        this.mBackStackId = -1;
        this.mObserver = new d();
        this.mDialogCreated = false;
    }

    @Override // androidx.fragment.app.o
    @vo6
    public hl3 createFragmentContainer() {
        return new e(super.createFragmentContainer());
    }

    public void dismiss() {
        j(false, false, false);
    }

    public void dismissAllowingStateLoss() {
        j(true, false, false);
    }

    @vm5
    public void dismissNow() {
        j(false, false, true);
    }

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

    public boolean getShowsDialog() {
        return this.mShowsDialog;
    }

    @y99
    public int getTheme() {
        return this.mTheme;
    }

    public boolean isCancelable() {
        return this.mCancelable;
    }

    public final void j(boolean z, boolean z2, boolean z3) {
        if (this.mDismissed) {
            return;
        }
        this.mDismissed = true;
        this.mShownByMe = false;
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            dialog.setOnDismissListener(null);
            this.mDialog.dismiss();
            if (!z2) {
                if (Looper.myLooper() == this.mHandler.getLooper()) {
                    onDismiss(this.mDialog);
                } else {
                    this.mHandler.post(this.mDismissRunnable);
                }
            }
        }
        this.mViewDestroyed = true;
        if (this.mBackStackId < 0) {
            ab parentFragmentManager = getParentFragmentManager();
            parentFragmentManager.getClass();
            androidx.fragment.app.a aVar = new androidx.fragment.app.a(parentFragmentManager);
            aVar.p = true;
            aVar.h(this);
            if (z3) {
                aVar.f();
                return;
            } else if (z) {
                aVar.m(true, true);
                return;
            } else {
                aVar.d();
                return;
            }
        }
        if (z3) {
            ab parentFragmentManager2 = getParentFragmentManager();
            int i = this.mBackStackId;
            if (i < 0) {
                parentFragmentManager2.getClass();
                throw new IllegalArgumentException(n41.k("Bad id: ", i));
            }
            parentFragmentManager2.av(i, 1);
        } else {
            ab parentFragmentManager3 = getParentFragmentManager();
            int i2 = this.mBackStackId;
            parentFragmentManager3.getClass();
            if (i2 < 0) {
                throw new IllegalArgumentException(n41.k("Bad id: ", i2));
            }
            parentFragmentManager3.y(parentFragmentManager3.new n(null, i2), z);
        }
        this.mBackStackId = -1;
    }

    @Override // androidx.fragment.app.o
    @Deprecated
    @vm5
    public void onActivityCreated(@rq6 Bundle bundle) {
        super.onActivityCreated(bundle);
    }

    @Override // androidx.fragment.app.o
    @vm5
    public void onAttach(@vo6 Context context) {
        super.onAttach(context);
        getViewLifecycleOwnerLiveData().g(this.mObserver);
        if (this.mShownByMe) {
            return;
        }
        this.mDismissed = false;
    }

    public void onCancel(@vo6 DialogInterface dialogInterface) {
    }

    @Override // androidx.fragment.app.o
    @vm5
    public void onCreate(@rq6 Bundle bundle) {
        super.onCreate(bundle);
        this.mHandler = new Handler();
        this.mShowsDialog = this.mContainerId == 0;
        if (bundle != null) {
            this.mStyle = bundle.getInt(SAVED_STYLE, 0);
            this.mTheme = bundle.getInt(SAVED_THEME, 0);
            this.mCancelable = bundle.getBoolean(SAVED_CANCELABLE, true);
            this.mShowsDialog = bundle.getBoolean(SAVED_SHOWS_DIALOG, this.mShowsDialog);
            this.mBackStackId = bundle.getInt(SAVED_BACK_STACK_ID, -1);
        }
    }

    public Dialog onCreateDialog(Bundle bundle) {
        if (ab.am(3)) {
            toString();
        }
        return new p91(requireContext(), getTheme());
    }

    @Override // androidx.fragment.app.o
    @vm5
    public void onDestroyView() {
        super.onDestroyView();
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            this.mViewDestroyed = true;
            dialog.setOnDismissListener(null);
            this.mDialog.dismiss();
            if (!this.mDismissed) {
                onDismiss(this.mDialog);
            }
            this.mDialog = null;
            this.mDialogCreated = false;
        }
    }

    @Override // androidx.fragment.app.o
    @vm5
    public void onDetach() {
        super.onDetach();
        if (!this.mShownByMe && !this.mDismissed) {
            this.mDismissed = true;
        }
        getViewLifecycleOwnerLiveData().k(this.mObserver);
    }

    @Override // android.content.DialogInterface.OnDismissListener
    @or0
    public void onDismiss(@vo6 DialogInterface dialogInterface) {
        if (this.mViewDestroyed) {
            return;
        }
        if (ab.am(3)) {
            toString();
        }
        j(true, true, false);
    }

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

    @Override // androidx.fragment.app.o
    @vo6
    public LayoutInflater onGetLayoutInflater(@rq6 Bundle bundle) {
        LayoutInflater layoutInflaterOnGetLayoutInflater = super.onGetLayoutInflater(bundle);
        boolean z = this.mShowsDialog;
        if (z && !this.mCreatingDialog) {
            if (z && !this.mDialogCreated) {
                try {
                    this.mCreatingDialog = true;
                    Dialog dialogOnCreateDialog = onCreateDialog(bundle);
                    this.mDialog = dialogOnCreateDialog;
                    if (this.mShowsDialog) {
                        setupDialog(dialogOnCreateDialog, this.mStyle);
                        Context context = getContext();
                        if (context instanceof Activity) {
                            this.mDialog.setOwnerActivity((Activity) context);
                        }
                        this.mDialog.setCancelable(this.mCancelable);
                        this.mDialog.setOnCancelListener(this.mOnCancelListener);
                        this.mDialog.setOnDismissListener(this.mOnDismissListener);
                        this.mDialogCreated = true;
                    } else {
                        this.mDialog = null;
                    }
                    this.mCreatingDialog = false;
                } catch (Throwable th) {
                    this.mCreatingDialog = false;
                    throw th;
                }
            }
            if (ab.am(2)) {
                toString();
            }
            Dialog dialog = this.mDialog;
            if (dialog != null) {
                return layoutInflaterOnGetLayoutInflater.cloneInContext(dialog.getContext());
            }
        } else if (ab.am(2)) {
            toString();
        }
        return layoutInflaterOnGetLayoutInflater;
    }

    public boolean onHasView() {
        return this.mDialogCreated;
    }

    @Override // androidx.fragment.app.o
    @vm5
    public void onSaveInstanceState(@vo6 Bundle bundle) {
        super.onSaveInstanceState(bundle);
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            Bundle bundleOnSaveInstanceState = dialog.onSaveInstanceState();
            bundleOnSaveInstanceState.putBoolean(SAVED_INTERNAL_DIALOG_SHOWING, false);
            bundle.putBundle(SAVED_DIALOG_STATE_TAG, bundleOnSaveInstanceState);
        }
        int i = this.mStyle;
        if (i != 0) {
            bundle.putInt(SAVED_STYLE, i);
        }
        int i2 = this.mTheme;
        if (i2 != 0) {
            bundle.putInt(SAVED_THEME, i2);
        }
        boolean z = this.mCancelable;
        if (!z) {
            bundle.putBoolean(SAVED_CANCELABLE, z);
        }
        boolean z2 = this.mShowsDialog;
        if (!z2) {
            bundle.putBoolean(SAVED_SHOWS_DIALOG, z2);
        }
        int i3 = this.mBackStackId;
        if (i3 != -1) {
            bundle.putInt(SAVED_BACK_STACK_ID, i3);
        }
    }

    @Override // androidx.fragment.app.o
    @vm5
    public void onStart() {
        super.onStart();
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            this.mViewDestroyed = false;
            dialog.show();
            View decorView = this.mDialog.getWindow().getDecorView();
            sla.a(decorView, this);
            decorView.setTag(R.id.view_tree_view_model_store_owner, this);
            savedstate_release.a(decorView, this);
        }
    }

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

    @Override // androidx.fragment.app.o
    @vm5
    public void onViewStateRestored(@rq6 Bundle bundle) {
        Bundle bundle2;
        super.onViewStateRestored(bundle);
        if (this.mDialog == null || bundle == null || (bundle2 = bundle.getBundle(SAVED_DIALOG_STATE_TAG)) == null) {
            return;
        }
        this.mDialog.onRestoreInstanceState(bundle2);
    }

    @Override // androidx.fragment.app.o
    public void performCreateView(@vo6 LayoutInflater layoutInflater, @rq6 ViewGroup viewGroup, @rq6 Bundle bundle) {
        Bundle bundle2;
        super.performCreateView(layoutInflater, viewGroup, bundle);
        if (this.mView != null || this.mDialog == null || bundle == null || (bundle2 = bundle.getBundle(SAVED_DIALOG_STATE_TAG)) == null) {
            return;
        }
        this.mDialog.onRestoreInstanceState(bundle2);
    }

    @vo6
    public final p91 requireComponentDialog() {
        Dialog dialogRequireDialog = requireDialog();
        if (dialogRequireDialog instanceof p91) {
            return (p91) dialogRequireDialog;
        }
        throw new IllegalStateException("DialogFragment " + this + " did not return a ComponentDialog instance from requireDialog(). The actual Dialog is " + dialogRequireDialog);
    }

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

    public void setCancelable(boolean z) {
        this.mCancelable = z;
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            dialog.setCancelable(z);
        }
    }

    public void setShowsDialog(boolean z) {
        this.mShowsDialog = z;
    }

    public void setStyle(int i, @y99 int i2) {
        if (ab.am(2)) {
            toString();
        }
        this.mStyle = i;
        if (i == 2 || i == 3) {
            this.mTheme = android.R.style.Theme.Panel;
        }
        if (i2 != 0) {
            this.mTheme = i2;
        }
    }

    @m38
    public void setupDialog(@vo6 Dialog dialog, int i) {
        if (i != 1 && i != 2) {
            if (i != 3) {
                return;
            }
            Window window = dialog.getWindow();
            if (window != null) {
                window.addFlags(24);
            }
        }
        dialog.requestWindowFeature(1);
    }

    public void show(@vo6 ab abVar, @rq6 String str) {
        this.mDismissed = false;
        this.mShownByMe = true;
        abVar.getClass();
        androidx.fragment.app.a aVar = new androidx.fragment.app.a(abVar);
        aVar.p = true;
        aVar.g(0, this, str, 1);
        aVar.d();
    }

    public void showNow(@vo6 ab abVar, @rq6 String str) {
        this.mDismissed = false;
        this.mShownByMe = true;
        abVar.getClass();
        androidx.fragment.app.a aVar = new androidx.fragment.app.a(abVar);
        aVar.p = true;
        aVar.g(0, this, str, 1);
        aVar.f();
    }

    public int show(@vo6 am amVar, @rq6 String str) {
        this.mDismissed = false;
        this.mShownByMe = true;
        amVar.g(0, this, str, 1);
        this.mViewDestroyed = false;
        int iD = amVar.d();
        this.mBackStackId = iD;
        return iD;
    }

    public l(int i) {
        super(i);
        this.mDismissRunnable = new a();
        this.mOnCancelListener = new b();
        this.mOnDismissListener = new c();
        this.mStyle = 0;
        this.mTheme = 0;
        this.mCancelable = true;
        this.mShowsDialog = true;
        this.mBackStackId = -1;
        this.mObserver = new d();
        this.mDialogCreated = false;
    }
}
