package androidx.fragment.app; import android.R; 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.LifecycleOwner; import androidx.lifecycle.Observer; /* loaded from: classes.dex */ public class d extends Fragment 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 boolean mCreatingDialog; private Dialog mDialog; private boolean mDismissed; private Handler mHandler; private boolean mShownByMe; private boolean mViewDestroyed; private Runnable mDismissRunnable = new a(); private DialogInterface.OnCancelListener mOnCancelListener = new b(); private DialogInterface.OnDismissListener mOnDismissListener = new c(); private int mStyle = 0; private int mTheme = 0; private boolean mCancelable = true; private boolean mShowsDialog = true; private int mBackStackId = -1; private Observer mObserver = new C0024d(); private boolean mDialogCreated = false; class a implements Runnable { a() { } @Override // java.lang.Runnable public void run() { d.this.mOnDismissListener.onDismiss(d.this.mDialog); } } class b implements DialogInterface.OnCancelListener { b() { } @Override // android.content.DialogInterface.OnCancelListener public void onCancel(DialogInterface dialogInterface) { if (d.this.mDialog != null) { d dVar = d.this; dVar.onCancel(dVar.mDialog); } } } class c implements DialogInterface.OnDismissListener { c() { } @Override // android.content.DialogInterface.OnDismissListener public void onDismiss(DialogInterface dialogInterface) { if (d.this.mDialog != null) { d dVar = d.this; dVar.onDismiss(dVar.mDialog); } } } /* renamed from: androidx.fragment.app.d$d, reason: collision with other inner class name */ class C0024d implements Observer { C0024d() { } @Override // androidx.lifecycle.Observer /* renamed from: a, reason: merged with bridge method [inline-methods] */ public void onChanged(LifecycleOwner lifecycleOwner) { if (lifecycleOwner == null || !d.this.mShowsDialog) { return; } View requireView = d.this.requireView(); if (requireView.getParent() != null) { throw new IllegalStateException("DialogFragment can not be attached to a container view"); } if (d.this.mDialog != null) { if (n.E0(3)) { Log.d("FragmentManager", "DialogFragment " + this + " setting the content view on " + d.this.mDialog); } d.this.mDialog.setContentView(requireView); } } } class e extends g { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ g f1804a; e(g gVar) { this.f1804a = gVar; } @Override // androidx.fragment.app.g public View c(int i10) { return this.f1804a.d() ? this.f1804a.c(i10) : d.this.onFindViewById(i10); } @Override // androidx.fragment.app.g public boolean d() { return this.f1804a.d() || d.this.onHasView(); } } private void g(boolean z10, boolean z11) { if (this.mDismissed) { return; } this.mDismissed = true; this.mShownByMe = false; Dialog dialog = this.mDialog; if (dialog != null) { dialog.setOnDismissListener(null); this.mDialog.dismiss(); if (!z11) { if (Looper.myLooper() == this.mHandler.getLooper()) { onDismiss(this.mDialog); } else { this.mHandler.post(this.mDismissRunnable); } } } this.mViewDestroyed = true; if (this.mBackStackId >= 0) { getParentFragmentManager().V0(this.mBackStackId, 1); this.mBackStackId = -1; return; } v m10 = getParentFragmentManager().m(); m10.l(this); if (z10) { m10.g(); } else { m10.f(); } } private void h(Bundle bundle) { if (this.mShowsDialog && !this.mDialogCreated) { try { this.mCreatingDialog = true; Dialog onCreateDialog = onCreateDialog(bundle); this.mDialog = onCreateDialog; if (this.mShowsDialog) { setupDialog(onCreateDialog, 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; } } finally { this.mCreatingDialog = false; } } } @Override // androidx.fragment.app.Fragment g createFragmentContainer() { return new e(super.createFragmentContainer()); } public void dismiss() { g(false, false); } public void dismissAllowingStateLoss() { g(true, false); } public Dialog getDialog() { return this.mDialog; } public boolean getShowsDialog() { return this.mShowsDialog; } public int getTheme() { return this.mTheme; } public boolean isCancelable() { return this.mCancelable; } @Override // androidx.fragment.app.Fragment public void onAttach(Context context) { super.onAttach(context); getViewLifecycleOwnerLiveData().i(this.mObserver); if (this.mShownByMe) { return; } this.mDismissed = false; } @Override // android.content.DialogInterface.OnCancelListener public void onCancel(DialogInterface dialogInterface) { } @Override // androidx.fragment.app.Fragment public void onCreate(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 (n.E0(3)) { Log.d("FragmentManager", "onCreateDialog called for DialogFragment " + this); } return new Dialog(requireContext(), getTheme()); } @Override // androidx.fragment.app.Fragment 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.Fragment public void onDetach() { super.onDetach(); if (!this.mShownByMe && !this.mDismissed) { this.mDismissed = true; } getViewLifecycleOwnerLiveData().m(this.mObserver); } @Override // android.content.DialogInterface.OnDismissListener public void onDismiss(DialogInterface dialogInterface) { if (this.mViewDestroyed) { return; } if (n.E0(3)) { Log.d("FragmentManager", "onDismiss called for DialogFragment " + this); } g(true, true); } View onFindViewById(int i10) { Dialog dialog = this.mDialog; if (dialog != null) { return dialog.findViewById(i10); } return null; } @Override // androidx.fragment.app.Fragment public LayoutInflater onGetLayoutInflater(Bundle bundle) { LayoutInflater onGetLayoutInflater = super.onGetLayoutInflater(bundle); if (this.mShowsDialog && !this.mCreatingDialog) { h(bundle); if (n.E0(2)) { Log.d("FragmentManager", "get layout inflater for DialogFragment " + this + " from dialog context"); } Dialog dialog = this.mDialog; return dialog != null ? onGetLayoutInflater.cloneInContext(dialog.getContext()) : onGetLayoutInflater; } if (n.E0(2)) { String str = "getting layout inflater for DialogFragment " + this; if (this.mShowsDialog) { Log.d("FragmentManager", "mCreatingDialog = true: " + str); } else { Log.d("FragmentManager", "mShowsDialog = false: " + str); } } return onGetLayoutInflater; } boolean onHasView() { return this.mDialogCreated; } @Override // androidx.fragment.app.Fragment public void onSaveInstanceState(Bundle bundle) { super.onSaveInstanceState(bundle); Dialog dialog = this.mDialog; if (dialog != null) { Bundle onSaveInstanceState = dialog.onSaveInstanceState(); onSaveInstanceState.putBoolean(SAVED_INTERNAL_DIALOG_SHOWING, false); bundle.putBundle(SAVED_DIALOG_STATE_TAG, onSaveInstanceState); } int i10 = this.mStyle; if (i10 != 0) { bundle.putInt(SAVED_STYLE, i10); } int i11 = this.mTheme; if (i11 != 0) { bundle.putInt(SAVED_THEME, i11); } boolean z10 = this.mCancelable; if (!z10) { bundle.putBoolean(SAVED_CANCELABLE, z10); } boolean z11 = this.mShowsDialog; if (!z11) { bundle.putBoolean(SAVED_SHOWS_DIALOG, z11); } int i12 = this.mBackStackId; if (i12 != -1) { bundle.putInt(SAVED_BACK_STACK_ID, i12); } } @Override // androidx.fragment.app.Fragment public void onStart() { super.onStart(); Dialog dialog = this.mDialog; if (dialog != null) { this.mViewDestroyed = false; dialog.show(); View decorView = this.mDialog.getWindow().getDecorView(); androidx.lifecycle.y.a(decorView, this); androidx.lifecycle.z.a(decorView, this); androidx.savedstate.d.a(decorView, this); } } @Override // androidx.fragment.app.Fragment public void onStop() { super.onStop(); Dialog dialog = this.mDialog; if (dialog != null) { dialog.hide(); } } @Override // androidx.fragment.app.Fragment public void onViewStateRestored(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.Fragment void performCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, 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); } 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 z10) { this.mCancelable = z10; Dialog dialog = this.mDialog; if (dialog != null) { dialog.setCancelable(z10); } } public void setShowsDialog(boolean z10) { this.mShowsDialog = z10; } public void setStyle(int i10, int i11) { if (n.E0(2)) { Log.d("FragmentManager", "Setting style and theme for DialogFragment " + this + " to " + i10 + ", " + i11); } this.mStyle = i10; if (i10 == 2 || i10 == 3) { this.mTheme = R.style.Theme.Panel; } if (i11 != 0) { this.mTheme = i11; } } public void setupDialog(Dialog dialog, int i10) { if (i10 != 1 && i10 != 2) { if (i10 != 3) { return; } Window window = dialog.getWindow(); if (window != null) { window.addFlags(24); } } dialog.requestWindowFeature(1); } public void show(n nVar, String str) { this.mDismissed = false; this.mShownByMe = true; v m10 = nVar.m(); m10.d(this, str); m10.f(); } public void showNow(n nVar, String str) { this.mDismissed = false; this.mShownByMe = true; v m10 = nVar.m(); m10.d(this, str); m10.h(); } public int show(v vVar, String str) { this.mDismissed = false; this.mShownByMe = true; vVar.d(this, str); this.mViewDestroyed = false; int f10 = vVar.f(); this.mBackStackId = f10; return f10; } }