package yh;

import android.content.Context;
import android.util.Log;
import androidx.fragment.app.z;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/* loaded from: classes4.dex */
public class v extends androidx.fragment.app.f {

    /* renamed from: p, reason: collision with root package name */
    private final yh.a f52785p;

    /* renamed from: q, reason: collision with root package name */
    private final s f52786q;

    /* renamed from: r, reason: collision with root package name */
    private final Set f52787r;

    /* renamed from: s, reason: collision with root package name */
    private v f52788s;

    /* renamed from: t, reason: collision with root package name */
    private com.bumptech.glide.l f52789t;

    /* renamed from: u, reason: collision with root package name */
    private androidx.fragment.app.f f52790u;

    /* loaded from: classes4.dex */
    private class a implements s {
        a() {
        }

        @Override // yh.s
        public Set a() {
            Set<v> y10 = v.this.y();
            HashSet hashSet = new HashSet(y10.size());
            for (v vVar : y10) {
                if (vVar.B() != null) {
                    hashSet.add(vVar.B());
                }
            }
            return hashSet;
        }

        public String toString() {
            return super.toString() + "{fragment=" + v.this + "}";
        }
    }

    public v() {
        this(new yh.a());
    }

    private androidx.fragment.app.f A() {
        androidx.fragment.app.f parentFragment = getParentFragment();
        return parentFragment != null ? parentFragment : this.f52790u;
    }

    private static z C(androidx.fragment.app.f fVar) {
        while (fVar.getParentFragment() != null) {
            fVar = fVar.getParentFragment();
        }
        return fVar.getFragmentManager();
    }

    private boolean D(androidx.fragment.app.f fVar) {
        androidx.fragment.app.f A = A();
        while (true) {
            androidx.fragment.app.f parentFragment = fVar.getParentFragment();
            if (parentFragment == null) {
                return false;
            }
            if (parentFragment.equals(A)) {
                return true;
            }
            fVar = fVar.getParentFragment();
        }
    }

    private void E(Context context, z zVar) {
        H();
        v k10 = com.bumptech.glide.b.c(context).k().k(zVar);
        this.f52788s = k10;
        if (equals(k10)) {
            return;
        }
        this.f52788s.x(this);
    }

    private void F(v vVar) {
        this.f52787r.remove(vVar);
    }

    private void H() {
        v vVar = this.f52788s;
        if (vVar != null) {
            vVar.F(this);
            this.f52788s = null;
        }
    }

    private void x(v vVar) {
        this.f52787r.add(vVar);
    }

    public com.bumptech.glide.l B() {
        return this.f52789t;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void G(androidx.fragment.app.f fVar) {
        z C;
        this.f52790u = fVar;
        if (fVar == null || fVar.getContext() == null || (C = C(fVar)) == null) {
            return;
        }
        E(fVar.getContext(), C);
    }

    @Override // androidx.fragment.app.f
    public void onAttach(Context context) {
        super.onAttach(context);
        z C = C(this);
        if (C == null) {
            if (Log.isLoggable("SupportRMFragment", 5)) {
                Log.w("SupportRMFragment", "Unable to register fragment with root, ancestor detached");
            }
        } else {
            try {
                E(getContext(), C);
            } catch (IllegalStateException e10) {
                if (Log.isLoggable("SupportRMFragment", 5)) {
                    Log.w("SupportRMFragment", "Unable to register fragment with root", e10);
                }
            }
        }
    }

    @Override // androidx.fragment.app.f
    public void onDestroy() {
        super.onDestroy();
        this.f52785p.c();
        H();
    }

    @Override // androidx.fragment.app.f
    public void onDetach() {
        super.onDetach();
        this.f52790u = null;
        H();
    }

    @Override // androidx.fragment.app.f
    public void onStart() {
        super.onStart();
        this.f52785p.d();
    }

    @Override // androidx.fragment.app.f
    public void onStop() {
        super.onStop();
        this.f52785p.e();
    }

    @Override // androidx.fragment.app.f
    public String toString() {
        return super.toString() + "{parent=" + A() + "}";
    }

    Set y() {
        v vVar = this.f52788s;
        if (vVar == null) {
            return Collections.emptySet();
        }
        if (equals(vVar)) {
            return Collections.unmodifiableSet(this.f52787r);
        }
        HashSet hashSet = new HashSet();
        for (v vVar2 : this.f52788s.y()) {
            if (D(vVar2.A())) {
                hashSet.add(vVar2);
            }
        }
        return Collections.unmodifiableSet(hashSet);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public yh.a z() {
        return this.f52785p;
    }

    public v(yh.a aVar) {
        this.f52786q = new a();
        this.f52787r = new HashSet();
        this.f52785p = aVar;
    }
}
