package androidx.recyclerview.widget;

import android.content.Context;
import android.graphics.PointF;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.util.List;

/* loaded from: classes.dex */
public class LinearLayoutManager extends RecyclerView.p implements RecyclerView.a0.b {
    int H;
    private c I;
    n J;
    private boolean K;
    private boolean L;
    boolean M;
    private boolean N;
    private boolean O;
    int P;
    int Q;
    private boolean R;
    d S;
    final a T;
    private final b U;
    private int V;
    private int[] W;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class a {

        /* renamed from: a, reason: collision with root package name */
        n f5087a;

        /* renamed from: b, reason: collision with root package name */
        int f5088b;

        /* renamed from: c, reason: collision with root package name */
        int f5089c;

        /* renamed from: d, reason: collision with root package name */
        boolean f5090d;

        /* renamed from: e, reason: collision with root package name */
        boolean f5091e;

        a() {
            e();
        }

        void a() {
            this.f5089c = this.f5090d ? this.f5087a.i() : this.f5087a.m();
        }

        public void b(View view, int i10) {
            if (this.f5090d) {
                this.f5089c = this.f5087a.d(view) + this.f5087a.o();
            } else {
                this.f5089c = this.f5087a.g(view);
            }
            this.f5088b = i10;
        }

        public void c(View view, int i10) {
            int o10 = this.f5087a.o();
            if (o10 >= 0) {
                b(view, i10);
                return;
            }
            this.f5088b = i10;
            if (this.f5090d) {
                int i11 = (this.f5087a.i() - o10) - this.f5087a.d(view);
                this.f5089c = this.f5087a.i() - i11;
                if (i11 > 0) {
                    int e10 = this.f5089c - this.f5087a.e(view);
                    int m10 = this.f5087a.m();
                    int min = e10 - (m10 + Math.min(this.f5087a.g(view) - m10, 0));
                    if (min < 0) {
                        this.f5089c += Math.min(i11, -min);
                        return;
                    }
                    return;
                }
                return;
            }
            int g10 = this.f5087a.g(view);
            int m11 = g10 - this.f5087a.m();
            this.f5089c = g10;
            if (m11 > 0) {
                int i12 = (this.f5087a.i() - Math.min(0, (this.f5087a.i() - o10) - this.f5087a.d(view))) - (g10 + this.f5087a.e(view));
                if (i12 < 0) {
                    this.f5089c -= Math.min(m11, -i12);
                }
            }
        }

        boolean d(View view, RecyclerView.b0 b0Var) {
            RecyclerView.q qVar = (RecyclerView.q) view.getLayoutParams();
            return !qVar.c() && qVar.a() >= 0 && qVar.a() < b0Var.b();
        }

        void e() {
            this.f5088b = -1;
            this.f5089c = Integer.MIN_VALUE;
            this.f5090d = false;
            this.f5091e = false;
        }

        public String toString() {
            return "AnchorInfo{mPosition=" + this.f5088b + ", mCoordinate=" + this.f5089c + ", mLayoutFromEnd=" + this.f5090d + ", mValid=" + this.f5091e + '}';
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    /* loaded from: classes.dex */
    public static class b {

        /* renamed from: a, reason: collision with root package name */
        public int f5092a;

        /* renamed from: b, reason: collision with root package name */
        public boolean f5093b;

        /* renamed from: c, reason: collision with root package name */
        public boolean f5094c;

        /* renamed from: d, reason: collision with root package name */
        public boolean f5095d;

        protected b() {
        }

        void a() {
            this.f5092a = 0;
            this.f5093b = false;
            this.f5094c = false;
            this.f5095d = false;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class c {

        /* renamed from: b, reason: collision with root package name */
        int f5097b;

        /* renamed from: c, reason: collision with root package name */
        int f5098c;

        /* renamed from: d, reason: collision with root package name */
        int f5099d;

        /* renamed from: e, reason: collision with root package name */
        int f5100e;

        /* renamed from: f, reason: collision with root package name */
        int f5101f;

        /* renamed from: g, reason: collision with root package name */
        int f5102g;

        /* renamed from: k, reason: collision with root package name */
        int f5106k;

        /* renamed from: m, reason: collision with root package name */
        boolean f5108m;

        /* renamed from: a, reason: collision with root package name */
        boolean f5096a = true;

        /* renamed from: h, reason: collision with root package name */
        int f5103h = 0;

        /* renamed from: i, reason: collision with root package name */
        int f5104i = 0;

        /* renamed from: j, reason: collision with root package name */
        boolean f5105j = false;

        /* renamed from: l, reason: collision with root package name */
        List f5107l = null;

        c() {
        }

        private View e() {
            int size = this.f5107l.size();
            for (int i10 = 0; i10 < size; i10++) {
                View view = ((RecyclerView.e0) this.f5107l.get(i10)).f5192p;
                RecyclerView.q qVar = (RecyclerView.q) view.getLayoutParams();
                if (!qVar.c() && this.f5099d == qVar.a()) {
                    b(view);
                    return view;
                }
            }
            return null;
        }

        public void a() {
            b(null);
        }

        public void b(View view) {
            View f10 = f(view);
            if (f10 == null) {
                this.f5099d = -1;
            } else {
                this.f5099d = ((RecyclerView.q) f10.getLayoutParams()).a();
            }
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        public boolean c(RecyclerView.b0 b0Var) {
            int i10 = this.f5099d;
            return i10 >= 0 && i10 < b0Var.b();
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        public View d(RecyclerView.w wVar) {
            if (this.f5107l != null) {
                return e();
            }
            View o10 = wVar.o(this.f5099d);
            this.f5099d += this.f5100e;
            return o10;
        }

        public View f(View view) {
            int a10;
            int size = this.f5107l.size();
            View view2 = null;
            int i10 = Api.BaseClientBuilder.API_PRIORITY_OTHER;
            for (int i11 = 0; i11 < size; i11++) {
                View view3 = ((RecyclerView.e0) this.f5107l.get(i11)).f5192p;
                RecyclerView.q qVar = (RecyclerView.q) view3.getLayoutParams();
                if (view3 != view && !qVar.c() && (a10 = (qVar.a() - this.f5099d) * this.f5100e) >= 0 && a10 < i10) {
                    view2 = view3;
                    if (a10 == 0) {
                        break;
                    }
                    i10 = a10;
                }
            }
            return view2;
        }
    }

    /* loaded from: classes.dex */
    public static class d implements Parcelable {
        public static final Parcelable.Creator<d> CREATOR = new a();

        /* renamed from: p, reason: collision with root package name */
        int f5109p;

        /* renamed from: q, reason: collision with root package name */
        int f5110q;

        /* renamed from: r, reason: collision with root package name */
        boolean f5111r;

        /* loaded from: classes.dex */
        class a implements Parcelable.Creator {
            a() {
            }

            @Override // android.os.Parcelable.Creator
            /* renamed from: a, reason: merged with bridge method [inline-methods] */
            public d createFromParcel(Parcel parcel) {
                return new d(parcel);
            }

            @Override // android.os.Parcelable.Creator
            /* renamed from: b, reason: merged with bridge method [inline-methods] */
            public d[] newArray(int i10) {
                return new d[i10];
            }
        }

        public d() {
        }

        boolean a() {
            return this.f5109p >= 0;
        }

        void b() {
            this.f5109p = -1;
        }

        @Override // android.os.Parcelable
        public int describeContents() {
            return 0;
        }

        @Override // android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i10) {
            parcel.writeInt(this.f5109p);
            parcel.writeInt(this.f5110q);
            parcel.writeInt(this.f5111r ? 1 : 0);
        }

        d(Parcel parcel) {
            this.f5109p = parcel.readInt();
            this.f5110q = parcel.readInt();
            this.f5111r = parcel.readInt() == 1;
        }

        public d(d dVar) {
            this.f5109p = dVar.f5109p;
            this.f5110q = dVar.f5110q;
            this.f5111r = dVar.f5111r;
        }
    }

    public LinearLayoutManager(Context context) {
        this(context, 1, false);
    }

    private void A2(RecyclerView.w wVar, int i10, int i11) {
        if (i10 == i11) {
            return;
        }
        if (i11 <= i10) {
            while (i10 > i11) {
                v1(i10, wVar);
                i10--;
            }
        } else {
            for (int i12 = i11 - 1; i12 >= i10; i12--) {
                v1(i12, wVar);
            }
        }
    }

    private void B2(RecyclerView.w wVar, int i10, int i11) {
        int T = T();
        if (i10 < 0) {
            return;
        }
        int h10 = (this.J.h() - i10) + i11;
        if (this.M) {
            for (int i12 = 0; i12 < T; i12++) {
                View S = S(i12);
                if (this.J.g(S) < h10 || this.J.q(S) < h10) {
                    A2(wVar, 0, i12);
                    return;
                }
            }
            return;
        }
        int i13 = T - 1;
        for (int i14 = i13; i14 >= 0; i14--) {
            View S2 = S(i14);
            if (this.J.g(S2) < h10 || this.J.q(S2) < h10) {
                A2(wVar, i13, i14);
                return;
            }
        }
    }

    private void C2(RecyclerView.w wVar, int i10, int i11) {
        if (i10 < 0) {
            return;
        }
        int i12 = i10 - i11;
        int T = T();
        if (!this.M) {
            for (int i13 = 0; i13 < T; i13++) {
                View S = S(i13);
                if (this.J.d(S) > i12 || this.J.p(S) > i12) {
                    A2(wVar, 0, i13);
                    return;
                }
            }
            return;
        }
        int i14 = T - 1;
        for (int i15 = i14; i15 >= 0; i15--) {
            View S2 = S(i15);
            if (this.J.d(S2) > i12 || this.J.p(S2) > i12) {
                A2(wVar, i14, i15);
                return;
            }
        }
    }

    private void E2() {
        if (this.H == 1 || !u2()) {
            this.M = this.L;
        } else {
            this.M = !this.L;
        }
    }

    private boolean J2(RecyclerView.w wVar, RecyclerView.b0 b0Var, a aVar) {
        View n22;
        boolean z10 = false;
        if (T() == 0) {
            return false;
        }
        View f02 = f0();
        if (f02 != null && aVar.d(f02, b0Var)) {
            aVar.c(f02, n0(f02));
            return true;
        }
        boolean z11 = this.K;
        boolean z12 = this.N;
        if (z11 != z12 || (n22 = n2(wVar, b0Var, aVar.f5090d, z12)) == null) {
            return false;
        }
        aVar.b(n22, n0(n22));
        if (!b0Var.e() && T1()) {
            int g10 = this.J.g(n22);
            int d10 = this.J.d(n22);
            int m10 = this.J.m();
            int i10 = this.J.i();
            boolean z13 = d10 <= m10 && g10 < m10;
            if (g10 >= i10 && d10 > i10) {
                z10 = true;
            }
            if (z13 || z10) {
                if (aVar.f5090d) {
                    m10 = i10;
                }
                aVar.f5089c = m10;
            }
        }
        return true;
    }

    private boolean K2(RecyclerView.b0 b0Var, a aVar) {
        int i10;
        if (!b0Var.e() && (i10 = this.P) != -1) {
            if (i10 >= 0 && i10 < b0Var.b()) {
                aVar.f5088b = this.P;
                d dVar = this.S;
                if (dVar != null && dVar.a()) {
                    boolean z10 = this.S.f5111r;
                    aVar.f5090d = z10;
                    if (z10) {
                        aVar.f5089c = this.J.i() - this.S.f5110q;
                    } else {
                        aVar.f5089c = this.J.m() + this.S.f5110q;
                    }
                    return true;
                }
                if (this.Q != Integer.MIN_VALUE) {
                    boolean z11 = this.M;
                    aVar.f5090d = z11;
                    if (z11) {
                        aVar.f5089c = this.J.i() - this.Q;
                    } else {
                        aVar.f5089c = this.J.m() + this.Q;
                    }
                    return true;
                }
                View M = M(this.P);
                if (M == null) {
                    if (T() > 0) {
                        aVar.f5090d = (this.P < n0(S(0))) == this.M;
                    }
                    aVar.a();
                } else {
                    if (this.J.e(M) > this.J.n()) {
                        aVar.a();
                        return true;
                    }
                    if (this.J.g(M) - this.J.m() < 0) {
                        aVar.f5089c = this.J.m();
                        aVar.f5090d = false;
                        return true;
                    }
                    if (this.J.i() - this.J.d(M) < 0) {
                        aVar.f5089c = this.J.i();
                        aVar.f5090d = true;
                        return true;
                    }
                    aVar.f5089c = aVar.f5090d ? this.J.d(M) + this.J.o() : this.J.g(M);
                }
                return true;
            }
            this.P = -1;
            this.Q = Integer.MIN_VALUE;
        }
        return false;
    }

    private void L2(RecyclerView.w wVar, RecyclerView.b0 b0Var, a aVar) {
        if (K2(b0Var, aVar) || J2(wVar, b0Var, aVar)) {
            return;
        }
        aVar.a();
        aVar.f5088b = this.N ? b0Var.b() - 1 : 0;
    }

    private void M2(int i10, int i11, boolean z10, RecyclerView.b0 b0Var) {
        int m10;
        this.I.f5108m = D2();
        this.I.f5101f = i10;
        int[] iArr = this.W;
        iArr[0] = 0;
        iArr[1] = 0;
        U1(b0Var, iArr);
        int max = Math.max(0, this.W[0]);
        int max2 = Math.max(0, this.W[1]);
        boolean z11 = i10 == 1;
        c cVar = this.I;
        int i12 = z11 ? max2 : max;
        cVar.f5103h = i12;
        if (!z11) {
            max = max2;
        }
        cVar.f5104i = max;
        if (z11) {
            cVar.f5103h = i12 + this.J.j();
            View q22 = q2();
            c cVar2 = this.I;
            cVar2.f5100e = this.M ? -1 : 1;
            int n02 = n0(q22);
            c cVar3 = this.I;
            cVar2.f5099d = n02 + cVar3.f5100e;
            cVar3.f5097b = this.J.d(q22);
            m10 = this.J.d(q22) - this.J.i();
        } else {
            View r22 = r2();
            this.I.f5103h += this.J.m();
            c cVar4 = this.I;
            cVar4.f5100e = this.M ? 1 : -1;
            int n03 = n0(r22);
            c cVar5 = this.I;
            cVar4.f5099d = n03 + cVar5.f5100e;
            cVar5.f5097b = this.J.g(r22);
            m10 = (-this.J.g(r22)) + this.J.m();
        }
        c cVar6 = this.I;
        cVar6.f5098c = i11;
        if (z10) {
            cVar6.f5098c = i11 - m10;
        }
        cVar6.f5102g = m10;
    }

    private void N2(int i10, int i11) {
        this.I.f5098c = this.J.i() - i11;
        c cVar = this.I;
        cVar.f5100e = this.M ? -1 : 1;
        cVar.f5099d = i10;
        cVar.f5101f = 1;
        cVar.f5097b = i11;
        cVar.f5102g = Integer.MIN_VALUE;
    }

    private void O2(a aVar) {
        N2(aVar.f5088b, aVar.f5089c);
    }

    private void P2(int i10, int i11) {
        this.I.f5098c = i11 - this.J.m();
        c cVar = this.I;
        cVar.f5099d = i10;
        cVar.f5100e = this.M ? 1 : -1;
        cVar.f5101f = -1;
        cVar.f5097b = i11;
        cVar.f5102g = Integer.MIN_VALUE;
    }

    private void Q2(a aVar) {
        P2(aVar.f5088b, aVar.f5089c);
    }

    private int W1(RecyclerView.b0 b0Var) {
        if (T() == 0) {
            return 0;
        }
        b2();
        return q.a(b0Var, this.J, f2(!this.O, true), e2(!this.O, true), this, this.O);
    }

    private int X1(RecyclerView.b0 b0Var) {
        if (T() == 0) {
            return 0;
        }
        b2();
        return q.b(b0Var, this.J, f2(!this.O, true), e2(!this.O, true), this, this.O, this.M);
    }

    private int Y1(RecyclerView.b0 b0Var) {
        if (T() == 0) {
            return 0;
        }
        b2();
        return q.c(b0Var, this.J, f2(!this.O, true), e2(!this.O, true), this, this.O);
    }

    private View d2() {
        return j2(0, T());
    }

    private View h2() {
        return j2(T() - 1, -1);
    }

    private View l2() {
        return this.M ? d2() : h2();
    }

    private View m2() {
        return this.M ? h2() : d2();
    }

    private int o2(int i10, RecyclerView.w wVar, RecyclerView.b0 b0Var, boolean z10) {
        int i11;
        int i12 = this.J.i() - i10;
        if (i12 <= 0) {
            return 0;
        }
        int i13 = -F2(-i12, wVar, b0Var);
        int i14 = i10 + i13;
        if (!z10 || (i11 = this.J.i() - i14) <= 0) {
            return i13;
        }
        this.J.r(i11);
        return i11 + i13;
    }

    private int p2(int i10, RecyclerView.w wVar, RecyclerView.b0 b0Var, boolean z10) {
        int m10;
        int m11 = i10 - this.J.m();
        if (m11 <= 0) {
            return 0;
        }
        int i11 = -F2(m11, wVar, b0Var);
        int i12 = i10 + i11;
        if (!z10 || (m10 = i12 - this.J.m()) <= 0) {
            return i11;
        }
        this.J.r(-m10);
        return i11 - m10;
    }

    private View q2() {
        return S(this.M ? 0 : T() - 1);
    }

    private View r2() {
        return S(this.M ? T() - 1 : 0);
    }

    private void x2(RecyclerView.w wVar, RecyclerView.b0 b0Var, int i10, int i11) {
        if (!b0Var.g() || T() == 0 || b0Var.e() || !T1()) {
            return;
        }
        List k10 = wVar.k();
        int size = k10.size();
        int n02 = n0(S(0));
        int i12 = 0;
        int i13 = 0;
        for (int i14 = 0; i14 < size; i14++) {
            RecyclerView.e0 e0Var = (RecyclerView.e0) k10.get(i14);
            if (!e0Var.x()) {
                if (((e0Var.o() < n02) != this.M ? (char) 65535 : (char) 1) == 65535) {
                    i12 += this.J.e(e0Var.f5192p);
                } else {
                    i13 += this.J.e(e0Var.f5192p);
                }
            }
        }
        this.I.f5107l = k10;
        if (i12 > 0) {
            P2(n0(r2()), i10);
            c cVar = this.I;
            cVar.f5103h = i12;
            cVar.f5098c = 0;
            cVar.a();
            c2(wVar, this.I, b0Var, false);
        }
        if (i13 > 0) {
            N2(n0(q2()), i11);
            c cVar2 = this.I;
            cVar2.f5103h = i13;
            cVar2.f5098c = 0;
            cVar2.a();
            c2(wVar, this.I, b0Var, false);
        }
        this.I.f5107l = null;
    }

    private void z2(RecyclerView.w wVar, c cVar) {
        if (!cVar.f5096a || cVar.f5108m) {
            return;
        }
        int i10 = cVar.f5102g;
        int i11 = cVar.f5104i;
        if (cVar.f5101f == -1) {
            B2(wVar, i10, i11);
        } else {
            C2(wVar, i10, i11);
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public int A(RecyclerView.b0 b0Var) {
        return W1(b0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public int B(RecyclerView.b0 b0Var) {
        return X1(b0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public int C(RecyclerView.b0 b0Var) {
        return Y1(b0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public int D(RecyclerView.b0 b0Var) {
        return W1(b0Var);
    }

    boolean D2() {
        return this.J.k() == 0 && this.J.h() == 0;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public int E(RecyclerView.b0 b0Var) {
        return X1(b0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public int E1(int i10, RecyclerView.w wVar, RecyclerView.b0 b0Var) {
        if (this.H == 1) {
            return 0;
        }
        return F2(i10, wVar, b0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public int F(RecyclerView.b0 b0Var) {
        return Y1(b0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void F1(int i10) {
        this.P = i10;
        this.Q = Integer.MIN_VALUE;
        d dVar = this.S;
        if (dVar != null) {
            dVar.b();
        }
        B1();
    }

    int F2(int i10, RecyclerView.w wVar, RecyclerView.b0 b0Var) {
        if (T() == 0 || i10 == 0) {
            return 0;
        }
        b2();
        this.I.f5096a = true;
        int i11 = i10 > 0 ? 1 : -1;
        int abs = Math.abs(i10);
        M2(i11, abs, true, b0Var);
        c cVar = this.I;
        int c22 = cVar.f5102g + c2(wVar, cVar, b0Var, false);
        if (c22 < 0) {
            return 0;
        }
        if (abs > c22) {
            i10 = i11 * c22;
        }
        this.J.r(-i10);
        this.I.f5106k = i10;
        return i10;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public int G1(int i10, RecyclerView.w wVar, RecyclerView.b0 b0Var) {
        if (this.H == 0) {
            return 0;
        }
        return F2(i10, wVar, b0Var);
    }

    public void G2(int i10) {
        if (i10 != 0 && i10 != 1) {
            throw new IllegalArgumentException("invalid orientation:" + i10);
        }
        q(null);
        if (i10 != this.H || this.J == null) {
            n b10 = n.b(this, i10);
            this.J = b10;
            this.T.f5087a = b10;
            this.H = i10;
            B1();
        }
    }

    public void H2(boolean z10) {
        q(null);
        if (z10 == this.L) {
            return;
        }
        this.L = z10;
        B1();
    }

    public void I2(boolean z10) {
        q(null);
        if (this.N == z10) {
            return;
        }
        this.N = z10;
        B1();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public View M(int i10) {
        int T = T();
        if (T == 0) {
            return null;
        }
        int n02 = i10 - n0(S(0));
        if (n02 >= 0 && n02 < T) {
            View S = S(n02);
            if (n0(S) == i10) {
                return S;
            }
        }
        return super.M(i10);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public RecyclerView.q N() {
        return new RecyclerView.q(-2, -2);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    boolean O1() {
        return (h0() == 1073741824 || v0() == 1073741824 || !w0()) ? false : true;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void P0(RecyclerView recyclerView, RecyclerView.w wVar) {
        super.P0(recyclerView, wVar);
        if (this.R) {
            s1(wVar);
            wVar.c();
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public View Q0(View view, int i10, RecyclerView.w wVar, RecyclerView.b0 b0Var) {
        int Z1;
        E2();
        if (T() == 0 || (Z1 = Z1(i10)) == Integer.MIN_VALUE) {
            return null;
        }
        b2();
        M2(Z1, (int) (this.J.n() * 0.33333334f), false, b0Var);
        c cVar = this.I;
        cVar.f5102g = Integer.MIN_VALUE;
        cVar.f5096a = false;
        c2(wVar, cVar, b0Var, true);
        View m22 = Z1 == -1 ? m2() : l2();
        View r22 = Z1 == -1 ? r2() : q2();
        if (!r22.hasFocusable()) {
            return m22;
        }
        if (m22 == null) {
            return null;
        }
        return r22;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void Q1(RecyclerView recyclerView, RecyclerView.b0 b0Var, int i10) {
        k kVar = new k(recyclerView.getContext());
        kVar.p(i10);
        R1(kVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void R0(AccessibilityEvent accessibilityEvent) {
        super.R0(accessibilityEvent);
        if (T() > 0) {
            accessibilityEvent.setFromIndex(g2());
            accessibilityEvent.setToIndex(i2());
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public boolean T1() {
        return this.S == null && this.K == this.N;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void U1(RecyclerView.b0 b0Var, int[] iArr) {
        int i10;
        int s22 = s2(b0Var);
        if (this.I.f5101f == -1) {
            i10 = 0;
        } else {
            i10 = s22;
            s22 = 0;
        }
        iArr[0] = s22;
        iArr[1] = i10;
    }

    void V1(RecyclerView.b0 b0Var, c cVar, RecyclerView.p.c cVar2) {
        int i10 = cVar.f5099d;
        if (i10 < 0 || i10 >= b0Var.b()) {
            return;
        }
        cVar2.a(i10, Math.max(0, cVar.f5102g));
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int Z1(int i10) {
        return i10 != 1 ? i10 != 2 ? i10 != 17 ? i10 != 33 ? i10 != 66 ? (i10 == 130 && this.H == 1) ? 1 : Integer.MIN_VALUE : this.H == 0 ? 1 : Integer.MIN_VALUE : this.H == 1 ? -1 : Integer.MIN_VALUE : this.H == 0 ? -1 : Integer.MIN_VALUE : (this.H != 1 && u2()) ? -1 : 1 : (this.H != 1 && u2()) ? 1 : -1;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.a0.b
    public PointF a(int i10) {
        if (T() == 0) {
            return null;
        }
        int i11 = (i10 < n0(S(0))) != this.M ? -1 : 1;
        return this.H == 0 ? new PointF(i11, BitmapDescriptorFactory.HUE_RED) : new PointF(BitmapDescriptorFactory.HUE_RED, i11);
    }

    c a2() {
        return new c();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void b2() {
        if (this.I == null) {
            this.I = a2();
        }
    }

    int c2(RecyclerView.w wVar, c cVar, RecyclerView.b0 b0Var, boolean z10) {
        int i10 = cVar.f5098c;
        int i11 = cVar.f5102g;
        if (i11 != Integer.MIN_VALUE) {
            if (i10 < 0) {
                cVar.f5102g = i11 + i10;
            }
            z2(wVar, cVar);
        }
        int i12 = cVar.f5098c + cVar.f5103h;
        b bVar = this.U;
        while (true) {
            if ((!cVar.f5108m && i12 <= 0) || !cVar.c(b0Var)) {
                break;
            }
            bVar.a();
            w2(wVar, b0Var, cVar, bVar);
            if (!bVar.f5093b) {
                cVar.f5097b += bVar.f5092a * cVar.f5101f;
                if (!bVar.f5094c || cVar.f5107l != null || !b0Var.e()) {
                    int i13 = cVar.f5098c;
                    int i14 = bVar.f5092a;
                    cVar.f5098c = i13 - i14;
                    i12 -= i14;
                }
                int i15 = cVar.f5102g;
                if (i15 != Integer.MIN_VALUE) {
                    int i16 = i15 + bVar.f5092a;
                    cVar.f5102g = i16;
                    int i17 = cVar.f5098c;
                    if (i17 < 0) {
                        cVar.f5102g = i16 + i17;
                    }
                    z2(wVar, cVar);
                }
                if (z10 && bVar.f5095d) {
                    break;
                }
            } else {
                break;
            }
        }
        return i10 - cVar.f5098c;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void e1(RecyclerView.w wVar, RecyclerView.b0 b0Var) {
        int i10;
        int i11;
        int i12;
        int i13;
        int o22;
        int i14;
        View M;
        int g10;
        int i15;
        int i16 = -1;
        if (!(this.S == null && this.P == -1) && b0Var.b() == 0) {
            s1(wVar);
            return;
        }
        d dVar = this.S;
        if (dVar != null && dVar.a()) {
            this.P = this.S.f5109p;
        }
        b2();
        this.I.f5096a = false;
        E2();
        View f02 = f0();
        a aVar = this.T;
        if (!aVar.f5091e || this.P != -1 || this.S != null) {
            aVar.e();
            a aVar2 = this.T;
            aVar2.f5090d = this.M ^ this.N;
            L2(wVar, b0Var, aVar2);
            this.T.f5091e = true;
        } else if (f02 != null && (this.J.g(f02) >= this.J.i() || this.J.d(f02) <= this.J.m())) {
            this.T.c(f02, n0(f02));
        }
        c cVar = this.I;
        cVar.f5101f = cVar.f5106k >= 0 ? 1 : -1;
        int[] iArr = this.W;
        iArr[0] = 0;
        iArr[1] = 0;
        U1(b0Var, iArr);
        int max = Math.max(0, this.W[0]) + this.J.m();
        int max2 = Math.max(0, this.W[1]) + this.J.j();
        if (b0Var.e() && (i14 = this.P) != -1 && this.Q != Integer.MIN_VALUE && (M = M(i14)) != null) {
            if (this.M) {
                i15 = this.J.i() - this.J.d(M);
                g10 = this.Q;
            } else {
                g10 = this.J.g(M) - this.J.m();
                i15 = this.Q;
            }
            int i17 = i15 - g10;
            if (i17 > 0) {
                max += i17;
            } else {
                max2 -= i17;
            }
        }
        a aVar3 = this.T;
        if (!aVar3.f5090d ? !this.M : this.M) {
            i16 = 1;
        }
        y2(wVar, b0Var, aVar3, i16);
        G(wVar);
        this.I.f5108m = D2();
        this.I.f5105j = b0Var.e();
        this.I.f5104i = 0;
        a aVar4 = this.T;
        if (aVar4.f5090d) {
            Q2(aVar4);
            c cVar2 = this.I;
            cVar2.f5103h = max;
            c2(wVar, cVar2, b0Var, false);
            c cVar3 = this.I;
            i11 = cVar3.f5097b;
            int i18 = cVar3.f5099d;
            int i19 = cVar3.f5098c;
            if (i19 > 0) {
                max2 += i19;
            }
            O2(this.T);
            c cVar4 = this.I;
            cVar4.f5103h = max2;
            cVar4.f5099d += cVar4.f5100e;
            c2(wVar, cVar4, b0Var, false);
            c cVar5 = this.I;
            i10 = cVar5.f5097b;
            int i20 = cVar5.f5098c;
            if (i20 > 0) {
                P2(i18, i11);
                c cVar6 = this.I;
                cVar6.f5103h = i20;
                c2(wVar, cVar6, b0Var, false);
                i11 = this.I.f5097b;
            }
        } else {
            O2(aVar4);
            c cVar7 = this.I;
            cVar7.f5103h = max2;
            c2(wVar, cVar7, b0Var, false);
            c cVar8 = this.I;
            i10 = cVar8.f5097b;
            int i21 = cVar8.f5099d;
            int i22 = cVar8.f5098c;
            if (i22 > 0) {
                max += i22;
            }
            Q2(this.T);
            c cVar9 = this.I;
            cVar9.f5103h = max;
            cVar9.f5099d += cVar9.f5100e;
            c2(wVar, cVar9, b0Var, false);
            c cVar10 = this.I;
            i11 = cVar10.f5097b;
            int i23 = cVar10.f5098c;
            if (i23 > 0) {
                N2(i21, i10);
                c cVar11 = this.I;
                cVar11.f5103h = i23;
                c2(wVar, cVar11, b0Var, false);
                i10 = this.I.f5097b;
            }
        }
        if (T() > 0) {
            if (this.M ^ this.N) {
                int o23 = o2(i10, wVar, b0Var, true);
                i12 = i11 + o23;
                i13 = i10 + o23;
                o22 = p2(i12, wVar, b0Var, false);
            } else {
                int p22 = p2(i11, wVar, b0Var, true);
                i12 = i11 + p22;
                i13 = i10 + p22;
                o22 = o2(i13, wVar, b0Var, false);
            }
            i11 = i12 + o22;
            i10 = i13 + o22;
        }
        x2(wVar, b0Var, i11, i10);
        if (b0Var.e()) {
            this.T.e();
        } else {
            this.J.s();
        }
        this.K = this.N;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public View e2(boolean z10, boolean z11) {
        return this.M ? k2(0, T(), z10, z11) : k2(T() - 1, -1, z10, z11);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void f1(RecyclerView.b0 b0Var) {
        super.f1(b0Var);
        this.S = null;
        this.P = -1;
        this.Q = Integer.MIN_VALUE;
        this.T.e();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public View f2(boolean z10, boolean z11) {
        return this.M ? k2(T() - 1, -1, z10, z11) : k2(0, T(), z10, z11);
    }

    public int g2() {
        View k22 = k2(0, T(), false, true);
        if (k22 == null) {
            return -1;
        }
        return n0(k22);
    }

    public int i2() {
        View k22 = k2(T() - 1, -1, false, true);
        if (k22 == null) {
            return -1;
        }
        return n0(k22);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void j1(Parcelable parcelable) {
        if (parcelable instanceof d) {
            d dVar = (d) parcelable;
            this.S = dVar;
            if (this.P != -1) {
                dVar.b();
            }
            B1();
        }
    }

    View j2(int i10, int i11) {
        int i12;
        int i13;
        b2();
        if ((i11 > i10 ? (char) 1 : i11 < i10 ? (char) 65535 : (char) 0) == 0) {
            return S(i10);
        }
        if (this.J.g(S(i10)) < this.J.m()) {
            i12 = 16644;
            i13 = 16388;
        } else {
            i12 = 4161;
            i13 = 4097;
        }
        return this.H == 0 ? this.f5223t.a(i10, i11, i12, i13) : this.f5224u.a(i10, i11, i12, i13);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public Parcelable k1() {
        if (this.S != null) {
            return new d(this.S);
        }
        d dVar = new d();
        if (T() > 0) {
            b2();
            boolean z10 = this.K ^ this.M;
            dVar.f5111r = z10;
            if (z10) {
                View q22 = q2();
                dVar.f5110q = this.J.i() - this.J.d(q22);
                dVar.f5109p = n0(q22);
            } else {
                View r22 = r2();
                dVar.f5109p = n0(r22);
                dVar.f5110q = this.J.g(r22) - this.J.m();
            }
        } else {
            dVar.b();
        }
        return dVar;
    }

    View k2(int i10, int i11, boolean z10, boolean z11) {
        b2();
        int i12 = z10 ? 24579 : 320;
        int i13 = z11 ? 320 : 0;
        return this.H == 0 ? this.f5223t.a(i10, i11, i12, i13) : this.f5224u.a(i10, i11, i12, i13);
    }

    View n2(RecyclerView.w wVar, RecyclerView.b0 b0Var, boolean z10, boolean z11) {
        int i10;
        int i11;
        int i12;
        b2();
        int T = T();
        if (z11) {
            i11 = T() - 1;
            i10 = -1;
            i12 = -1;
        } else {
            i10 = T;
            i11 = 0;
            i12 = 1;
        }
        int b10 = b0Var.b();
        int m10 = this.J.m();
        int i13 = this.J.i();
        View view = null;
        View view2 = null;
        View view3 = null;
        while (i11 != i10) {
            View S = S(i11);
            int n02 = n0(S);
            int g10 = this.J.g(S);
            int d10 = this.J.d(S);
            if (n02 >= 0 && n02 < b10) {
                if (!((RecyclerView.q) S.getLayoutParams()).c()) {
                    boolean z12 = d10 <= m10 && g10 < m10;
                    boolean z13 = g10 >= i13 && d10 > i13;
                    if (!z12 && !z13) {
                        return S;
                    }
                    if (z10) {
                        if (!z13) {
                            if (view != null) {
                            }
                            view = S;
                        }
                        view2 = S;
                    } else {
                        if (!z12) {
                            if (view != null) {
                            }
                            view = S;
                        }
                        view2 = S;
                    }
                } else if (view3 == null) {
                    view3 = S;
                }
            }
            i11 += i12;
        }
        return view != null ? view : view2 != null ? view2 : view3;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void q(String str) {
        if (this.S == null) {
            super.q(str);
        }
    }

    protected int s2(RecyclerView.b0 b0Var) {
        if (b0Var.d()) {
            return this.J.n();
        }
        return 0;
    }

    public int t2() {
        return this.H;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public boolean u() {
        return this.H == 0;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public boolean u2() {
        return j0() == 1;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public boolean v() {
        return this.H == 1;
    }

    public boolean v2() {
        return this.O;
    }

    void w2(RecyclerView.w wVar, RecyclerView.b0 b0Var, c cVar, b bVar) {
        int i10;
        int i11;
        int i12;
        int i13;
        int f10;
        View d10 = cVar.d(wVar);
        if (d10 == null) {
            bVar.f5093b = true;
            return;
        }
        RecyclerView.q qVar = (RecyclerView.q) d10.getLayoutParams();
        if (cVar.f5107l == null) {
            if (this.M == (cVar.f5101f == -1)) {
                n(d10);
            } else {
                o(d10, 0);
            }
        } else {
            if (this.M == (cVar.f5101f == -1)) {
                l(d10);
            } else {
                m(d10, 0);
            }
        }
        H0(d10, 0, 0);
        bVar.f5092a = this.J.e(d10);
        if (this.H == 1) {
            if (u2()) {
                f10 = u0() - getPaddingRight();
                i13 = f10 - this.J.f(d10);
            } else {
                i13 = getPaddingLeft();
                f10 = this.J.f(d10) + i13;
            }
            if (cVar.f5101f == -1) {
                int i14 = cVar.f5097b;
                i12 = i14;
                i11 = f10;
                i10 = i14 - bVar.f5092a;
            } else {
                int i15 = cVar.f5097b;
                i10 = i15;
                i11 = f10;
                i12 = bVar.f5092a + i15;
            }
        } else {
            int paddingTop = getPaddingTop();
            int f11 = this.J.f(d10) + paddingTop;
            if (cVar.f5101f == -1) {
                int i16 = cVar.f5097b;
                i11 = i16;
                i10 = paddingTop;
                i12 = f11;
                i13 = i16 - bVar.f5092a;
            } else {
                int i17 = cVar.f5097b;
                i10 = paddingTop;
                i11 = bVar.f5092a + i17;
                i12 = f11;
                i13 = i17;
            }
        }
        G0(d10, i13, i10, i11, i12);
        if (qVar.c() || qVar.b()) {
            bVar.f5094c = true;
        }
        bVar.f5095d = d10.hasFocusable();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void y(int i10, int i11, RecyclerView.b0 b0Var, RecyclerView.p.c cVar) {
        if (this.H != 0) {
            i10 = i11;
        }
        if (T() == 0 || i10 == 0) {
            return;
        }
        b2();
        M2(i10 > 0 ? 1 : -1, Math.abs(i10), true, b0Var);
        V1(b0Var, this.I, cVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public boolean y0() {
        return true;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void y2(RecyclerView.w wVar, RecyclerView.b0 b0Var, a aVar, int i10) {
    }

    @Override // androidx.recyclerview.widget.RecyclerView.p
    public void z(int i10, RecyclerView.p.c cVar) {
        boolean z10;
        int i11;
        d dVar = this.S;
        if (dVar == null || !dVar.a()) {
            E2();
            z10 = this.M;
            i11 = this.P;
            if (i11 == -1) {
                i11 = z10 ? i10 - 1 : 0;
            }
        } else {
            d dVar2 = this.S;
            z10 = dVar2.f5111r;
            i11 = dVar2.f5109p;
        }
        int i12 = z10 ? -1 : 1;
        for (int i13 = 0; i13 < this.V && i11 >= 0 && i11 < i10; i13++) {
            cVar.a(i11, 0);
            i11 += i12;
        }
    }

    public LinearLayoutManager(Context context, int i10, boolean z10) {
        this.H = 1;
        this.L = false;
        this.M = false;
        this.N = false;
        this.O = true;
        this.P = -1;
        this.Q = Integer.MIN_VALUE;
        this.S = null;
        this.T = new a();
        this.U = new b();
        this.V = 2;
        this.W = new int[2];
        G2(i10);
        H2(z10);
    }

    public LinearLayoutManager(Context context, AttributeSet attributeSet, int i10, int i11) {
        this.H = 1;
        this.L = false;
        this.M = false;
        this.N = false;
        this.O = true;
        this.P = -1;
        this.Q = Integer.MIN_VALUE;
        this.S = null;
        this.T = new a();
        this.U = new b();
        this.V = 2;
        this.W = new int[2];
        RecyclerView.p.d o02 = RecyclerView.p.o0(context, attributeSet, i10, i11);
        G2(o02.f5232a);
        H2(o02.f5234c);
        I2(o02.f5235d);
    }
}
