package androidx.leanback.widget;

import V.C0629x;
import n.C2580g;

/* JADX INFO: loaded from: classes.dex */
public final class O extends AbstractC1078j {

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final C1077i f11840j = new C1077i(0);

    public O() {
        n(1);
    }

    @Override // androidx.leanback.widget.AbstractC1078j
    public final boolean b(int i6, boolean z6) {
        int iMin;
        int iN;
        if (this.f11983b.i() == 0 || (!z6 && c(i6))) {
            return false;
        }
        int i7 = this.f11988g;
        if (i7 >= 0) {
            iMin = i7 + 1;
        } else {
            int i8 = this.f11990i;
            iMin = i8 != -1 ? Math.min(i8, this.f11983b.i() - 1) : 0;
        }
        int i9 = iMin;
        boolean z7 = false;
        while (i9 < this.f11983b.i()) {
            C0.B b5 = this.f11983b;
            Object[] objArr = this.f11982a;
            int iG = b5.g(i9, true, objArr, false);
            if (this.f11987f < 0 || this.f11988g < 0) {
                iN = this.f11984c ? Integer.MAX_VALUE : Integer.MIN_VALUE;
                this.f11987f = i9;
                this.f11988g = i9;
            } else {
                if (this.f11984c) {
                    int i10 = i9 - 1;
                    iN = (this.f11983b.l(i10) - this.f11983b.n(i10)) - this.f11985d;
                } else {
                    int i11 = i9 - 1;
                    iN = this.f11985d + this.f11983b.n(i11) + this.f11983b.l(i11);
                }
                this.f11988g = i9;
            }
            this.f11983b.d(objArr[0], i9, iG, 0, iN);
            if (z6 || c(i6)) {
                return true;
            }
            i9++;
            z7 = true;
        }
        return z7;
    }

    @Override // androidx.leanback.widget.AbstractC1078j
    public final void e(int i6, int i7, C0629x c0629x) {
        int iO;
        int iL;
        if (!this.f11984c ? i7 < 0 : i7 > 0) {
            if (this.f11988g == this.f11983b.i() - 1) {
                return;
            }
            int i8 = this.f11988g;
            if (i8 >= 0) {
                iO = i8 + 1;
            } else {
                int i9 = this.f11990i;
                iO = i9 != -1 ? Math.min(i9, this.f11983b.i() - 1) : 0;
            }
            int iN = this.f11983b.n(this.f11988g) + this.f11985d;
            int iL2 = this.f11983b.l(this.f11988g);
            if (this.f11984c) {
                iN = -iN;
            }
            iL = iN + iL2;
        } else {
            if (this.f11987f == 0) {
                return;
            }
            iO = o();
            iL = this.f11983b.l(this.f11987f) + (this.f11984c ? this.f11985d : -this.f11985d);
        }
        c0629x.a(iO, Math.abs(iL - i6));
    }

    @Override // androidx.leanback.widget.AbstractC1078j
    public final int g(int[] iArr, int i6, boolean z6) {
        if (iArr != null) {
            iArr[0] = 0;
            iArr[1] = i6;
        }
        if (this.f11984c) {
            return this.f11983b.l(i6);
        }
        return this.f11983b.n(i6) + this.f11983b.l(i6);
    }

    @Override // androidx.leanback.widget.AbstractC1078j
    public final int i(int[] iArr, int i6, boolean z6) {
        if (iArr != null) {
            iArr[0] = 0;
            iArr[1] = i6;
        }
        return this.f11984c ? this.f11983b.l(i6) - this.f11983b.n(i6) : this.f11983b.l(i6);
    }

    @Override // androidx.leanback.widget.AbstractC1078j
    public final C2580g[] j(int i6, int i7) {
        C2580g c2580g = this.f11989h[0];
        c2580g.f21438c = c2580g.f21437b;
        c2580g.a(i6);
        this.f11989h[0].a(i7);
        return this.f11989h;
    }

    @Override // androidx.leanback.widget.AbstractC1078j
    public final C1077i k(int i6) {
        return this.f11840j;
    }

    @Override // androidx.leanback.widget.AbstractC1078j
    public final boolean m(int i6, boolean z6) {
        int iL;
        if (this.f11983b.i() == 0 || (!z6 && d(i6))) {
            return false;
        }
        int i7 = ((C1084p) this.f11983b.f506b).f12052u;
        boolean z7 = false;
        for (int iO = o(); iO >= i7; iO--) {
            C0.B b5 = this.f11983b;
            Object[] objArr = this.f11982a;
            int iG = b5.g(iO, false, objArr, false);
            if (this.f11987f < 0 || this.f11988g < 0) {
                iL = this.f11984c ? Integer.MIN_VALUE : Integer.MAX_VALUE;
                this.f11987f = iO;
                this.f11988g = iO;
            } else {
                iL = this.f11984c ? this.f11983b.l(iO + 1) + this.f11985d + iG : (this.f11983b.l(iO + 1) - this.f11985d) - iG;
                this.f11987f = iO;
            }
            this.f11983b.d(objArr[0], iO, iG, 0, iL);
            z7 = true;
            if (z6 || d(i6)) {
                break;
            }
        }
        return z7;
    }

    public final int o() {
        int i6 = this.f11987f;
        if (i6 >= 0) {
            return i6 - 1;
        }
        int i7 = this.f11990i;
        return i7 != -1 ? Math.min(i7, this.f11983b.i() - 1) : this.f11983b.i() - 1;
    }
}
