package d.k.b;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import androidx.activity.ComponentActivity;
import androidx.activity.OnBackPressedDispatcher;
import d.h.b.b;
import d.h.c.a;
import d.k.b.a0;
import d.m.e;
import d.q.a;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class n extends ComponentActivity implements b.d {
    public static final String FRAGMENTS_TAG = "android:support:fragments";
    public boolean mCreated;
    public final d.m.i mFragmentLifecycleRegistry;
    public final v mFragments;
    public boolean mResumed;
    public boolean mStopped;

    public class a implements a.b {
        public a() {
        }

        @Override // d.q.a.b
        public Bundle a() {
            Bundle bundle = new Bundle();
            n.this.markFragmentsCreated();
            n.this.mFragmentLifecycleRegistry.e(e.a.ON_STOP);
            Parcelable parcelableZ = n.this.mFragments.a.f3171o.Z();
            if (parcelableZ != null) {
                bundle.putParcelable(n.FRAGMENTS_TAG, parcelableZ);
            }
            return bundle;
        }
    }

    public class b implements d.a.d.b {
        public b() {
        }

        @Override // d.a.d.b
        public void a(Context context) {
            x<?> xVar = n.this.mFragments.a;
            xVar.f3171o.b(xVar, xVar, null);
            Bundle bundleA = n.this.getSavedStateRegistry().a(n.FRAGMENTS_TAG);
            if (bundleA != null) {
                Parcelable parcelable = bundleA.getParcelable(n.FRAGMENTS_TAG);
                x<?> xVar2 = n.this.mFragments.a;
                if (!(xVar2 instanceof d.m.z)) {
                    throw new IllegalStateException("Your FragmentHostCallback must implement ViewModelStoreOwner to call restoreSaveState(). Call restoreAllState()  if you're still using retainNestedNonConfig().");
                }
                xVar2.f3171o.Y(parcelable);
            }
        }
    }

    public class c extends x<n> implements d.m.z, d.a.c, d.a.e.f, e0 {
        public c() {
            super(n.this);
        }

        @Override // d.k.b.e0
        public void a(a0 a0Var, m mVar) {
            n.this.onAttachFragment(mVar);
        }

        @Override // d.k.b.t
        public View b(int i2) {
            return n.this.findViewById(i2);
        }

        @Override // d.k.b.t
        public boolean c() {
            Window window = n.this.getWindow();
            return (window == null || window.peekDecorView() == null) ? false : true;
        }

        @Override // d.k.b.x
        public n d() {
            return n.this;
        }

        @Override // d.k.b.x
        public LayoutInflater e() {
            return n.this.getLayoutInflater().cloneInContext(n.this);
        }

        @Override // d.k.b.x
        public boolean f(m mVar) {
            return !n.this.isFinishing();
        }

        @Override // d.k.b.x
        public void g() {
            n.this.supportInvalidateOptionsMenu();
        }

        @Override // d.a.e.f
        public d.a.e.e getActivityResultRegistry() {
            return n.this.getActivityResultRegistry();
        }

        @Override // d.m.h
        public d.m.e getLifecycle() {
            return n.this.mFragmentLifecycleRegistry;
        }

        @Override // d.a.c
        public OnBackPressedDispatcher getOnBackPressedDispatcher() {
            return n.this.getOnBackPressedDispatcher();
        }

        @Override // d.m.z
        public d.m.y getViewModelStore() {
            return n.this.getViewModelStore();
        }
    }

    public n() {
        c cVar = new c();
        d.h.b.h.e(cVar, "callbacks == null");
        this.mFragments = new v(cVar);
        this.mFragmentLifecycleRegistry = new d.m.i(this);
        this.mStopped = true;
        init();
    }

    private void init() {
        getSavedStateRegistry().b(FRAGMENTS_TAG, new a());
        addOnContextAvailableListener(new b());
    }

    private static boolean markState(a0 a0Var, e.b bVar) {
        e.b bVar2 = e.b.STARTED;
        boolean zMarkState = false;
        for (m mVar : a0Var.f2892c.i()) {
            if (mVar != null) {
                x<?> xVar = mVar.E;
                if ((xVar == null ? null : xVar.d()) != null) {
                    zMarkState |= markState(mVar.e(), bVar);
                }
                u0 u0Var = mVar.f3036a0;
                if (u0Var != null) {
                    u0Var.b();
                    if (u0Var.f3140m.f3190b.compareTo(bVar2) >= 0) {
                        d.m.i iVar = mVar.f3036a0.f3140m;
                        iVar.d("setCurrentState");
                        iVar.g(bVar);
                        zMarkState = true;
                    }
                }
                if (mVar.Z.f3190b.compareTo(bVar2) >= 0) {
                    d.m.i iVar2 = mVar.Z;
                    iVar2.d("setCurrentState");
                    iVar2.g(bVar);
                    zMarkState = true;
                }
            }
        }
        return zMarkState;
    }

    public final View dispatchFragmentsOnCreateView(View view, String str, Context context, AttributeSet attributeSet) {
        return this.mFragments.a.f3171o.f2895f.onCreateView(view, str, context, attributeSet);
    }

    @Override // android.app.Activity
    public void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
        super.dump(str, fileDescriptor, printWriter, strArr);
        printWriter.print(str);
        printWriter.print("Local FragmentActivity ");
        printWriter.print(Integer.toHexString(System.identityHashCode(this)));
        printWriter.println(" State:");
        String str2 = str + "  ";
        printWriter.print(str2);
        printWriter.print("mCreated=");
        printWriter.print(this.mCreated);
        printWriter.print(" mResumed=");
        printWriter.print(this.mResumed);
        printWriter.print(" mStopped=");
        printWriter.print(this.mStopped);
        if (getApplication() != null) {
            d.n.a.a.b(this).a(str2, fileDescriptor, printWriter, strArr);
        }
        this.mFragments.a.f3171o.y(str, fileDescriptor, printWriter, strArr);
    }

    public a0 getSupportFragmentManager() {
        return this.mFragments.a.f3171o;
    }

    @Deprecated
    public d.n.a.a getSupportLoaderManager() {
        return d.n.a.a.b(this);
    }

    public void markFragmentsCreated() {
        while (markState(getSupportFragmentManager(), e.b.CREATED)) {
        }
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public void onActivityResult(int i2, int i3, Intent intent) {
        this.mFragments.a();
        super.onActivityResult(i2, i3, intent);
    }

    @Deprecated
    public void onAttachFragment(m mVar) {
    }

    @Override // android.app.Activity, android.content.ComponentCallbacks
    public void onConfigurationChanged(Configuration configuration) {
        this.mFragments.a();
        super.onConfigurationChanged(configuration);
        this.mFragments.a.f3171o.k(configuration);
    }

    @Override // androidx.activity.ComponentActivity, d.h.b.i, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.mFragmentLifecycleRegistry.e(e.a.ON_CREATE);
        this.mFragments.a.f3171o.m();
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean onCreatePanelMenu(int i2, Menu menu) {
        if (i2 != 0) {
            return super.onCreatePanelMenu(i2, menu);
        }
        boolean zOnCreatePanelMenu = super.onCreatePanelMenu(i2, menu);
        v vVar = this.mFragments;
        return zOnCreatePanelMenu | vVar.a.f3171o.n(menu, getMenuInflater());
    }

    @Override // android.app.Activity, android.view.LayoutInflater.Factory2
    public View onCreateView(View view, String str, Context context, AttributeSet attributeSet) {
        View viewDispatchFragmentsOnCreateView = dispatchFragmentsOnCreateView(view, str, context, attributeSet);
        return viewDispatchFragmentsOnCreateView == null ? super.onCreateView(view, str, context, attributeSet) : viewDispatchFragmentsOnCreateView;
    }

    @Override // android.app.Activity, android.view.LayoutInflater.Factory
    public View onCreateView(String str, Context context, AttributeSet attributeSet) {
        View viewDispatchFragmentsOnCreateView = dispatchFragmentsOnCreateView(null, str, context, attributeSet);
        return viewDispatchFragmentsOnCreateView == null ? super.onCreateView(str, context, attributeSet) : viewDispatchFragmentsOnCreateView;
    }

    @Override // android.app.Activity
    public void onDestroy() {
        super.onDestroy();
        this.mFragments.a.f3171o.o();
        this.mFragmentLifecycleRegistry.e(e.a.ON_DESTROY);
    }

    @Override // android.app.Activity, android.content.ComponentCallbacks
    public void onLowMemory() {
        super.onLowMemory();
        this.mFragments.a.f3171o.p();
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean onMenuItemSelected(int i2, MenuItem menuItem) {
        if (super.onMenuItemSelected(i2, menuItem)) {
            return true;
        }
        if (i2 == 0) {
            return this.mFragments.a.f3171o.r(menuItem);
        }
        if (i2 != 6) {
            return false;
        }
        return this.mFragments.a.f3171o.l(menuItem);
    }

    @Override // android.app.Activity
    public void onMultiWindowModeChanged(boolean z2) {
        this.mFragments.a.f3171o.q(z2);
    }

    @Override // android.app.Activity
    public void onNewIntent(@SuppressLint({"UnknownNullness"}) Intent intent) {
        this.mFragments.a();
        super.onNewIntent(intent);
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public void onPanelClosed(int i2, Menu menu) {
        if (i2 == 0) {
            this.mFragments.a.f3171o.s(menu);
        }
        super.onPanelClosed(i2, menu);
    }

    @Override // android.app.Activity
    public void onPause() {
        super.onPause();
        this.mResumed = false;
        this.mFragments.a.f3171o.w(5);
        this.mFragmentLifecycleRegistry.e(e.a.ON_PAUSE);
    }

    @Override // android.app.Activity
    public void onPictureInPictureModeChanged(boolean z2) {
        this.mFragments.a.f3171o.u(z2);
    }

    @Override // android.app.Activity
    public void onPostResume() {
        super.onPostResume();
        onResumeFragments();
    }

    @Deprecated
    public boolean onPrepareOptionsPanel(View view, Menu menu) {
        return super.onPreparePanel(0, view, menu);
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean onPreparePanel(int i2, View view, Menu menu) {
        return i2 == 0 ? onPrepareOptionsPanel(view, menu) | this.mFragments.a.f3171o.v(menu) : super.onPreparePanel(i2, view, menu);
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public void onRequestPermissionsResult(int i2, String[] strArr, int[] iArr) {
        this.mFragments.a();
        super.onRequestPermissionsResult(i2, strArr, iArr);
    }

    @Override // android.app.Activity
    public void onResume() {
        this.mFragments.a();
        super.onResume();
        this.mResumed = true;
        this.mFragments.a.f3171o.C(true);
    }

    public void onResumeFragments() {
        this.mFragmentLifecycleRegistry.e(e.a.ON_RESUME);
        a0 a0Var = this.mFragments.a.f3171o;
        a0Var.B = false;
        a0Var.C = false;
        a0Var.J.f2968i = false;
        a0Var.w(7);
    }

    @Override // android.app.Activity
    public void onStart() {
        this.mFragments.a();
        super.onStart();
        this.mStopped = false;
        if (!this.mCreated) {
            this.mCreated = true;
            a0 a0Var = this.mFragments.a.f3171o;
            a0Var.B = false;
            a0Var.C = false;
            a0Var.J.f2968i = false;
            a0Var.w(4);
        }
        this.mFragments.a.f3171o.C(true);
        this.mFragmentLifecycleRegistry.e(e.a.ON_START);
        a0 a0Var2 = this.mFragments.a.f3171o;
        a0Var2.B = false;
        a0Var2.C = false;
        a0Var2.J.f2968i = false;
        a0Var2.w(5);
    }

    @Override // android.app.Activity
    public void onStateNotSaved() {
        this.mFragments.a();
    }

    @Override // android.app.Activity
    public void onStop() {
        super.onStop();
        this.mStopped = true;
        markFragmentsCreated();
        a0 a0Var = this.mFragments.a.f3171o;
        a0Var.C = true;
        a0Var.J.f2968i = true;
        a0Var.w(4);
        this.mFragmentLifecycleRegistry.e(e.a.ON_STOP);
    }

    public void setEnterSharedElementCallback(d.h.b.r rVar) {
        int i2 = d.h.b.b.f2569b;
        b.C0029b.c(this, null);
    }

    public void setExitSharedElementCallback(d.h.b.r rVar) {
        int i2 = d.h.b.b.f2569b;
        b.C0029b.d(this, null);
    }

    public void startActivityFromFragment(m mVar, @SuppressLint({"UnknownNullness"}) Intent intent, int i2) {
        startActivityFromFragment(mVar, intent, i2, (Bundle) null);
    }

    public void startActivityFromFragment(m mVar, @SuppressLint({"UnknownNullness"}) Intent intent, int i2, Bundle bundle) {
        if (i2 == -1) {
            int i3 = d.h.b.b.f2569b;
            b.a.b(this, intent, -1, bundle);
            return;
        }
        if (mVar.E == null) {
            throw new IllegalStateException(g.a.a.a.a.s("Fragment ", mVar, " not attached to Activity"));
        }
        a0 a0VarO = mVar.o();
        if (a0VarO.f2912w != null) {
            a0VarO.f2915z.addLast(new a0.k(mVar.f3044q, i2));
            if (intent != null && bundle != null) {
                intent.putExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE", bundle);
            }
            a0VarO.f2912w.a(intent, null);
            return;
        }
        x<?> xVar = a0VarO.f2906q;
        Objects.requireNonNull(xVar);
        if (i2 != -1) {
            throw new IllegalStateException("Starting activity with a requestCode requires a FragmentActivity host");
        }
        Context context = xVar.f3169m;
        Object obj = d.h.c.a.a;
        a.C0030a.b(context, intent, bundle);
    }

    @Deprecated
    public void startIntentSenderFromFragment(m mVar, @SuppressLint({"UnknownNullness"}) IntentSender intentSender, int i2, Intent intent, int i3, int i4, int i5, Bundle bundle) throws IntentSender.SendIntentException {
        Intent intent2 = intent;
        if (i2 == -1) {
            int i6 = d.h.b.b.f2569b;
            b.a.c(this, intentSender, i2, intent, i3, i4, i5, bundle);
            return;
        }
        if (mVar.E == null) {
            throw new IllegalStateException(g.a.a.a.a.s("Fragment ", mVar, " not attached to Activity"));
        }
        if (a0.M(2)) {
            Log.v("FragmentManager", "Fragment " + mVar + " received the following in startIntentSenderForResult() requestCode: " + i2 + " IntentSender: " + intentSender + " fillInIntent: " + intent2 + " options: " + bundle);
        }
        a0 a0VarO = mVar.o();
        if (a0VarO.f2913x == null) {
            x<?> xVar = a0VarO.f2906q;
            Objects.requireNonNull(xVar);
            if (i2 != -1) {
                throw new IllegalStateException("Starting intent sender with a requestCode requires a FragmentActivity host");
            }
            Activity activity = xVar.f3168f;
            int i7 = d.h.b.b.f2569b;
            b.a.c(activity, intentSender, i2, intent, i3, i4, i5, bundle);
            return;
        }
        if (bundle != null) {
            if (intent2 == null) {
                intent2 = new Intent();
                intent2.putExtra("androidx.fragment.extra.ACTIVITY_OPTIONS_BUNDLE", true);
            }
            if (a0.M(2)) {
                Log.v("FragmentManager", "ActivityOptions " + bundle + " were added to fillInIntent " + intent2 + " for fragment " + mVar);
            }
            intent2.putExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE", bundle);
        }
        d.a.e.g gVar = new d.a.e.g(intentSender, intent2, i3, i4);
        a0VarO.f2915z.addLast(new a0.k(mVar.f3044q, i2));
        if (a0.M(2)) {
            Log.v("FragmentManager", "Fragment " + mVar + "is launching an IntentSender for result ");
        }
        a0VarO.f2913x.a(gVar, null);
    }

    public void supportFinishAfterTransition() {
        int i2 = d.h.b.b.f2569b;
        b.C0029b.a(this);
    }

    @Deprecated
    public void supportInvalidateOptionsMenu() {
        invalidateOptionsMenu();
    }

    public void supportPostponeEnterTransition() {
        int i2 = d.h.b.b.f2569b;
        b.C0029b.b(this);
    }

    public void supportStartPostponedEnterTransition() {
        int i2 = d.h.b.b.f2569b;
        b.C0029b.e(this);
    }

    @Override // d.h.b.b.d
    @Deprecated
    public final void validateRequestPermissionsRequestCode(int i2) {
    }

    public n(int i2) {
        super(i2);
        c cVar = new c();
        d.h.b.h.e(cVar, "callbacks == null");
        this.mFragments = new v(cVar);
        this.mFragmentLifecycleRegistry = new d.m.i(this);
        this.mStopped = true;
        init();
    }
}
