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.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import androidx.lifecycle.LiveData; import o.AbstractC13482fbE; import o.C14957gcv; import o.HBt; import o.InterfaceC16541pFg; import o.UBQ; import o.iuP; import o.sxb; import o.wTJ; import o.yRS; import o.zBc; /* loaded from: classes.dex */ public class DialogFragment 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 int mBackStackId; private boolean mCancelable; private boolean mCreatingDialog; private Dialog mDialog; private boolean mDialogCreated; private Runnable mDismissRunnable; private boolean mDismissed; private Handler mHandler; private zBc mObserver; private DialogInterface.OnCancelListener mOnCancelListener; private DialogInterface.OnDismissListener mOnDismissListener; private boolean mShownByMe; private boolean mShowsDialog; private int mStyle; private int mTheme; private boolean mViewDestroyed; @Override // android.content.DialogInterface.OnCancelListener public void onCancel(DialogInterface dialogInterface) { } public DialogFragment() { this.mDismissRunnable = new Runnable(this) { // from class: androidx.fragment.app.DialogFragment.2 final DialogFragment a; { this.a = this; } @Override // java.lang.Runnable public final void run() { this.a.mOnDismissListener.onDismiss(this.a.mDialog); } }; this.mOnCancelListener = new DialogInterface.OnCancelListener(this) { // from class: androidx.fragment.app.DialogFragment.3 final DialogFragment c; { this.c = this; } @Override // android.content.DialogInterface.OnCancelListener public final void onCancel(DialogInterface dialogInterface) { if (this.c.mDialog != null) { DialogFragment dialogFragment = this.c; dialogFragment.onCancel(dialogFragment.mDialog); } } }; this.mOnDismissListener = new DialogInterface.OnDismissListener(this) { // from class: androidx.fragment.app.DialogFragment.4 final DialogFragment d; { this.d = this; } @Override // android.content.DialogInterface.OnDismissListener public final void onDismiss(DialogInterface dialogInterface) { if (this.d.mDialog != null) { DialogFragment dialogFragment = this.d; dialogFragment.onDismiss(dialogFragment.mDialog); } } }; this.mStyle = 0; this.mTheme = 0; this.mCancelable = true; this.mShowsDialog = true; this.mBackStackId = -1; this.mObserver = new zBc(this) { // from class: androidx.fragment.app.DialogFragment.1 final DialogFragment a; { this.a = this; } @Override // o.zBc public final /* synthetic */ void onChanged(InterfaceC16541pFg interfaceC16541pFg) { if (interfaceC16541pFg == null || !this.a.mShowsDialog) { return; } View requireView = this.a.requireView(); if (requireView.getParent() == null) { if (this.a.mDialog != null) { if (yRS.b(3)) { Dialog unused = this.a.mDialog; } this.a.mDialog.setContentView(requireView); return; } return; } throw new IllegalStateException("DialogFragment can not be attached to a container view"); } }; this.mDialogCreated = false; } public DialogFragment(int i) { super(i); this.mDismissRunnable = new Runnable(this) { // from class: androidx.fragment.app.DialogFragment.2 final DialogFragment a; { this.a = this; } @Override // java.lang.Runnable public final void run() { this.a.mOnDismissListener.onDismiss(this.a.mDialog); } }; this.mOnCancelListener = new DialogInterface.OnCancelListener(this) { // from class: androidx.fragment.app.DialogFragment.3 final DialogFragment c; { this.c = this; } @Override // android.content.DialogInterface.OnCancelListener public final void onCancel(DialogInterface dialogInterface) { if (this.c.mDialog != null) { DialogFragment dialogFragment = this.c; dialogFragment.onCancel(dialogFragment.mDialog); } } }; this.mOnDismissListener = new DialogInterface.OnDismissListener(this) { // from class: androidx.fragment.app.DialogFragment.4 final DialogFragment d; { this.d = this; } @Override // android.content.DialogInterface.OnDismissListener public final void onDismiss(DialogInterface dialogInterface) { if (this.d.mDialog != null) { DialogFragment dialogFragment = this.d; dialogFragment.onDismiss(dialogFragment.mDialog); } } }; this.mStyle = 0; this.mTheme = 0; this.mCancelable = true; this.mShowsDialog = true; this.mBackStackId = -1; this.mObserver = new zBc(this) { // from class: androidx.fragment.app.DialogFragment.1 final DialogFragment a; { this.a = this; } @Override // o.zBc public final /* synthetic */ void onChanged(InterfaceC16541pFg interfaceC16541pFg) { if (interfaceC16541pFg == null || !this.a.mShowsDialog) { return; } View requireView = this.a.requireView(); if (requireView.getParent() == null) { if (this.a.mDialog != null) { if (yRS.b(3)) { Dialog unused = this.a.mDialog; } this.a.mDialog.setContentView(requireView); return; } return; } throw new IllegalStateException("DialogFragment can not be attached to a container view"); } }; this.mDialogCreated = false; } public void setStyle(int i, int i2) { yRS.b(2); this.mStyle = i; if (i == 2 || i == 3) { this.mTheme = R.style.Theme.Panel; } if (i2 != 0) { this.mTheme = i2; } } public void show(yRS yrs, String str) { this.mDismissed = false; this.mShownByMe = true; AbstractC13482fbE a = yrs.a(); a.r = true; a.b(0, this, str, 1); a.b(); } public void showNow(yRS yrs, String str) { this.mDismissed = false; this.mShownByMe = true; AbstractC13482fbE a = yrs.a(); a.r = true; a.b(0, this, str, 1); a.d(); } public void dismiss() { dismissInternal(false, false, false); } public void dismissNow() { dismissInternal(false, false, true); } public void dismissAllowingStateLoss() { dismissInternal(true, false, false); } private void dismissInternal(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) { if (z3) { getParentFragmentManager().e(this.mBackStackId); } else { getParentFragmentManager().a(this.mBackStackId, z); } this.mBackStackId = -1; return; } AbstractC13482fbE a = getParentFragmentManager().a(); a.r = true; a.e(this); if (z3) { a.d(); } else if (z) { a.a(); } else { a.b(); } } public final Dialog requireDialog() { Dialog dialog = getDialog(); if (dialog != null) { return dialog; } StringBuilder sb = new StringBuilder("DialogFragment "); sb.append(this); sb.append(" does not have a Dialog."); throw new IllegalStateException(sb.toString()); } public void setCancelable(boolean z) { this.mCancelable = z; Dialog dialog = this.mDialog; if (dialog != null) { dialog.setCancelable(z); } } @Override // androidx.fragment.app.Fragment public void onAttach(Context context) { super.onAttach(context); LiveData viewLifecycleOwnerLiveData = getViewLifecycleOwnerLiveData(); zBc zbc = this.mObserver; LiveData.e("observeForever"); LiveData.HBt hBt = new LiveData.HBt(viewLifecycleOwnerLiveData, zbc); LiveData.Sts a = viewLifecycleOwnerLiveData.b.a(zbc, hBt); if (!(a instanceof LiveData.LifecycleBoundObserver)) { if (a == null) { hBt.b(true); } if (this.mShownByMe) { return; } this.mDismissed = false; return; } throw new IllegalArgumentException("Cannot add the same observer with different lifecycles"); } @Override // androidx.fragment.app.Fragment public void onDetach() { super.onDetach(); if (!this.mShownByMe && !this.mDismissed) { this.mDismissed = true; } getViewLifecycleOwnerLiveData().c(this.mObserver); } @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); } } /* JADX INFO: Access modifiers changed from: package-private */ @Override // androidx.fragment.app.Fragment public 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); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // androidx.fragment.app.Fragment public wTJ createFragmentContainer() { return new wTJ(this, super.createFragmentContainer()) { // from class: androidx.fragment.app.DialogFragment.5 final wTJ a; final DialogFragment c; { this.c = this; this.a = r2; } @Override // o.wTJ public final View b(int i) { if (this.a.c()) { return this.a.b(i); } return this.c.onFindViewById(i); } @Override // o.wTJ public final boolean c() { return this.a.c() || this.c.onHasView(); } }; } View onFindViewById(int i) { Dialog dialog = this.mDialog; if (dialog != null) { return dialog.findViewById(i); } return null; } @Override // androidx.fragment.app.Fragment public LayoutInflater onGetLayoutInflater(Bundle bundle) { LayoutInflater onGetLayoutInflater = super.onGetLayoutInflater(bundle); if (!this.mShowsDialog || this.mCreatingDialog) { yRS.b(2); return onGetLayoutInflater; } prepareDialog(bundle); yRS.b(2); Dialog dialog = this.mDialog; return dialog != null ? onGetLayoutInflater.cloneInContext(dialog.getContext()) : onGetLayoutInflater; } public void setupDialog(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 Dialog onCreateDialog(Bundle bundle) { yRS.b(3); return new HBt(requireContext(), getTheme()); } @Override // android.content.DialogInterface.OnDismissListener public void onDismiss(DialogInterface dialogInterface) { if (this.mViewDestroyed) { return; } yRS.b(3); dismissInternal(true, true, false); } private void prepareDialog(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 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 @Deprecated public void onActivityCreated(Bundle bundle) { super.onActivityCreated(bundle); } @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(); decorView.setTag(UBQ.HBt.view_tree_lifecycle_owner, this); decorView.setTag(sxb.Sts.view_tree_view_model_store_owner, this); C14957gcv.e(decorView, ""); decorView.setTag(iuP.RVV.view_tree_saved_state_registry_owner, this); } } @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 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.Fragment public void onStop() { super.onStop(); Dialog dialog = this.mDialog; if (dialog != null) { dialog.hide(); } } @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; } } public int show(AbstractC13482fbE abstractC13482fbE, String str) { this.mDismissed = false; this.mShownByMe = true; abstractC13482fbE.b(0, this, str, 1); this.mViewDestroyed = false; int b = abstractC13482fbE.b(); this.mBackStackId = b; return b; } public void setShowsDialog(boolean z) { this.mShowsDialog = z; } boolean onHasView() { return this.mDialogCreated; } public boolean isCancelable() { return this.mCancelable; } public int getTheme() { return this.mTheme; } public boolean getShowsDialog() { return this.mShowsDialog; } public Dialog getDialog() { return this.mDialog; } }