package o;

import android.view.View;
import android.view.ViewTreeObserver;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Tz, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class ViewTreeObserverOnGlobalFocusChangeListenerC0518Tz extends LP implements InterfaceC0887cA, ViewTreeObserver.OnGlobalFocusChangeListener {
    public ViewTreeObserver A;
    public final C0492Sz B = new C0492Sz(this, 0);
    public final C0492Sz C = new C0492Sz(this, 1);
    public View z;

    @Override // o.LP
    public final void A0() {
        ViewTreeObserver viewTreeObserver = this.A;
        if (viewTreeObserver != null && viewTreeObserver.isAlive()) {
            viewTreeObserver.removeOnGlobalFocusChangeListener(this);
        }
        this.A = null;
        AbstractC0662Zn.F(this).getViewTreeObserver().removeOnGlobalFocusChangeListener(this);
        this.z = null;
    }

    public final C1556jA H0() {
        if (!this.l.y) {
            AbstractC2133pH.b("visitLocalDescendants called on an unattached node");
        }
        LP lp = this.l;
        if ((lp.f209o & 1024) != 0) {
            boolean z = false;
            for (LP lp2 = lp.q; lp2 != null; lp2 = lp2.q) {
                if ((lp2.n & 1024) != 0) {
                    LP lpI = lp2;
                    C1479iR c1479iR = null;
                    while (lpI != null) {
                        if (lpI instanceof C1556jA) {
                            C1556jA c1556jA = (C1556jA) lpI;
                            if (z) {
                                return c1556jA;
                            }
                            z = true;
                        } else if ((lpI.n & 1024) != 0 && (lpI instanceof AbstractC0561Vq)) {
                            int i = 0;
                            for (LP lp3 = ((AbstractC0561Vq) lpI).A; lp3 != null; lp3 = lp3.q) {
                                if ((lp3.n & 1024) != 0) {
                                    i++;
                                    if (i == 1) {
                                        lpI = lp3;
                                    } else {
                                        if (c1479iR == null) {
                                            c1479iR = new C1479iR(new LP[16]);
                                        }
                                        if (lpI != null) {
                                            c1479iR.b(lpI);
                                            lpI = null;
                                        }
                                        c1479iR.b(lp3);
                                    }
                                }
                            }
                            if (i == 1) {
                            }
                        }
                        lpI = AbstractC2539te.i(c1479iR);
                    }
                }
            }
        }
        throw new IllegalStateException("Could not find focus target of embedded view wrapper");
    }

    @Override // o.InterfaceC0887cA
    public final void S(InterfaceC0696aA interfaceC0696aA) {
        interfaceC0696aA.c(false);
        interfaceC0696aA.a(this.B);
        interfaceC0696aA.d(this.C);
    }

    @Override // android.view.ViewTreeObserver.OnGlobalFocusChangeListener
    public final void onGlobalFocusChanged(View view, View view2) {
        if (AbstractC2539te.S(this).x == null) {
            return;
        }
        View viewI = AbstractC2001nt0.i(this);
        InterfaceC0622Xz focusOwner = ((C2207q3) AbstractC2539te.T(this)).getFocusOwner();
        InterfaceC1577jV interfaceC1577jVT = AbstractC2539te.T(this);
        boolean z = (view == null || view.equals(interfaceC1577jVT) || !AbstractC2001nt0.g(viewI, view)) ? false : true;
        boolean z2 = (view2 == null || view2.equals(interfaceC1577jVT) || !AbstractC2001nt0.g(viewI, view2)) ? false : true;
        if (z && z2) {
            this.z = view2;
            return;
        }
        if (!z2) {
            if (!z) {
                this.z = null;
                return;
            }
            this.z = null;
            if (H0().J0().a()) {
                ((C0674Zz) focusOwner).b(8, false, false);
                return;
            }
            return;
        }
        this.z = view2;
        C1556jA c1556jAH0 = H0();
        int iOrdinal = c1556jAH0.J0().ordinal();
        if (iOrdinal == 0 || iOrdinal == 1 || iOrdinal == 2) {
            return;
        }
        if (iOrdinal != 3) {
            throw new C2170pj();
        }
        AbstractC0662Zn.B(c1556jAH0);
    }

    @Override // o.LP
    public final void z0() {
        ViewTreeObserver viewTreeObserver = AbstractC0662Zn.F(this).getViewTreeObserver();
        this.A = viewTreeObserver;
        viewTreeObserver.addOnGlobalFocusChangeListener(this);
    }
}
