package androidx.recyclerview.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
    private BitSet B;
    private boolean G;
    private boolean H;
    private e I;
    private int J;
    private int[] O;
    f[] t;
    h u;
    h v;
    private int w;
    private int x;
    private final androidx.recyclerview.widget.f y;
    private int s = -1;
    boolean z = false;
    boolean A = false;
    int C = -1;
    int D = Integer.MIN_VALUE;
    d E = new d();
    private int F = 2;
    private final Rect K = new Rect();
    private final b L = new b();
    private boolean M = false;
    private boolean N = true;
    private final Runnable P = new a();

    class a implements Runnable {
        a() {
        }

        @Override // java.lang.Runnable
        public void run() {
            StaggeredGridLayoutManager.this.M1();
        }
    }

    class b {
        int a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        int f1055b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        boolean f1056c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        boolean f1057d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        boolean f1058e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        int[] f1059f;

        b() {
            c();
        }

        void a() {
            this.f1055b = this.f1056c ? StaggeredGridLayoutManager.this.u.i() : StaggeredGridLayoutManager.this.u.m();
        }

        void b(int i2) {
            if (this.f1056c) {
                this.f1055b = StaggeredGridLayoutManager.this.u.i() - i2;
            } else {
                this.f1055b = StaggeredGridLayoutManager.this.u.m() + i2;
            }
        }

        void c() {
            this.a = -1;
            this.f1055b = Integer.MIN_VALUE;
            this.f1056c = false;
            this.f1057d = false;
            this.f1058e = false;
            int[] iArr = this.f1059f;
            if (iArr != null) {
                Arrays.fill(iArr, -1);
            }
        }

        void d(f[] fVarArr) {
            int length = fVarArr.length;
            int[] iArr = this.f1059f;
            if (iArr == null || iArr.length < length) {
                this.f1059f = new int[StaggeredGridLayoutManager.this.t.length];
            }
            for (int i2 = 0; i2 < length; i2++) {
                this.f1059f[i2] = fVarArr[i2].p(Integer.MIN_VALUE);
            }
        }
    }

    public static class c extends RecyclerView.p {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        f f1061e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        boolean f1062f;

        public c(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
        }

        public boolean e() {
            return this.f1062f;
        }

        public c(int i2, int i3) {
            super(i2, i3);
        }

        public c(ViewGroup.MarginLayoutParams marginLayoutParams) {
            super(marginLayoutParams);
        }

        public c(ViewGroup.LayoutParams layoutParams) {
            super(layoutParams);
        }
    }

    @SuppressLint({"BanParcelableUsage"})
    public static class e implements Parcelable {
        public static final Parcelable.Creator<e> CREATOR = new a();

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        int f1068b;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        int f1069f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        int f1070g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        int[] f1071h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        int f1072i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        int[] f1073j;

        /* JADX INFO: renamed from: k, reason: collision with root package name */
        List<d.a> f1074k;
        boolean l;
        boolean m;
        boolean n;

        class a implements Parcelable.Creator<e> {
            a() {
            }

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

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

        public e() {
        }

        void a() {
            this.f1071h = null;
            this.f1070g = 0;
            this.f1068b = -1;
            this.f1069f = -1;
        }

        void b() {
            this.f1071h = null;
            this.f1070g = 0;
            this.f1072i = 0;
            this.f1073j = null;
            this.f1074k = null;
        }

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

        @Override // android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i2) {
            parcel.writeInt(this.f1068b);
            parcel.writeInt(this.f1069f);
            parcel.writeInt(this.f1070g);
            if (this.f1070g > 0) {
                parcel.writeIntArray(this.f1071h);
            }
            parcel.writeInt(this.f1072i);
            if (this.f1072i > 0) {
                parcel.writeIntArray(this.f1073j);
            }
            parcel.writeInt(this.l ? 1 : 0);
            parcel.writeInt(this.m ? 1 : 0);
            parcel.writeInt(this.n ? 1 : 0);
            parcel.writeList(this.f1074k);
        }

        e(Parcel parcel) {
            this.f1068b = parcel.readInt();
            this.f1069f = parcel.readInt();
            int i2 = parcel.readInt();
            this.f1070g = i2;
            if (i2 > 0) {
                int[] iArr = new int[i2];
                this.f1071h = iArr;
                parcel.readIntArray(iArr);
            }
            int i3 = parcel.readInt();
            this.f1072i = i3;
            if (i3 > 0) {
                int[] iArr2 = new int[i3];
                this.f1073j = iArr2;
                parcel.readIntArray(iArr2);
            }
            this.l = parcel.readInt() == 1;
            this.m = parcel.readInt() == 1;
            this.n = parcel.readInt() == 1;
            this.f1074k = parcel.readArrayList(d.a.class.getClassLoader());
        }

        public e(e eVar) {
            this.f1070g = eVar.f1070g;
            this.f1068b = eVar.f1068b;
            this.f1069f = eVar.f1069f;
            this.f1071h = eVar.f1071h;
            this.f1072i = eVar.f1072i;
            this.f1073j = eVar.f1073j;
            this.l = eVar.l;
            this.m = eVar.m;
            this.n = eVar.n;
            this.f1074k = eVar.f1074k;
        }
    }

    class f {
        ArrayList<View> a = new ArrayList<>();

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        int f1075b = Integer.MIN_VALUE;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        int f1076c = Integer.MIN_VALUE;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        int f1077d = 0;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        final int f1078e;

        f(int i2) {
            this.f1078e = i2;
        }

        void a(View view) {
            c cVarN = n(view);
            cVarN.f1061e = this;
            this.a.add(view);
            this.f1076c = Integer.MIN_VALUE;
            if (this.a.size() == 1) {
                this.f1075b = Integer.MIN_VALUE;
            }
            if (cVarN.c() || cVarN.b()) {
                this.f1077d += StaggeredGridLayoutManager.this.u.e(view);
            }
        }

        void b(boolean z, int i2) {
            int iL = z ? l(Integer.MIN_VALUE) : p(Integer.MIN_VALUE);
            e();
            if (iL == Integer.MIN_VALUE) {
                return;
            }
            if (!z || iL >= StaggeredGridLayoutManager.this.u.i()) {
                if (z || iL <= StaggeredGridLayoutManager.this.u.m()) {
                    if (i2 != Integer.MIN_VALUE) {
                        iL += i2;
                    }
                    this.f1076c = iL;
                    this.f1075b = iL;
                }
            }
        }

        void c() {
            d.a aVarF;
            ArrayList<View> arrayList = this.a;
            View view = arrayList.get(arrayList.size() - 1);
            c cVarN = n(view);
            this.f1076c = StaggeredGridLayoutManager.this.u.d(view);
            if (cVarN.f1062f && (aVarF = StaggeredGridLayoutManager.this.E.f(cVarN.a())) != null && aVarF.f1065f == 1) {
                this.f1076c += aVarF.a(this.f1078e);
            }
        }

        void d() {
            d.a aVarF;
            View view = this.a.get(0);
            c cVarN = n(view);
            this.f1075b = StaggeredGridLayoutManager.this.u.g(view);
            if (cVarN.f1062f && (aVarF = StaggeredGridLayoutManager.this.E.f(cVarN.a())) != null && aVarF.f1065f == -1) {
                this.f1075b -= aVarF.a(this.f1078e);
            }
        }

        void e() {
            this.a.clear();
            q();
            this.f1077d = 0;
        }

        public int f() {
            return StaggeredGridLayoutManager.this.z ? i(this.a.size() - 1, -1, true) : i(0, this.a.size(), true);
        }

        public int g() {
            return StaggeredGridLayoutManager.this.z ? i(0, this.a.size(), true) : i(this.a.size() - 1, -1, true);
        }

        int h(int i2, int i3, boolean z, boolean z2, boolean z3) {
            int iM = StaggeredGridLayoutManager.this.u.m();
            int i4 = StaggeredGridLayoutManager.this.u.i();
            int i5 = i3 > i2 ? 1 : -1;
            while (i2 != i3) {
                View view = this.a.get(i2);
                int iG = StaggeredGridLayoutManager.this.u.g(view);
                int iD = StaggeredGridLayoutManager.this.u.d(view);
                boolean z4 = false;
                boolean z5 = !z3 ? iG >= i4 : iG > i4;
                if (!z3 ? iD > iM : iD >= iM) {
                    z4 = true;
                }
                if (z5 && z4) {
                    if (z && z2) {
                        if (iG >= iM && iD <= i4) {
                            return StaggeredGridLayoutManager.this.f0(view);
                        }
                    } else {
                        if (z2) {
                            return StaggeredGridLayoutManager.this.f0(view);
                        }
                        if (iG < iM || iD > i4) {
                            return StaggeredGridLayoutManager.this.f0(view);
                        }
                    }
                }
                i2 += i5;
            }
            return -1;
        }

        int i(int i2, int i3, boolean z) {
            return h(i2, i3, false, false, z);
        }

        public int j() {
            return this.f1077d;
        }

        int k() {
            int i2 = this.f1076c;
            if (i2 != Integer.MIN_VALUE) {
                return i2;
            }
            c();
            return this.f1076c;
        }

        int l(int i2) {
            int i3 = this.f1076c;
            if (i3 != Integer.MIN_VALUE) {
                return i3;
            }
            if (this.a.size() == 0) {
                return i2;
            }
            c();
            return this.f1076c;
        }

        public View m(int i2, int i3) {
            View view = null;
            if (i3 != -1) {
                int size = this.a.size() - 1;
                while (size >= 0) {
                    View view2 = this.a.get(size);
                    StaggeredGridLayoutManager staggeredGridLayoutManager = StaggeredGridLayoutManager.this;
                    if (staggeredGridLayoutManager.z && staggeredGridLayoutManager.f0(view2) >= i2) {
                        break;
                    }
                    StaggeredGridLayoutManager staggeredGridLayoutManager2 = StaggeredGridLayoutManager.this;
                    if ((!staggeredGridLayoutManager2.z && staggeredGridLayoutManager2.f0(view2) <= i2) || !view2.hasFocusable()) {
                        break;
                    }
                    size--;
                    view = view2;
                }
            } else {
                int size2 = this.a.size();
                int i4 = 0;
                while (i4 < size2) {
                    View view3 = this.a.get(i4);
                    StaggeredGridLayoutManager staggeredGridLayoutManager3 = StaggeredGridLayoutManager.this;
                    if (staggeredGridLayoutManager3.z && staggeredGridLayoutManager3.f0(view3) <= i2) {
                        break;
                    }
                    StaggeredGridLayoutManager staggeredGridLayoutManager4 = StaggeredGridLayoutManager.this;
                    if ((!staggeredGridLayoutManager4.z && staggeredGridLayoutManager4.f0(view3) >= i2) || !view3.hasFocusable()) {
                        break;
                    }
                    i4++;
                    view = view3;
                }
            }
            return view;
        }

        c n(View view) {
            return (c) view.getLayoutParams();
        }

        int o() {
            int i2 = this.f1075b;
            if (i2 != Integer.MIN_VALUE) {
                return i2;
            }
            d();
            return this.f1075b;
        }

        int p(int i2) {
            int i3 = this.f1075b;
            if (i3 != Integer.MIN_VALUE) {
                return i3;
            }
            if (this.a.size() == 0) {
                return i2;
            }
            d();
            return this.f1075b;
        }

        void q() {
            this.f1075b = Integer.MIN_VALUE;
            this.f1076c = Integer.MIN_VALUE;
        }

        void r(int i2) {
            int i3 = this.f1075b;
            if (i3 != Integer.MIN_VALUE) {
                this.f1075b = i3 + i2;
            }
            int i4 = this.f1076c;
            if (i4 != Integer.MIN_VALUE) {
                this.f1076c = i4 + i2;
            }
        }

        void s() {
            int size = this.a.size();
            View viewRemove = this.a.remove(size - 1);
            c cVarN = n(viewRemove);
            cVarN.f1061e = null;
            if (cVarN.c() || cVarN.b()) {
                this.f1077d -= StaggeredGridLayoutManager.this.u.e(viewRemove);
            }
            if (size == 1) {
                this.f1075b = Integer.MIN_VALUE;
            }
            this.f1076c = Integer.MIN_VALUE;
        }

        void t() {
            View viewRemove = this.a.remove(0);
            c cVarN = n(viewRemove);
            cVarN.f1061e = null;
            if (this.a.size() == 0) {
                this.f1076c = Integer.MIN_VALUE;
            }
            if (cVarN.c() || cVarN.b()) {
                this.f1077d -= StaggeredGridLayoutManager.this.u.e(viewRemove);
            }
            this.f1075b = Integer.MIN_VALUE;
        }

        void u(View view) {
            c cVarN = n(view);
            cVarN.f1061e = this;
            this.a.add(0, view);
            this.f1075b = Integer.MIN_VALUE;
            if (this.a.size() == 1) {
                this.f1076c = Integer.MIN_VALUE;
            }
            if (cVarN.c() || cVarN.b()) {
                this.f1077d += StaggeredGridLayoutManager.this.u.e(view);
            }
        }

        void v(int i2) {
            this.f1075b = i2;
            this.f1076c = i2;
        }
    }

    public StaggeredGridLayoutManager(Context context, AttributeSet attributeSet, int i2, int i3) {
        RecyclerView.LayoutManager.Properties propertiesG0 = RecyclerView.LayoutManager.g0(context, attributeSet, i2, i3);
        B2(propertiesG0.a);
        D2(propertiesG0.f1010b);
        C2(propertiesG0.f1011c);
        this.y = new androidx.recyclerview.widget.f();
        U1();
    }

    private void A2(int i2) {
        androidx.recyclerview.widget.f fVar = this.y;
        fVar.f1157e = i2;
        fVar.f1156d = this.A != (i2 == -1) ? -1 : 1;
    }

    private void E2(int i2, int i3) {
        for (int i4 = 0; i4 < this.s; i4++) {
            if (!this.t[i4].a.isEmpty()) {
                K2(this.t[i4], i2, i3);
            }
        }
    }

    private boolean F2(RecyclerView.a0 a0Var, b bVar) {
        bVar.a = this.G ? a2(a0Var.b()) : W1(a0Var.b());
        bVar.f1055b = Integer.MIN_VALUE;
        return true;
    }

    private void G1(View view) {
        for (int i2 = this.s - 1; i2 >= 0; i2--) {
            this.t[i2].a(view);
        }
    }

    private void H1(b bVar) {
        e eVar = this.I;
        int i2 = eVar.f1070g;
        if (i2 > 0) {
            if (i2 == this.s) {
                for (int i3 = 0; i3 < this.s; i3++) {
                    this.t[i3].e();
                    e eVar2 = this.I;
                    int i4 = eVar2.f1071h[i3];
                    if (i4 != Integer.MIN_VALUE) {
                        i4 += eVar2.m ? this.u.i() : this.u.m();
                    }
                    this.t[i3].v(i4);
                }
            } else {
                eVar.b();
                e eVar3 = this.I;
                eVar3.f1068b = eVar3.f1069f;
            }
        }
        e eVar4 = this.I;
        this.H = eVar4.n;
        C2(eVar4.l);
        y2();
        e eVar5 = this.I;
        int i5 = eVar5.f1068b;
        if (i5 != -1) {
            this.C = i5;
            bVar.f1056c = eVar5.m;
        } else {
            bVar.f1056c = this.A;
        }
        e eVar6 = this.I;
        if (eVar6.f1072i > 1) {
            d dVar = this.E;
            dVar.a = eVar6.f1073j;
            dVar.f1063b = eVar6.f1074k;
        }
    }

    private void I2(int i2, RecyclerView.a0 a0Var) {
        int iN;
        int iN2;
        int iC;
        androidx.recyclerview.widget.f fVar = this.y;
        boolean z = false;
        fVar.f1154b = 0;
        fVar.f1155c = i2;
        if (!v0() || (iC = a0Var.c()) == -1) {
            iN = 0;
            iN2 = 0;
        } else {
            if (this.A == (iC < i2)) {
                iN = this.u.n();
                iN2 = 0;
            } else {
                iN2 = this.u.n();
                iN = 0;
            }
        }
        if (L()) {
            this.y.f1158f = this.u.m() - iN2;
            this.y.f1159g = this.u.i() + iN;
        } else {
            this.y.f1159g = this.u.h() + iN;
            this.y.f1158f = -iN2;
        }
        androidx.recyclerview.widget.f fVar2 = this.y;
        fVar2.f1160h = false;
        fVar2.a = true;
        if (this.u.k() == 0 && this.u.h() == 0) {
            z = true;
        }
        fVar2.f1161i = z;
    }

    private void K1(View view, c cVar, androidx.recyclerview.widget.f fVar) {
        if (fVar.f1157e == 1) {
            if (cVar.f1062f) {
                G1(view);
                return;
            } else {
                cVar.f1061e.a(view);
                return;
            }
        }
        if (cVar.f1062f) {
            t2(view);
        } else {
            cVar.f1061e.u(view);
        }
    }

    private void K2(f fVar, int i2, int i3) {
        int iJ = fVar.j();
        if (i2 == -1) {
            if (fVar.o() + iJ <= i3) {
                this.B.set(fVar.f1078e, false);
            }
        } else if (fVar.k() - iJ >= i3) {
            this.B.set(fVar.f1078e, false);
        }
    }

    private int L1(int i2) {
        if (I() == 0) {
            return this.A ? 1 : -1;
        }
        return (i2 < d2()) != this.A ? -1 : 1;
    }

    private int L2(int i2, int i3, int i4) {
        if (i3 == 0 && i4 == 0) {
            return i2;
        }
        int mode = View.MeasureSpec.getMode(i2);
        return (mode == Integer.MIN_VALUE || mode == 1073741824) ? View.MeasureSpec.makeMeasureSpec(Math.max(0, (View.MeasureSpec.getSize(i2) - i3) - i4), mode) : i2;
    }

    private boolean N1(f fVar) {
        if (this.A) {
            if (fVar.k() < this.u.i()) {
                ArrayList<View> arrayList = fVar.a;
                return !fVar.n(arrayList.get(arrayList.size() - 1)).f1062f;
            }
        } else if (fVar.o() > this.u.m()) {
            return !fVar.n(fVar.a.get(0)).f1062f;
        }
        return false;
    }

    private int O1(RecyclerView.a0 a0Var) {
        if (I() == 0) {
            return 0;
        }
        return j.a(a0Var, this.u, Y1(!this.N), X1(!this.N), this, this.N);
    }

    private int P1(RecyclerView.a0 a0Var) {
        if (I() == 0) {
            return 0;
        }
        return j.b(a0Var, this.u, Y1(!this.N), X1(!this.N), this, this.N, this.A);
    }

    private int Q1(RecyclerView.a0 a0Var) {
        if (I() == 0) {
            return 0;
        }
        return j.c(a0Var, this.u, Y1(!this.N), X1(!this.N), this, this.N);
    }

    private int R1(int i2) {
        return i2 != 1 ? i2 != 2 ? i2 != 17 ? i2 != 33 ? i2 != 66 ? (i2 == 130 && this.w == 1) ? 1 : Integer.MIN_VALUE : this.w == 0 ? 1 : Integer.MIN_VALUE : this.w == 1 ? -1 : Integer.MIN_VALUE : this.w == 0 ? -1 : Integer.MIN_VALUE : (this.w != 1 && n2()) ? -1 : 1 : (this.w != 1 && n2()) ? 1 : -1;
    }

    private d.a S1(int i2) {
        d.a aVar = new d.a();
        aVar.f1066g = new int[this.s];
        for (int i3 = 0; i3 < this.s; i3++) {
            aVar.f1066g[i3] = i2 - this.t[i3].l(i2);
        }
        return aVar;
    }

    private d.a T1(int i2) {
        d.a aVar = new d.a();
        aVar.f1066g = new int[this.s];
        for (int i3 = 0; i3 < this.s; i3++) {
            aVar.f1066g[i3] = this.t[i3].p(i2) - i2;
        }
        return aVar;
    }

    private void U1() {
        this.u = h.b(this, this.w);
        this.v = h.b(this, 1 - this.w);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v14 */
    /* JADX WARN: Type inference failed for: r0v15 */
    /* JADX WARN: Type inference failed for: r0v44 */
    /* JADX WARN: Type inference failed for: r16v0, types: [androidx.recyclerview.widget.RecyclerView$LayoutManager, androidx.recyclerview.widget.StaggeredGridLayoutManager] */
    /* JADX WARN: Type inference failed for: r3v0 */
    /* JADX WARN: Type inference failed for: r3v1 */
    /* JADX WARN: Type inference failed for: r3v10 */
    /* JADX WARN: Type inference failed for: r3v2 */
    /* JADX WARN: Type inference failed for: r9v0 */
    /* JADX WARN: Type inference failed for: r9v1, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r9v7 */
    private int V1(RecyclerView.v vVar, androidx.recyclerview.widget.f fVar, RecyclerView.a0 a0Var) {
        f fVarJ2;
        int iE;
        int i2;
        int iE2;
        int iE3;
        boolean z;
        ?? r9 = 0;
        this.B.set(0, this.s, true);
        int i3 = this.y.f1161i ? fVar.f1157e == 1 ? Integer.MAX_VALUE : Integer.MIN_VALUE : fVar.f1157e == 1 ? fVar.f1159g + fVar.f1154b : fVar.f1158f - fVar.f1154b;
        E2(fVar.f1157e, i3);
        int i4 = this.A ? this.u.i() : this.u.m();
        ?? r0 = false;
        while (fVar.a(a0Var) && (this.y.f1161i || !this.B.isEmpty())) {
            View viewB = fVar.b(vVar);
            c cVar = (c) viewB.getLayoutParams();
            int iA = cVar.a();
            int iG = this.E.g(iA);
            ?? r3 = iG == -1 ? 1 : r9;
            if (r3 != 0) {
                fVarJ2 = cVar.f1062f ? this.t[r9] : j2(fVar);
                this.E.n(iA, fVarJ2);
            } else {
                fVarJ2 = this.t[iG];
            }
            f fVar2 = fVarJ2;
            cVar.f1061e = fVar2;
            if (fVar.f1157e == 1) {
                c(viewB);
            } else {
                d(viewB, r9);
            }
            p2(viewB, cVar, r9);
            if (fVar.f1157e == 1) {
                int iF2 = cVar.f1062f ? f2(i4) : fVar2.l(i4);
                int iE4 = this.u.e(viewB) + iF2;
                if (r3 != 0 && cVar.f1062f) {
                    d.a aVarS1 = S1(iF2);
                    aVarS1.f1065f = -1;
                    aVarS1.f1064b = iA;
                    this.E.a(aVarS1);
                }
                i2 = iE4;
                iE = iF2;
            } else {
                int iI2 = cVar.f1062f ? i2(i4) : fVar2.p(i4);
                iE = iI2 - this.u.e(viewB);
                if (r3 != 0 && cVar.f1062f) {
                    d.a aVarT1 = T1(iI2);
                    aVarT1.f1065f = 1;
                    aVarT1.f1064b = iA;
                    this.E.a(aVarT1);
                }
                i2 = iI2;
            }
            if (cVar.f1062f && fVar.f1156d == -1) {
                if (r3 != 0) {
                    this.M = true;
                } else {
                    if (!(fVar.f1157e == 1 ? I1() : J1())) {
                        d.a aVarF = this.E.f(iA);
                        if (aVarF != null) {
                            aVarF.f1067h = true;
                        }
                        this.M = true;
                    }
                }
            }
            K1(viewB, cVar, fVar);
            if (n2() && this.w == 1) {
                int i5 = cVar.f1062f ? this.v.i() : this.v.i() - (((this.s - 1) - fVar2.f1078e) * this.x);
                iE3 = i5;
                iE2 = i5 - this.v.e(viewB);
            } else {
                int iM = cVar.f1062f ? this.v.m() : (fVar2.f1078e * this.x) + this.v.m();
                iE2 = iM;
                iE3 = this.v.e(viewB) + iM;
            }
            if (this.w == 1) {
                x0(viewB, iE2, iE, iE3, i2);
            } else {
                x0(viewB, iE, iE2, i2, iE3);
            }
            if (cVar.f1062f) {
                E2(this.y.f1157e, i3);
            } else {
                K2(fVar2, this.y.f1157e, i3);
            }
            u2(vVar, this.y);
            if (!this.y.f1160h || !viewB.hasFocusable()) {
                z = false;
            } else if (cVar.f1062f) {
                this.B.clear();
                z = false;
            } else {
                z = false;
                this.B.set(fVar2.f1078e, false);
            }
            r9 = z;
            r0 = true;
        }
        ?? r32 = r9;
        if (r0 == false) {
            u2(vVar, this.y);
        }
        int iM2 = this.y.f1157e == -1 ? this.u.m() - i2(this.u.m()) : f2(this.u.i()) - this.u.i();
        return iM2 > 0 ? Math.min(fVar.f1154b, iM2) : r32 == true ? 1 : 0;
    }

    private int W1(int i2) {
        int I = I();
        for (int i3 = 0; i3 < I; i3++) {
            int iF0 = f0(H(i3));
            if (iF0 >= 0 && iF0 < i2) {
                return iF0;
            }
        }
        return 0;
    }

    private int a2(int i2) {
        for (int I = I() - 1; I >= 0; I--) {
            int iF0 = f0(H(I));
            if (iF0 >= 0 && iF0 < i2) {
                return iF0;
            }
        }
        return 0;
    }

    private void b2(RecyclerView.v vVar, RecyclerView.a0 a0Var, boolean z) {
        int i2;
        int iF2 = f2(Integer.MIN_VALUE);
        if (iF2 != Integer.MIN_VALUE && (i2 = this.u.i() - iF2) > 0) {
            int i3 = i2 - (-z2(-i2, vVar, a0Var));
            if (!z || i3 <= 0) {
                return;
            }
            this.u.r(i3);
        }
    }

    private void c2(RecyclerView.v vVar, RecyclerView.a0 a0Var, boolean z) {
        int iM;
        int iI2 = i2(Integer.MAX_VALUE);
        if (iI2 != Integer.MAX_VALUE && (iM = iI2 - this.u.m()) > 0) {
            int iZ2 = iM - z2(iM, vVar, a0Var);
            if (!z || iZ2 <= 0) {
                return;
            }
            this.u.r(-iZ2);
        }
    }

    private int f2(int i2) {
        int iL = this.t[0].l(i2);
        for (int i3 = 1; i3 < this.s; i3++) {
            int iL2 = this.t[i3].l(i2);
            if (iL2 > iL) {
                iL = iL2;
            }
        }
        return iL;
    }

    private int g2(int i2) {
        int iP = this.t[0].p(i2);
        for (int i3 = 1; i3 < this.s; i3++) {
            int iP2 = this.t[i3].p(i2);
            if (iP2 > iP) {
                iP = iP2;
            }
        }
        return iP;
    }

    private int h2(int i2) {
        int iL = this.t[0].l(i2);
        for (int i3 = 1; i3 < this.s; i3++) {
            int iL2 = this.t[i3].l(i2);
            if (iL2 < iL) {
                iL = iL2;
            }
        }
        return iL;
    }

    private int i2(int i2) {
        int iP = this.t[0].p(i2);
        for (int i3 = 1; i3 < this.s; i3++) {
            int iP2 = this.t[i3].p(i2);
            if (iP2 < iP) {
                iP = iP2;
            }
        }
        return iP;
    }

    private f j2(androidx.recyclerview.widget.f fVar) {
        int i2;
        int i3;
        int i4 = -1;
        if (r2(fVar.f1157e)) {
            i2 = this.s - 1;
            i3 = -1;
        } else {
            i2 = 0;
            i4 = this.s;
            i3 = 1;
        }
        f fVar2 = null;
        if (fVar.f1157e == 1) {
            int i5 = Integer.MAX_VALUE;
            int iM = this.u.m();
            while (i2 != i4) {
                f fVar3 = this.t[i2];
                int iL = fVar3.l(iM);
                if (iL < i5) {
                    fVar2 = fVar3;
                    i5 = iL;
                }
                i2 += i3;
            }
            return fVar2;
        }
        int i6 = Integer.MIN_VALUE;
        int i7 = this.u.i();
        while (i2 != i4) {
            f fVar4 = this.t[i2];
            int iP = fVar4.p(i7);
            if (iP > i6) {
                fVar2 = fVar4;
                i6 = iP;
            }
            i2 += i3;
        }
        return fVar2;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0025  */
    /* JADX WARN: Removed duplicated region for block: B:21:0x003c  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x0043 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0044  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private void k2(int r7, int r8, int r9) {
        /*
            r6 = this;
            boolean r0 = r6.A
            if (r0 == 0) goto L9
            int r0 = r6.e2()
            goto Ld
        L9:
            int r0 = r6.d2()
        Ld:
            r1 = 8
            if (r9 != r1) goto L1a
            if (r7 >= r8) goto L16
            int r2 = r8 + 1
            goto L1c
        L16:
            int r2 = r7 + 1
            r3 = r8
            goto L1d
        L1a:
            int r2 = r7 + r8
        L1c:
            r3 = r7
        L1d:
            androidx.recyclerview.widget.StaggeredGridLayoutManager$d r4 = r6.E
            r4.h(r3)
            r4 = 1
            if (r9 == r4) goto L3c
            r5 = 2
            if (r9 == r5) goto L36
            if (r9 == r1) goto L2b
            goto L41
        L2b:
            androidx.recyclerview.widget.StaggeredGridLayoutManager$d r9 = r6.E
            r9.k(r7, r4)
            androidx.recyclerview.widget.StaggeredGridLayoutManager$d r7 = r6.E
            r7.j(r8, r4)
            goto L41
        L36:
            androidx.recyclerview.widget.StaggeredGridLayoutManager$d r9 = r6.E
            r9.k(r7, r8)
            goto L41
        L3c:
            androidx.recyclerview.widget.StaggeredGridLayoutManager$d r9 = r6.E
            r9.j(r7, r8)
        L41:
            if (r2 > r0) goto L44
            return
        L44:
            boolean r7 = r6.A
            if (r7 == 0) goto L4d
            int r7 = r6.d2()
            goto L51
        L4d:
            int r7 = r6.e2()
        L51:
            if (r3 > r7) goto L56
            r6.q1()
        L56:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.StaggeredGridLayoutManager.k2(int, int, int):void");
    }

    private void o2(View view, int i2, int i3, boolean z) {
        i(view, this.K);
        c cVar = (c) view.getLayoutParams();
        int i4 = ((ViewGroup.MarginLayoutParams) cVar).leftMargin;
        Rect rect = this.K;
        int iL2 = L2(i2, i4 + rect.left, ((ViewGroup.MarginLayoutParams) cVar).rightMargin + rect.right);
        int i5 = ((ViewGroup.MarginLayoutParams) cVar).topMargin;
        Rect rect2 = this.K;
        int iL22 = L2(i3, i5 + rect2.top, ((ViewGroup.MarginLayoutParams) cVar).bottomMargin + rect2.bottom);
        if (z ? D1(view, iL2, iL22, cVar) : B1(view, iL2, iL22, cVar)) {
            view.measure(iL2, iL22);
        }
    }

    private void p2(View view, c cVar, boolean z) {
        if (cVar.f1062f) {
            if (this.w == 1) {
                o2(view, this.J, RecyclerView.LayoutManager.J(V(), W(), e0() + b0(), ((ViewGroup.MarginLayoutParams) cVar).height, true), z);
                return;
            } else {
                o2(view, RecyclerView.LayoutManager.J(m0(), n0(), c0() + d0(), ((ViewGroup.MarginLayoutParams) cVar).width, true), this.J, z);
                return;
            }
        }
        if (this.w == 1) {
            o2(view, RecyclerView.LayoutManager.J(this.x, n0(), 0, ((ViewGroup.MarginLayoutParams) cVar).width, false), RecyclerView.LayoutManager.J(V(), W(), e0() + b0(), ((ViewGroup.MarginLayoutParams) cVar).height, true), z);
        } else {
            o2(view, RecyclerView.LayoutManager.J(m0(), n0(), c0() + d0(), ((ViewGroup.MarginLayoutParams) cVar).width, true), RecyclerView.LayoutManager.J(this.x, W(), 0, ((ViewGroup.MarginLayoutParams) cVar).height, false), z);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:89:0x015a  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private void q2(androidx.recyclerview.widget.RecyclerView.v r9, androidx.recyclerview.widget.RecyclerView.a0 r10, boolean r11) {
        /*
            Method dump skipped, instruction units count: 379
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.StaggeredGridLayoutManager.q2(androidx.recyclerview.widget.RecyclerView$v, androidx.recyclerview.widget.RecyclerView$a0, boolean):void");
    }

    private boolean r2(int i2) {
        if (this.w == 0) {
            return (i2 == -1) != this.A;
        }
        return ((i2 == -1) == this.A) == n2();
    }

    private void t2(View view) {
        for (int i2 = this.s - 1; i2 >= 0; i2--) {
            this.t[i2].u(view);
        }
    }

    private void u2(RecyclerView.v vVar, androidx.recyclerview.widget.f fVar) {
        if (!fVar.a || fVar.f1161i) {
            return;
        }
        if (fVar.f1154b == 0) {
            if (fVar.f1157e == -1) {
                v2(vVar, fVar.f1159g);
                return;
            } else {
                w2(vVar, fVar.f1158f);
                return;
            }
        }
        if (fVar.f1157e != -1) {
            int iH2 = h2(fVar.f1159g) - fVar.f1159g;
            w2(vVar, iH2 < 0 ? fVar.f1158f : Math.min(iH2, fVar.f1154b) + fVar.f1158f);
        } else {
            int i2 = fVar.f1158f;
            int iG2 = i2 - g2(i2);
            v2(vVar, iG2 < 0 ? fVar.f1159g : fVar.f1159g - Math.min(iG2, fVar.f1154b));
        }
    }

    private void v2(RecyclerView.v vVar, int i2) {
        for (int I = I() - 1; I >= 0; I--) {
            View viewH = H(I);
            if (this.u.g(viewH) < i2 || this.u.q(viewH) < i2) {
                return;
            }
            c cVar = (c) viewH.getLayoutParams();
            if (cVar.f1062f) {
                for (int i3 = 0; i3 < this.s; i3++) {
                    if (this.t[i3].a.size() == 1) {
                        return;
                    }
                }
                for (int i4 = 0; i4 < this.s; i4++) {
                    this.t[i4].s();
                }
            } else if (cVar.f1061e.a.size() == 1) {
                return;
            } else {
                cVar.f1061e.s();
            }
            j1(viewH, vVar);
        }
    }

    private void w2(RecyclerView.v vVar, int i2) {
        while (I() > 0) {
            View viewH = H(0);
            if (this.u.d(viewH) > i2 || this.u.p(viewH) > i2) {
                return;
            }
            c cVar = (c) viewH.getLayoutParams();
            if (cVar.f1062f) {
                for (int i3 = 0; i3 < this.s; i3++) {
                    if (this.t[i3].a.size() == 1) {
                        return;
                    }
                }
                for (int i4 = 0; i4 < this.s; i4++) {
                    this.t[i4].t();
                }
            } else if (cVar.f1061e.a.size() == 1) {
                return;
            } else {
                cVar.f1061e.t();
            }
            j1(viewH, vVar);
        }
    }

    private void x2() {
        if (this.v.k() == 1073741824) {
            return;
        }
        float fMax = 0.0f;
        int I = I();
        for (int i2 = 0; i2 < I; i2++) {
            View viewH = H(i2);
            float fE = this.v.e(viewH);
            if (fE >= fMax) {
                if (((c) viewH.getLayoutParams()).e()) {
                    fE = (fE * 1.0f) / this.s;
                }
                fMax = Math.max(fMax, fE);
            }
        }
        int i3 = this.x;
        int iRound = Math.round(fMax * this.s);
        if (this.v.k() == Integer.MIN_VALUE) {
            iRound = Math.min(iRound, this.v.n());
        }
        J2(iRound);
        if (this.x == i3) {
            return;
        }
        for (int i4 = 0; i4 < I; i4++) {
            View viewH2 = H(i4);
            c cVar = (c) viewH2.getLayoutParams();
            if (!cVar.f1062f) {
                if (n2() && this.w == 1) {
                    int i5 = this.s;
                    int i6 = cVar.f1061e.f1078e;
                    viewH2.offsetLeftAndRight(((-((i5 - 1) - i6)) * this.x) - ((-((i5 - 1) - i6)) * i3));
                } else {
                    int i7 = cVar.f1061e.f1078e;
                    int i8 = this.x * i7;
                    int i9 = i7 * i3;
                    if (this.w == 1) {
                        viewH2.offsetLeftAndRight(i8 - i9);
                    } else {
                        viewH2.offsetTopAndBottom(i8 - i9);
                    }
                }
            }
        }
    }

    private void y2() {
        if (this.w == 1 || !n2()) {
            this.A = this.z;
        } else {
            this.A = !this.z;
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void A0(int i2) {
        super.A0(i2);
        for (int i3 = 0; i3 < this.s; i3++) {
            this.t[i3].r(i2);
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void B0(int i2) {
        super.B0(i2);
        for (int i3 = 0; i3 < this.s; i3++) {
            this.t[i3].r(i2);
        }
    }

    public void B2(int i2) {
        if (i2 != 0 && i2 != 1) {
            throw new IllegalArgumentException("invalid orientation.");
        }
        f(null);
        if (i2 == this.w) {
            return;
        }
        this.w = i2;
        h hVar = this.u;
        this.u = this.v;
        this.v = hVar;
        q1();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public RecyclerView.p C() {
        return this.w == 0 ? new c(-2, -1) : new c(-1, -2);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void C0(RecyclerView.h hVar, RecyclerView.h hVar2) {
        this.E.b();
        for (int i2 = 0; i2 < this.s; i2++) {
            this.t[i2].e();
        }
    }

    public void C2(boolean z) {
        f(null);
        e eVar = this.I;
        if (eVar != null && eVar.l != z) {
            eVar.l = z;
        }
        this.z = z;
        q1();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public RecyclerView.p D(Context context, AttributeSet attributeSet) {
        return new c(context, attributeSet);
    }

    public void D2(int i2) {
        f(null);
        if (i2 != this.s) {
            m2();
            this.s = i2;
            this.B = new BitSet(this.s);
            this.t = new f[this.s];
            for (int i3 = 0; i3 < this.s; i3++) {
                this.t[i3] = new f(i3);
            }
            q1();
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public RecyclerView.p E(ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof ViewGroup.MarginLayoutParams ? new c((ViewGroup.MarginLayoutParams) layoutParams) : new c(layoutParams);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public boolean F1() {
        return this.I == null;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void G0(RecyclerView recyclerView, RecyclerView.v vVar) {
        super.G0(recyclerView, vVar);
        l1(this.P);
        for (int i2 = 0; i2 < this.s; i2++) {
            this.t[i2].e();
        }
        recyclerView.requestLayout();
    }

    boolean G2(RecyclerView.a0 a0Var, b bVar) {
        int i2;
        if (!a0Var.e() && (i2 = this.C) != -1) {
            if (i2 >= 0 && i2 < a0Var.b()) {
                e eVar = this.I;
                if (eVar == null || eVar.f1068b == -1 || eVar.f1070g < 1) {
                    View viewB = B(this.C);
                    if (viewB != null) {
                        bVar.a = this.A ? e2() : d2();
                        if (this.D != Integer.MIN_VALUE) {
                            if (bVar.f1056c) {
                                bVar.f1055b = (this.u.i() - this.D) - this.u.d(viewB);
                            } else {
                                bVar.f1055b = (this.u.m() + this.D) - this.u.g(viewB);
                            }
                            return true;
                        }
                        if (this.u.e(viewB) > this.u.n()) {
                            bVar.f1055b = bVar.f1056c ? this.u.i() : this.u.m();
                            return true;
                        }
                        int iG = this.u.g(viewB) - this.u.m();
                        if (iG < 0) {
                            bVar.f1055b = -iG;
                            return true;
                        }
                        int i3 = this.u.i() - this.u.d(viewB);
                        if (i3 < 0) {
                            bVar.f1055b = i3;
                            return true;
                        }
                        bVar.f1055b = Integer.MIN_VALUE;
                    } else {
                        int i4 = this.C;
                        bVar.a = i4;
                        int i5 = this.D;
                        if (i5 == Integer.MIN_VALUE) {
                            bVar.f1056c = L1(i4) == 1;
                            bVar.a();
                        } else {
                            bVar.b(i5);
                        }
                        bVar.f1057d = true;
                    }
                } else {
                    bVar.f1055b = Integer.MIN_VALUE;
                    bVar.a = this.C;
                }
                return true;
            }
            this.C = -1;
            this.D = Integer.MIN_VALUE;
        }
        return false;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public View H0(View view, int i2, RecyclerView.v vVar, RecyclerView.a0 a0Var) {
        View viewA;
        View viewM;
        if (I() == 0 || (viewA = A(view)) == null) {
            return null;
        }
        y2();
        int iR1 = R1(i2);
        if (iR1 == Integer.MIN_VALUE) {
            return null;
        }
        c cVar = (c) viewA.getLayoutParams();
        boolean z = cVar.f1062f;
        f fVar = cVar.f1061e;
        int iE2 = iR1 == 1 ? e2() : d2();
        I2(iE2, a0Var);
        A2(iR1);
        androidx.recyclerview.widget.f fVar2 = this.y;
        fVar2.f1155c = fVar2.f1156d + iE2;
        fVar2.f1154b = (int) (this.u.n() * 0.33333334f);
        androidx.recyclerview.widget.f fVar3 = this.y;
        fVar3.f1160h = true;
        fVar3.a = false;
        V1(vVar, fVar3, a0Var);
        this.G = this.A;
        if (!z && (viewM = fVar.m(iE2, iR1)) != null && viewM != viewA) {
            return viewM;
        }
        if (r2(iR1)) {
            for (int i3 = this.s - 1; i3 >= 0; i3--) {
                View viewM2 = this.t[i3].m(iE2, iR1);
                if (viewM2 != null && viewM2 != viewA) {
                    return viewM2;
                }
            }
        } else {
            for (int i4 = 0; i4 < this.s; i4++) {
                View viewM3 = this.t[i4].m(iE2, iR1);
                if (viewM3 != null && viewM3 != viewA) {
                    return viewM3;
                }
            }
        }
        boolean z2 = (this.z ^ true) == (iR1 == -1);
        if (!z) {
            View viewB = B(z2 ? fVar.f() : fVar.g());
            if (viewB != null && viewB != viewA) {
                return viewB;
            }
        }
        if (r2(iR1)) {
            for (int i5 = this.s - 1; i5 >= 0; i5--) {
                if (i5 != fVar.f1078e) {
                    View viewB2 = B(z2 ? this.t[i5].f() : this.t[i5].g());
                    if (viewB2 != null && viewB2 != viewA) {
                        return viewB2;
                    }
                }
            }
        } else {
            for (int i6 = 0; i6 < this.s; i6++) {
                View viewB3 = B(z2 ? this.t[i6].f() : this.t[i6].g());
                if (viewB3 != null && viewB3 != viewA) {
                    return viewB3;
                }
            }
        }
        return null;
    }

    void H2(RecyclerView.a0 a0Var, b bVar) {
        if (G2(a0Var, bVar) || F2(a0Var, bVar)) {
            return;
        }
        bVar.a();
        bVar.a = 0;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void I0(AccessibilityEvent accessibilityEvent) {
        super.I0(accessibilityEvent);
        if (I() > 0) {
            View viewY1 = Y1(false);
            View viewX1 = X1(false);
            if (viewY1 == null || viewX1 == null) {
                return;
            }
            int iF0 = f0(viewY1);
            int iF02 = f0(viewX1);
            if (iF0 < iF02) {
                accessibilityEvent.setFromIndex(iF0);
                accessibilityEvent.setToIndex(iF02);
            } else {
                accessibilityEvent.setFromIndex(iF02);
                accessibilityEvent.setToIndex(iF0);
            }
        }
    }

    boolean I1() {
        int iL = this.t[0].l(Integer.MIN_VALUE);
        for (int i2 = 1; i2 < this.s; i2++) {
            if (this.t[i2].l(Integer.MIN_VALUE) != iL) {
                return false;
            }
        }
        return true;
    }

    boolean J1() {
        int iP = this.t[0].p(Integer.MIN_VALUE);
        for (int i2 = 1; i2 < this.s; i2++) {
            if (this.t[i2].p(Integer.MIN_VALUE) != iP) {
                return false;
            }
        }
        return true;
    }

    void J2(int i2) {
        this.x = i2 / this.s;
        this.J = View.MeasureSpec.makeMeasureSpec(i2, this.v.k());
    }

    boolean M1() {
        int iD2;
        int iE2;
        if (I() == 0 || this.F == 0 || !p0()) {
            return false;
        }
        if (this.A) {
            iD2 = e2();
            iE2 = d2();
        } else {
            iD2 = d2();
            iE2 = e2();
        }
        if (iD2 == 0 && l2() != null) {
            this.E.b();
            r1();
            q1();
            return true;
        }
        if (!this.M) {
            return false;
        }
        int i2 = this.A ? -1 : 1;
        int i3 = iE2 + 1;
        d.a aVarE = this.E.e(iD2, i3, i2, true);
        if (aVarE == null) {
            this.M = false;
            this.E.d(i3);
            return false;
        }
        d.a aVarE2 = this.E.e(iD2, aVarE.f1064b, i2 * (-1), true);
        if (aVarE2 == null) {
            this.E.d(aVarE.f1064b);
        } else {
            this.E.d(aVarE2.f1064b + 1);
        }
        r1();
        q1();
        return true;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void P0(RecyclerView recyclerView, int i2, int i3) {
        k2(i2, i3, 1);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void Q0(RecyclerView recyclerView) {
        this.E.b();
        q1();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void R0(RecyclerView recyclerView, int i2, int i3, int i4) {
        k2(i2, i3, 8);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void S0(RecyclerView recyclerView, int i2, int i3) {
        k2(i2, i3, 2);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void U0(RecyclerView recyclerView, int i2, int i3, Object obj) {
        k2(i2, i3, 4);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void V0(RecyclerView.v vVar, RecyclerView.a0 a0Var) {
        q2(vVar, a0Var, true);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void W0(RecyclerView.a0 a0Var) {
        super.W0(a0Var);
        this.C = -1;
        this.D = Integer.MIN_VALUE;
        this.I = null;
        this.L.c();
    }

    View X1(boolean z) {
        int iM = this.u.m();
        int i2 = this.u.i();
        View view = null;
        for (int I = I() - 1; I >= 0; I--) {
            View viewH = H(I);
            int iG = this.u.g(viewH);
            int iD = this.u.d(viewH);
            if (iD > iM && iG < i2) {
                if (iD <= i2 || !z) {
                    return viewH;
                }
                if (view == null) {
                    view = viewH;
                }
            }
        }
        return view;
    }

    View Y1(boolean z) {
        int iM = this.u.m();
        int i2 = this.u.i();
        int I = I();
        View view = null;
        for (int i3 = 0; i3 < I; i3++) {
            View viewH = H(i3);
            int iG = this.u.g(viewH);
            if (this.u.d(viewH) > iM && iG < i2) {
                if (iG >= iM || !z) {
                    return viewH;
                }
                if (view == null) {
                    view = viewH;
                }
            }
        }
        return view;
    }

    int Z1() {
        View viewX1 = this.A ? X1(true) : Y1(true);
        if (viewX1 == null) {
            return -1;
        }
        return f0(viewX1);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void a1(Parcelable parcelable) {
        if (parcelable instanceof e) {
            e eVar = (e) parcelable;
            this.I = eVar;
            if (this.C != -1) {
                eVar.a();
                this.I.b();
            }
            q1();
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public Parcelable b1() {
        int iP;
        int iM;
        int[] iArr;
        if (this.I != null) {
            return new e(this.I);
        }
        e eVar = new e();
        eVar.l = this.z;
        eVar.m = this.G;
        eVar.n = this.H;
        d dVar = this.E;
        if (dVar == null || (iArr = dVar.a) == null) {
            eVar.f1072i = 0;
        } else {
            eVar.f1073j = iArr;
            eVar.f1072i = iArr.length;
            eVar.f1074k = dVar.f1063b;
        }
        if (I() > 0) {
            eVar.f1068b = this.G ? e2() : d2();
            eVar.f1069f = Z1();
            int i2 = this.s;
            eVar.f1070g = i2;
            eVar.f1071h = new int[i2];
            for (int i3 = 0; i3 < this.s; i3++) {
                if (this.G) {
                    iP = this.t[i3].l(Integer.MIN_VALUE);
                    if (iP != Integer.MIN_VALUE) {
                        iM = this.u.i();
                        iP -= iM;
                    }
                } else {
                    iP = this.t[i3].p(Integer.MIN_VALUE);
                    if (iP != Integer.MIN_VALUE) {
                        iM = this.u.m();
                        iP -= iM;
                    }
                }
                eVar.f1071h[i3] = iP;
            }
        } else {
            eVar.f1068b = -1;
            eVar.f1069f = -1;
            eVar.f1070g = 0;
        }
        return eVar;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void c1(int i2) {
        if (i2 == 0) {
            M1();
        }
    }

    int d2() {
        if (I() == 0) {
            return 0;
        }
        return f0(H(0));
    }

    int e2() {
        int I = I();
        if (I == 0) {
            return 0;
        }
        return f0(H(I - 1));
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void f(String str) {
        if (this.I == null) {
            super.f(str);
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public boolean j() {
        return this.w == 0;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public boolean k() {
        return this.w == 1;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public boolean l(RecyclerView.p pVar) {
        return pVar instanceof c;
    }

    /* JADX WARN: Removed duplicated region for block: B:37:0x0088  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x008a  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    android.view.View l2() {
        /*
            r12 = this;
            int r0 = r12.I()
            r1 = 1
            int r0 = r0 - r1
            java.util.BitSet r2 = new java.util.BitSet
            int r3 = r12.s
            r2.<init>(r3)
            int r3 = r12.s
            r4 = 0
            r2.set(r4, r3, r1)
            int r3 = r12.w
            r5 = -1
            if (r3 != r1) goto L20
            boolean r3 = r12.n2()
            if (r3 == 0) goto L20
            r3 = r1
            goto L21
        L20:
            r3 = r5
        L21:
            boolean r6 = r12.A
            if (r6 == 0) goto L27
            r6 = r5
            goto L2b
        L27:
            int r0 = r0 + 1
            r6 = r0
            r0 = r4
        L2b:
            if (r0 >= r6) goto L2e
            r5 = r1
        L2e:
            if (r0 == r6) goto Lab
            android.view.View r7 = r12.H(r0)
            android.view.ViewGroup$LayoutParams r8 = r7.getLayoutParams()
            androidx.recyclerview.widget.StaggeredGridLayoutManager$c r8 = (androidx.recyclerview.widget.StaggeredGridLayoutManager.c) r8
            androidx.recyclerview.widget.StaggeredGridLayoutManager$f r9 = r8.f1061e
            int r9 = r9.f1078e
            boolean r9 = r2.get(r9)
            if (r9 == 0) goto L54
            androidx.recyclerview.widget.StaggeredGridLayoutManager$f r9 = r8.f1061e
            boolean r9 = r12.N1(r9)
            if (r9 == 0) goto L4d
            return r7
        L4d:
            androidx.recyclerview.widget.StaggeredGridLayoutManager$f r9 = r8.f1061e
            int r9 = r9.f1078e
            r2.clear(r9)
        L54:
            boolean r9 = r8.f1062f
            if (r9 == 0) goto L59
            goto La9
        L59:
            int r9 = r0 + r5
            if (r9 == r6) goto La9
            android.view.View r9 = r12.H(r9)
            boolean r10 = r12.A
            if (r10 == 0) goto L77
            androidx.recyclerview.widget.h r10 = r12.u
            int r10 = r10.d(r7)
            androidx.recyclerview.widget.h r11 = r12.u
            int r11 = r11.d(r9)
            if (r10 >= r11) goto L74
            return r7
        L74:
            if (r10 != r11) goto L8a
            goto L88
        L77:
            androidx.recyclerview.widget.h r10 = r12.u
            int r10 = r10.g(r7)
            androidx.recyclerview.widget.h r11 = r12.u
            int r11 = r11.g(r9)
            if (r10 <= r11) goto L86
            return r7
        L86:
            if (r10 != r11) goto L8a
        L88:
            r10 = r1
            goto L8b
        L8a:
            r10 = r4
        L8b:
            if (r10 == 0) goto La9
            android.view.ViewGroup$LayoutParams r9 = r9.getLayoutParams()
            androidx.recyclerview.widget.StaggeredGridLayoutManager$c r9 = (androidx.recyclerview.widget.StaggeredGridLayoutManager.c) r9
            androidx.recyclerview.widget.StaggeredGridLayoutManager$f r8 = r8.f1061e
            int r8 = r8.f1078e
            androidx.recyclerview.widget.StaggeredGridLayoutManager$f r9 = r9.f1061e
            int r9 = r9.f1078e
            int r8 = r8 - r9
            if (r8 >= 0) goto La0
            r8 = r1
            goto La1
        La0:
            r8 = r4
        La1:
            if (r3 >= 0) goto La5
            r9 = r1
            goto La6
        La5:
            r9 = r4
        La6:
            if (r8 == r9) goto La9
            return r7
        La9:
            int r0 = r0 + r5
            goto L2e
        Lab:
            r0 = 0
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.StaggeredGridLayoutManager.l2():android.view.View");
    }

    public void m2() {
        this.E.b();
        q1();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void n(int i2, int i3, RecyclerView.a0 a0Var, RecyclerView.LayoutManager.c cVar) {
        int iL;
        int iP;
        if (this.w != 0) {
            i2 = i3;
        }
        if (I() == 0 || i2 == 0) {
            return;
        }
        s2(i2, a0Var);
        int[] iArr = this.O;
        if (iArr == null || iArr.length < this.s) {
            this.O = new int[this.s];
        }
        int i4 = 0;
        for (int i5 = 0; i5 < this.s; i5++) {
            androidx.recyclerview.widget.f fVar = this.y;
            if (fVar.f1156d == -1) {
                iL = fVar.f1158f;
                iP = this.t[i5].p(iL);
            } else {
                iL = this.t[i5].l(fVar.f1159g);
                iP = this.y.f1159g;
            }
            int i6 = iL - iP;
            if (i6 >= 0) {
                this.O[i4] = i6;
                i4++;
            }
        }
        Arrays.sort(this.O, 0, i4);
        for (int i7 = 0; i7 < i4 && this.y.a(a0Var); i7++) {
            cVar.a(this.y.f1155c, this.O[i7]);
            androidx.recyclerview.widget.f fVar2 = this.y;
            fVar2.f1155c += fVar2.f1156d;
        }
    }

    boolean n2() {
        return X() == 1;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public int p(RecyclerView.a0 a0Var) {
        return O1(a0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public int q(RecyclerView.a0 a0Var) {
        return P1(a0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public boolean q0() {
        return this.F != 0;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public int r(RecyclerView.a0 a0Var) {
        return Q1(a0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public int s(RecyclerView.a0 a0Var) {
        return O1(a0Var);
    }

    void s2(int i2, RecyclerView.a0 a0Var) {
        int i3;
        int iD2;
        if (i2 > 0) {
            iD2 = e2();
            i3 = 1;
        } else {
            i3 = -1;
            iD2 = d2();
        }
        this.y.a = true;
        I2(iD2, a0Var);
        A2(i3);
        androidx.recyclerview.widget.f fVar = this.y;
        fVar.f1155c = iD2 + fVar.f1156d;
        fVar.f1154b = Math.abs(i2);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public int t(RecyclerView.a0 a0Var) {
        return P1(a0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public int t1(int i2, RecyclerView.v vVar, RecyclerView.a0 a0Var) {
        return z2(i2, vVar, a0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public int u(RecyclerView.a0 a0Var) {
        return Q1(a0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public int u1(int i2, RecyclerView.v vVar, RecyclerView.a0 a0Var) {
        return z2(i2, vVar, a0Var);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
    public void y1(Rect rect, int i2, int i3) {
        int iM;
        int iM2;
        int iC0 = c0() + d0();
        int iE0 = e0() + b0();
        if (this.w == 1) {
            iM2 = RecyclerView.LayoutManager.m(i3, rect.height() + iE0, Z());
            iM = RecyclerView.LayoutManager.m(i2, (this.x * this.s) + iC0, a0());
        } else {
            iM = RecyclerView.LayoutManager.m(i2, rect.width() + iC0, a0());
            iM2 = RecyclerView.LayoutManager.m(i3, (this.x * this.s) + iE0, Z());
        }
        x1(iM, iM2);
    }

    int z2(int i2, RecyclerView.v vVar, RecyclerView.a0 a0Var) {
        if (I() == 0 || i2 == 0) {
            return 0;
        }
        s2(i2, a0Var);
        int iV1 = V1(vVar, this.y, a0Var);
        if (this.y.f1154b >= iV1) {
            i2 = i2 < 0 ? -iV1 : iV1;
        }
        this.u.r(-i2);
        this.G = this.A;
        androidx.recyclerview.widget.f fVar = this.y;
        fVar.f1154b = 0;
        u2(vVar, fVar);
        return i2;
    }

    static class d {
        int[] a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        List<a> f1063b;

        d() {
        }

        private int i(int i2) {
            if (this.f1063b == null) {
                return -1;
            }
            a aVarF = f(i2);
            if (aVarF != null) {
                this.f1063b.remove(aVarF);
            }
            int size = this.f1063b.size();
            int i3 = 0;
            while (true) {
                if (i3 >= size) {
                    i3 = -1;
                    break;
                }
                if (this.f1063b.get(i3).f1064b >= i2) {
                    break;
                }
                i3++;
            }
            if (i3 == -1) {
                return -1;
            }
            a aVar = this.f1063b.get(i3);
            this.f1063b.remove(i3);
            return aVar.f1064b;
        }

        private void l(int i2, int i3) {
            List<a> list = this.f1063b;
            if (list == null) {
                return;
            }
            for (int size = list.size() - 1; size >= 0; size--) {
                a aVar = this.f1063b.get(size);
                int i4 = aVar.f1064b;
                if (i4 >= i2) {
                    aVar.f1064b = i4 + i3;
                }
            }
        }

        private void m(int i2, int i3) {
            List<a> list = this.f1063b;
            if (list == null) {
                return;
            }
            int i4 = i2 + i3;
            for (int size = list.size() - 1; size >= 0; size--) {
                a aVar = this.f1063b.get(size);
                int i5 = aVar.f1064b;
                if (i5 >= i2) {
                    if (i5 < i4) {
                        this.f1063b.remove(size);
                    } else {
                        aVar.f1064b = i5 - i3;
                    }
                }
            }
        }

        public void a(a aVar) {
            if (this.f1063b == null) {
                this.f1063b = new ArrayList();
            }
            int size = this.f1063b.size();
            for (int i2 = 0; i2 < size; i2++) {
                a aVar2 = this.f1063b.get(i2);
                if (aVar2.f1064b == aVar.f1064b) {
                    this.f1063b.remove(i2);
                }
                if (aVar2.f1064b >= aVar.f1064b) {
                    this.f1063b.add(i2, aVar);
                    return;
                }
            }
            this.f1063b.add(aVar);
        }

        void b() {
            int[] iArr = this.a;
            if (iArr != null) {
                Arrays.fill(iArr, -1);
            }
            this.f1063b = null;
        }

        void c(int i2) {
            int[] iArr = this.a;
            if (iArr == null) {
                int[] iArr2 = new int[Math.max(i2, 10) + 1];
                this.a = iArr2;
                Arrays.fill(iArr2, -1);
            } else if (i2 >= iArr.length) {
                int[] iArr3 = new int[o(i2)];
                this.a = iArr3;
                System.arraycopy(iArr, 0, iArr3, 0, iArr.length);
                int[] iArr4 = this.a;
                Arrays.fill(iArr4, iArr.length, iArr4.length, -1);
            }
        }

        int d(int i2) {
            List<a> list = this.f1063b;
            if (list != null) {
                for (int size = list.size() - 1; size >= 0; size--) {
                    if (this.f1063b.get(size).f1064b >= i2) {
                        this.f1063b.remove(size);
                    }
                }
            }
            return h(i2);
        }

        public a e(int i2, int i3, int i4, boolean z) {
            List<a> list = this.f1063b;
            if (list == null) {
                return null;
            }
            int size = list.size();
            for (int i5 = 0; i5 < size; i5++) {
                a aVar = this.f1063b.get(i5);
                int i6 = aVar.f1064b;
                if (i6 >= i3) {
                    return null;
                }
                if (i6 >= i2 && (i4 == 0 || aVar.f1065f == i4 || (z && aVar.f1067h))) {
                    return aVar;
                }
            }
            return null;
        }

        public a f(int i2) {
            List<a> list = this.f1063b;
            if (list == null) {
                return null;
            }
            for (int size = list.size() - 1; size >= 0; size--) {
                a aVar = this.f1063b.get(size);
                if (aVar.f1064b == i2) {
                    return aVar;
                }
            }
            return null;
        }

        int g(int i2) {
            int[] iArr = this.a;
            if (iArr == null || i2 >= iArr.length) {
                return -1;
            }
            return iArr[i2];
        }

        int h(int i2) {
            int[] iArr = this.a;
            if (iArr == null || i2 >= iArr.length) {
                return -1;
            }
            int i3 = i(i2);
            if (i3 == -1) {
                int[] iArr2 = this.a;
                Arrays.fill(iArr2, i2, iArr2.length, -1);
                return this.a.length;
            }
            int iMin = Math.min(i3 + 1, this.a.length);
            Arrays.fill(this.a, i2, iMin, -1);
            return iMin;
        }

        void j(int i2, int i3) {
            int[] iArr = this.a;
            if (iArr == null || i2 >= iArr.length) {
                return;
            }
            int i4 = i2 + i3;
            c(i4);
            int[] iArr2 = this.a;
            System.arraycopy(iArr2, i2, iArr2, i4, (iArr2.length - i2) - i3);
            Arrays.fill(this.a, i2, i4, -1);
            l(i2, i3);
        }

        void k(int i2, int i3) {
            int[] iArr = this.a;
            if (iArr == null || i2 >= iArr.length) {
                return;
            }
            int i4 = i2 + i3;
            c(i4);
            int[] iArr2 = this.a;
            System.arraycopy(iArr2, i4, iArr2, i2, (iArr2.length - i2) - i3);
            int[] iArr3 = this.a;
            Arrays.fill(iArr3, iArr3.length - i3, iArr3.length, -1);
            m(i2, i3);
        }

        void n(int i2, f fVar) {
            c(i2);
            this.a[i2] = fVar.f1078e;
        }

        int o(int i2) {
            int length = this.a.length;
            while (length <= i2) {
                length *= 2;
            }
            return length;
        }

        @SuppressLint({"BanParcelableUsage"})
        static class a implements Parcelable {
            public static final Parcelable.Creator<a> CREATOR = new C0014a();

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            int f1064b;

            /* JADX INFO: renamed from: f, reason: collision with root package name */
            int f1065f;

            /* JADX INFO: renamed from: g, reason: collision with root package name */
            int[] f1066g;

            /* JADX INFO: renamed from: h, reason: collision with root package name */
            boolean f1067h;

            /* JADX INFO: renamed from: androidx.recyclerview.widget.StaggeredGridLayoutManager$d$a$a, reason: collision with other inner class name */
            class C0014a implements Parcelable.Creator<a> {
                C0014a() {
                }

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

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

            a(Parcel parcel) {
                this.f1064b = parcel.readInt();
                this.f1065f = parcel.readInt();
                this.f1067h = parcel.readInt() == 1;
                int i2 = parcel.readInt();
                if (i2 > 0) {
                    int[] iArr = new int[i2];
                    this.f1066g = iArr;
                    parcel.readIntArray(iArr);
                }
            }

            int a(int i2) {
                int[] iArr = this.f1066g;
                if (iArr == null) {
                    return 0;
                }
                return iArr[i2];
            }

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

            public String toString() {
                return "FullSpanItem{mPosition=" + this.f1064b + ", mGapDir=" + this.f1065f + ", mHasUnwantedGapAfter=" + this.f1067h + ", mGapPerSpan=" + Arrays.toString(this.f1066g) + '}';
            }

            @Override // android.os.Parcelable
            public void writeToParcel(Parcel parcel, int i2) {
                parcel.writeInt(this.f1064b);
                parcel.writeInt(this.f1065f);
                parcel.writeInt(this.f1067h ? 1 : 0);
                int[] iArr = this.f1066g;
                if (iArr == null || iArr.length <= 0) {
                    parcel.writeInt(0);
                } else {
                    parcel.writeInt(iArr.length);
                    parcel.writeIntArray(this.f1066g);
                }
            }

            a() {
            }
        }
    }

    public StaggeredGridLayoutManager(int i2, int i3) {
        this.w = i3;
        D2(i2);
        this.y = new androidx.recyclerview.widget.f();
        U1();
    }
}
