package androidx.fragment.app;

import android.util.Log;
import androidx.lifecycle.AbstractC0405c0;
import androidx.lifecycle.C0407d0;
import androidx.lifecycle.C0417e0;
import androidx.lifecycle.C0421g0;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import p056s0.AbstractC1611a;

/* renamed from: androidx.fragment.app.p */
/* loaded from: classes.dex */
public final class C0356p extends AbstractC0405c0 {

    /* renamed from: k */
    public static final C0407d0.InterfaceC0411b f1439k = new C0357a();

    /* renamed from: g */
    public final boolean f1443g;

    /* renamed from: d */
    public final HashMap<String, Fragment> f1440d = new HashMap<>();

    /* renamed from: e */
    public final HashMap<String, C0356p> f1441e = new HashMap<>();

    /* renamed from: f */
    public final HashMap<String, C0421g0> f1442f = new HashMap<>();

    /* renamed from: h */
    public boolean f1444h = false;

    /* renamed from: i */
    public boolean f1445i = false;

    /* renamed from: j */
    public boolean f1446j = false;

    /* renamed from: androidx.fragment.app.p$a */
    /* loaded from: classes.dex */
    public class C0357a implements C0407d0.InterfaceC0411b {
        @Override // androidx.lifecycle.C0407d0.InterfaceC0411b
        /* renamed from: a */
        public <T extends AbstractC0405c0> T mo693a(Class<T> cls) {
            return new C0356p(true);
        }

        @Override // androidx.lifecycle.C0407d0.InterfaceC0411b
        /* renamed from: b */
        public /* synthetic */ AbstractC0405c0 mo692b(Class cls, AbstractC1611a abstractC1611a) {
            return C0417e0.m3710b(this, cls, abstractC1611a);
        }
    }

    public C0356p(boolean z) {
        this.f1443g = z;
    }

    /* renamed from: i */
    public static C0356p m3884i(C0421g0 c0421g0) {
        return (C0356p) new C0407d0(c0421g0, f1439k).m3720a(C0356p.class);
    }

    @Override // androidx.lifecycle.AbstractC0405c0
    /* renamed from: d */
    public void mo697d() {
        if (AbstractC0330m.m4049B0(3)) {
            Log.d("FragmentManager", "onCleared called for " + this);
        }
        this.f1444h = true;
    }

    /* renamed from: e */
    public void m3888e(Fragment fragment) {
        if (this.f1446j) {
            if (AbstractC0330m.m4049B0(2)) {
                Log.v("FragmentManager", "Ignoring addRetainedFragment as the state is already saved");
            }
        } else if (this.f1440d.containsKey(fragment.f1186i)) {
        } else {
            this.f1440d.put(fragment.f1186i, fragment);
            if (AbstractC0330m.m4049B0(2)) {
                Log.v("FragmentManager", "Updating retained Fragments: Added " + fragment);
            }
        }
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || C0356p.class != obj.getClass()) {
            return false;
        }
        C0356p c0356p = (C0356p) obj;
        return this.f1440d.equals(c0356p.f1440d) && this.f1441e.equals(c0356p.f1441e) && this.f1442f.equals(c0356p.f1442f);
    }

    /* renamed from: f */
    public void m3887f(Fragment fragment) {
        if (AbstractC0330m.m4049B0(3)) {
            Log.d("FragmentManager", "Clearing non-config state for " + fragment);
        }
        C0356p c0356p = this.f1441e.get(fragment.f1186i);
        if (c0356p != null) {
            c0356p.mo697d();
            this.f1441e.remove(fragment.f1186i);
        }
        C0421g0 c0421g0 = this.f1442f.get(fragment.f1186i);
        if (c0421g0 != null) {
            c0421g0.m3706a();
            this.f1442f.remove(fragment.f1186i);
        }
    }

    /* renamed from: g */
    public Fragment m3886g(String str) {
        return this.f1440d.get(str);
    }

    /* renamed from: h */
    public C0356p m3885h(Fragment fragment) {
        C0356p c0356p = this.f1441e.get(fragment.f1186i);
        if (c0356p == null) {
            C0356p c0356p2 = new C0356p(this.f1443g);
            this.f1441e.put(fragment.f1186i, c0356p2);
            return c0356p2;
        }
        return c0356p;
    }

    public int hashCode() {
        return (((this.f1440d.hashCode() * 31) + this.f1441e.hashCode()) * 31) + this.f1442f.hashCode();
    }

    /* renamed from: j */
    public Collection<Fragment> m3883j() {
        return new ArrayList(this.f1440d.values());
    }

    /* renamed from: k */
    public C0421g0 m3882k(Fragment fragment) {
        C0421g0 c0421g0 = this.f1442f.get(fragment.f1186i);
        if (c0421g0 == null) {
            C0421g0 c0421g02 = new C0421g0();
            this.f1442f.put(fragment.f1186i, c0421g02);
            return c0421g02;
        }
        return c0421g0;
    }

    /* renamed from: l */
    public boolean m3881l() {
        return this.f1444h;
    }

    /* renamed from: m */
    public void m3880m(Fragment fragment) {
        if (this.f1446j) {
            if (AbstractC0330m.m4049B0(2)) {
                Log.v("FragmentManager", "Ignoring removeRetainedFragment as the state is already saved");
                return;
            }
            return;
        }
        if ((this.f1440d.remove(fragment.f1186i) != null) && AbstractC0330m.m4049B0(2)) {
            Log.v("FragmentManager", "Updating retained Fragments: Removed " + fragment);
        }
    }

    /* renamed from: n */
    public void m3879n(boolean z) {
        this.f1446j = z;
    }

    /* renamed from: o */
    public boolean m3878o(Fragment fragment) {
        if (this.f1440d.containsKey(fragment.f1186i)) {
            return this.f1443g ? this.f1444h : !this.f1445i;
        }
        return true;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder("FragmentManagerViewModel{");
        sb.append(Integer.toHexString(System.identityHashCode(this)));
        sb.append("} Fragments (");
        Iterator<Fragment> it = this.f1440d.values().iterator();
        while (it.hasNext()) {
            sb.append(it.next());
            if (it.hasNext()) {
                sb.append(", ");
            }
        }
        sb.append(") Child Non Config (");
        Iterator<String> it2 = this.f1441e.keySet().iterator();
        while (it2.hasNext()) {
            sb.append(it2.next());
            if (it2.hasNext()) {
                sb.append(", ");
            }
        }
        sb.append(") ViewModelStores (");
        Iterator<String> it3 = this.f1442f.keySet().iterator();
        while (it3.hasNext()) {
            sb.append(it3.next());
            if (it3.hasNext()) {
                sb.append(", ");
            }
        }
        sb.append(')');
        return sb.toString();
    }
}