package o;

import android.graphics.Rect;
import android.view.View;
import java.lang.ref.WeakReference;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class A4 implements InterfaceC2813wX {
    public HK a;
    public C2058oa0 b;
    public NK c;
    public C1363h80 d;

    @Override // o.InterfaceC2813wX
    public final void a(C2730ve0 c2730ve0, HG hg, C1358h6 c1358h6, C0661Zm c0661Zm) {
        j(new F1(c2730ve0, this, hg, c1358h6, c0661Zm, 1));
    }

    @Override // o.InterfaceC2813wX
    public final void b() {
        j(null);
    }

    @Override // o.InterfaceC2813wX
    public final void c(T00 t00) {
        Rect rect;
        NK nk = this.c;
        if (nk != null) {
            nk.l = new Rect(C2887xC.D(t00.a), C2887xC.D(t00.b), C2887xC.D(t00.c), C2887xC.D(t00.d));
            if (!nk.j.isEmpty() || (rect = nk.l) == null) {
                return;
            }
            nk.a.requestRectangleOnScreen(new Rect(rect));
        }
    }

    @Override // o.InterfaceC2813wX
    public final void d(C2730ve0 c2730ve0, C2730ve0 c2730ve02) {
        NK nk = this.c;
        if (nk != null) {
            boolean z = (Ue0.b(nk.h.b, c2730ve02.b) && F3.c(nk.h.c, c2730ve02.c)) ? false : true;
            nk.h = c2730ve02;
            int size = nk.j.size();
            for (int i = 0; i < size; i++) {
                R00 r00 = (R00) ((WeakReference) nk.j.get(i)).get();
                if (r00 != null) {
                    r00.g = c2730ve02;
                }
            }
            IK ik = nk.m;
            synchronized (ik.c) {
                ik.j = null;
                ik.l = null;
                ik.k = null;
                ik.m = null;
                ik.n = null;
            }
            if (F3.c(c2730ve0, c2730ve02)) {
                if (z) {
                    DH dh = nk.b;
                    int iF = Ue0.f(c2730ve02.b);
                    int iE = Ue0.e(c2730ve02.b);
                    Ue0 ue0 = nk.h.c;
                    int iF2 = ue0 != null ? Ue0.f(ue0.a) : -1;
                    Ue0 ue02 = nk.h.c;
                    dh.m().updateSelection((View) dh.l, iF, iE, iF2, ue02 != null ? Ue0.e(ue02.a) : -1);
                    return;
                }
                return;
            }
            if (c2730ve0 != null && (!F3.c(c2730ve0.a.m, c2730ve02.a.m) || (Ue0.b(c2730ve0.b, c2730ve02.b) && !F3.c(c2730ve0.c, c2730ve02.c)))) {
                DH dh2 = nk.b;
                dh2.m().restartInput((View) dh2.l);
                return;
            }
            int size2 = nk.j.size();
            for (int i2 = 0; i2 < size2; i2++) {
                R00 r002 = (R00) ((WeakReference) nk.j.get(i2)).get();
                if (r002 != null) {
                    C2730ve0 c2730ve03 = nk.h;
                    DH dh3 = nk.b;
                    if (r002.k) {
                        r002.g = c2730ve03;
                        if (r002.i) {
                            dh3.m().updateExtractedText((View) dh3.l, r002.h, AbstractC2378rs0.B(c2730ve03));
                        }
                        Ue0 ue03 = c2730ve03.c;
                        long j = c2730ve03.b;
                        int iF3 = ue03 != null ? Ue0.f(ue03.a) : -1;
                        Ue0 ue04 = c2730ve03.c;
                        dh3.m().updateSelection((View) dh3.l, Ue0.f(j), Ue0.e(j), iF3, ue04 != null ? Ue0.e(ue04.a) : -1);
                    }
                }
            }
        }
    }

    @Override // o.InterfaceC2813wX
    public final void e() {
        M90 m90;
        HK hk = this.a;
        if (hk == null || (m90 = (M90) AbstractC2461sm0.j(hk, AbstractC0840bl.p)) == null) {
            return;
        }
        ((C1234fr) m90).b();
    }

    @Override // o.InterfaceC2813wX
    public final void f() {
        M90 m90;
        HK hk = this.a;
        if (hk == null || (m90 = (M90) AbstractC2461sm0.j(hk, AbstractC0840bl.p)) == null) {
            return;
        }
        ((C1234fr) m90).a();
    }

    @Override // o.InterfaceC2813wX
    public final void g() {
        C2058oa0 c2058oa0 = this.b;
        if (c2058oa0 != null) {
            c2058oa0.c(null);
        }
        this.b = null;
        InterfaceC1000dR interfaceC1000dRI = i();
        if (interfaceC1000dRI != null) {
            C1363h80 c1363h80 = (C1363h80) interfaceC1000dRI;
            synchronized (c1363h80) {
                c1363h80.u(c1363h80.o() + c1363h80.v, c1363h80.u, c1363h80.o() + c1363h80.v, c1363h80.o() + c1363h80.v + c1363h80.w);
            }
        }
    }

    @Override // o.InterfaceC2813wX
    public final void h(C2730ve0 c2730ve0, InterfaceC1955nT interfaceC1955nT, Ne0 ne0, C1513in c1513in, T00 t00, T00 t002) {
        NK nk = this.c;
        if (nk != null) {
            IK ik = nk.m;
            synchronized (ik.c) {
                try {
                    ik.j = c2730ve0;
                    ik.l = interfaceC1955nT;
                    ik.k = ne0;
                    ik.m = t00;
                    ik.n = t002;
                    if (ik.e || ik.d) {
                        ik.a();
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
    }

    public final InterfaceC1000dR i() {
        C1363h80 c1363h80 = this.d;
        if (c1363h80 != null) {
            return c1363h80;
        }
        if (!AbstractC1870mb0.a) {
            return null;
        }
        C1363h80 c1363h80C = C1884mi0.c(3, 2);
        this.d = c1363h80C;
        return c1363h80C;
    }

    public final void j(F1 f1) {
        HK hk = this.a;
        if (hk == null) {
            return;
        }
        this.b = hk.y ? AbstractC1692kh0.C(hk.v0(), null, new C2105p(hk, new C3063z4(f1, this, hk, c2058oa0, 0), c2058oa0, 26), 1) : null;
    }

    public final void k(HK hk) {
        if (this.a != hk) {
            AbstractC2417sH.c("Expected textInputModifierNode to be " + hk + " but was " + this.a);
        }
        this.a = null;
    }
}
