package com.google.android.flexbox;

import android.content.Context;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.ad;
import androidx.recyclerview.widget.ak;
import com.google.android.flexbox.d;
import defpackage.vw2;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class FlexboxLayoutManager extends RecyclerView.o implements com.google.android.flexbox.a, RecyclerView.ab.b {
    public static final Rect aa = new Rect();
    public int a;
    public final int b;
    public final int c;
    public boolean e;
    public boolean f;
    public RecyclerView.w k;
    public RecyclerView.ac l;
    public d m;
    public final b n;
    public ak o;
    public ak p;
    public e q;
    public int r;
    public int s;
    public int t;
    public int u;
    public final SparseArray v;
    public final Context w;
    public View x;
    public int y;
    public final d.b z;
    public final int d = -1;
    public List i = new ArrayList();
    public final com.google.android.flexbox.d j = new com.google.android.flexbox.d(this);

    public class b {
        public int a;
        public int b;
        public int c;
        public int d = 0;
        public boolean e;
        public boolean f;
        public boolean g;

        public b() {
        }

        public static void a(b bVar) {
            FlexboxLayoutManager flexboxLayoutManager = FlexboxLayoutManager.this;
            if (flexboxLayoutManager.j() || !flexboxLayoutManager.e) {
                bVar.c = bVar.e ? flexboxLayoutManager.o.i() : flexboxLayoutManager.o.m();
            } else {
                bVar.c = bVar.e ? flexboxLayoutManager.o.i() : flexboxLayoutManager.getWidth() - flexboxLayoutManager.o.m();
            }
        }

        public static void b(b bVar) {
            bVar.a = -1;
            bVar.b = -1;
            bVar.c = Integer.MIN_VALUE;
            bVar.f = false;
            bVar.g = false;
            FlexboxLayoutManager flexboxLayoutManager = FlexboxLayoutManager.this;
            if (flexboxLayoutManager.j()) {
                int i = flexboxLayoutManager.b;
                if (i == 0) {
                    bVar.e = flexboxLayoutManager.a == 1;
                    return;
                } else {
                    bVar.e = i == 2;
                    return;
                }
            }
            int i2 = flexboxLayoutManager.b;
            if (i2 == 0) {
                bVar.e = flexboxLayoutManager.a == 3;
            } else {
                bVar.e = i2 == 2;
            }
        }

        public final String toString() {
            return "AnchorInfo{mPosition=" + this.a + ", mFlexLinePosition=" + this.b + ", mCoordinate=" + this.c + ", mPerpendicularCoordinate=" + this.d + ", mLayoutFromEnd=" + this.e + ", mValid=" + this.f + ", mAssignedFromSavedState=" + this.g + '}';
        }
    }

    public static class c extends RecyclerView.p implements com.google.android.flexbox.b {
        public static final Parcelable.Creator<c> CREATOR = new a();
        public float e;
        public float f;
        public int i;
        public float j;
        public int k;
        public int l;
        public int m;
        public int n;
        public boolean o;

        public class a implements Parcelable.Creator<c> {
            @Override // android.os.Parcelable.Creator
            public final c createFromParcel(Parcel parcel) {
                c cVar = new c(-2, -2);
                cVar.e = 0.0f;
                cVar.f = 1.0f;
                cVar.i = -1;
                cVar.j = -1.0f;
                cVar.m = 16777215;
                cVar.n = 16777215;
                cVar.e = parcel.readFloat();
                cVar.f = parcel.readFloat();
                cVar.i = parcel.readInt();
                cVar.j = parcel.readFloat();
                cVar.k = parcel.readInt();
                cVar.l = parcel.readInt();
                cVar.m = parcel.readInt();
                cVar.n = parcel.readInt();
                cVar.o = parcel.readByte() != 0;
                ((ViewGroup.MarginLayoutParams) cVar).bottomMargin = parcel.readInt();
                ((ViewGroup.MarginLayoutParams) cVar).leftMargin = parcel.readInt();
                ((ViewGroup.MarginLayoutParams) cVar).rightMargin = parcel.readInt();
                ((ViewGroup.MarginLayoutParams) cVar).topMargin = parcel.readInt();
                ((ViewGroup.MarginLayoutParams) cVar).height = parcel.readInt();
                ((ViewGroup.MarginLayoutParams) cVar).width = parcel.readInt();
                return cVar;
            }

            @Override // android.os.Parcelable.Creator
            public final c[] newArray(int i) {
                return new c[i];
            }
        }

        @Override // com.google.android.flexbox.b
        public final int a() {
            return this.i;
        }

        @Override // com.google.android.flexbox.b
        public final float aa() {
            return this.j;
        }

        @Override // com.google.android.flexbox.b
        public final boolean ab() {
            return this.o;
        }

        @Override // com.google.android.flexbox.b
        public final int ad() {
            return this.m;
        }

        @Override // com.google.android.flexbox.b
        public final void am(int i) {
            this.k = i;
        }

        @Override // com.google.android.flexbox.b
        public final int an() {
            return ((ViewGroup.MarginLayoutParams) this).bottomMargin;
        }

        @Override // com.google.android.flexbox.b
        public final int ap() {
            return ((ViewGroup.MarginLayoutParams) this).leftMargin;
        }

        @Override // com.google.android.flexbox.b
        public final int av() {
            return ((ViewGroup.MarginLayoutParams) this).rightMargin;
        }

        @Override // com.google.android.flexbox.b
        public final int aw() {
            return this.l;
        }

        @Override // com.google.android.flexbox.b
        public final int az() {
            return this.n;
        }

        @Override // com.google.android.flexbox.b
        public final float b() {
            return this.f;
        }

        @Override // com.google.android.flexbox.b
        public final int d() {
            return this.k;
        }

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

        @Override // com.google.android.flexbox.b
        public final int getHeight() {
            return ((ViewGroup.MarginLayoutParams) this).height;
        }

        @Override // com.google.android.flexbox.b
        public final int getOrder() {
            return 1;
        }

        @Override // com.google.android.flexbox.b
        public final int getWidth() {
            return ((ViewGroup.MarginLayoutParams) this).width;
        }

        @Override // com.google.android.flexbox.b
        public final int h() {
            return ((ViewGroup.MarginLayoutParams) this).topMargin;
        }

        @Override // com.google.android.flexbox.b
        public final void p(int i) {
            this.l = i;
        }

        @Override // com.google.android.flexbox.b
        public final float u() {
            return this.e;
        }

        @Override // android.os.Parcelable
        public final void writeToParcel(Parcel parcel, int i) {
            parcel.writeFloat(this.e);
            parcel.writeFloat(this.f);
            parcel.writeInt(this.i);
            parcel.writeFloat(this.j);
            parcel.writeInt(this.k);
            parcel.writeInt(this.l);
            parcel.writeInt(this.m);
            parcel.writeInt(this.n);
            parcel.writeByte(this.o ? (byte) 1 : (byte) 0);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).bottomMargin);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).leftMargin);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).rightMargin);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).topMargin);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).height);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).width);
        }
    }

    public static class d {
        public int a;
        public boolean b;
        public int c;
        public int d;
        public int e;
        public int f;
        public int g;
        public int h;
        public int i;
        public boolean j;

        public final String toString() {
            StringBuilder sb = new StringBuilder("LayoutState{mAvailable=");
            sb.append(this.a);
            sb.append(", mFlexLinePosition=");
            sb.append(this.c);
            sb.append(", mPosition=");
            sb.append(this.d);
            sb.append(", mOffset=");
            sb.append(this.e);
            sb.append(", mScrollingOffset=");
            sb.append(this.f);
            sb.append(", mLastScrollDelta=");
            sb.append(this.g);
            sb.append(", mItemDirection=");
            sb.append(this.h);
            sb.append(", mLayoutDirection=");
            return vw2.n(sb, this.i, '}');
        }
    }

    public static class e implements Parcelable {
        public static final Parcelable.Creator<e> CREATOR = new a();
        public int a;
        public int b;

        public class a implements Parcelable.Creator<e> {
            @Override // android.os.Parcelable.Creator
            public final e createFromParcel(Parcel parcel) {
                e eVar = new e();
                eVar.a = parcel.readInt();
                eVar.b = parcel.readInt();
                return eVar;
            }

            @Override // android.os.Parcelable.Creator
            public final e[] newArray(int i) {
                return new e[i];
            }
        }

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

        public final String toString() {
            StringBuilder sb = new StringBuilder("SavedState{mAnchorPosition=");
            sb.append(this.a);
            sb.append(", mAnchorOffset=");
            return vw2.n(sb, this.b, '}');
        }

        @Override // android.os.Parcelable
        public final void writeToParcel(Parcel parcel, int i) {
            parcel.writeInt(this.a);
            parcel.writeInt(this.b);
        }
    }

    public FlexboxLayoutManager(Context context, AttributeSet attributeSet, int i, int i2) {
        b bVar = new b();
        this.n = bVar;
        this.r = -1;
        this.s = Integer.MIN_VALUE;
        this.t = Integer.MIN_VALUE;
        this.u = Integer.MIN_VALUE;
        this.v = new SparseArray();
        this.y = -1;
        this.z = new d.b();
        RecyclerView.o.d properties = RecyclerView.o.getProperties(context, attributeSet, i, i2);
        int i3 = properties.a;
        if (i3 != 0) {
            if (i3 == 1) {
                if (properties.c) {
                    ae(3);
                } else {
                    ae(2);
                }
            }
        } else if (properties.c) {
            ae(1);
        } else {
            ae(0);
        }
        int i4 = this.b;
        if (i4 != 1) {
            if (i4 == 0) {
                removeAllViews();
                this.i.clear();
                b.b(bVar);
                bVar.d = 0;
            }
            this.b = 1;
            this.o = null;
            this.p = null;
            requestLayout();
        }
        if (this.c != 4) {
            removeAllViews();
            this.i.clear();
            b.b(bVar);
            bVar.d = 0;
            this.c = 4;
            requestLayout();
        }
        this.w = context;
    }

    public static boolean l(int i, int i2, int i3) {
        int mode = View.MeasureSpec.getMode(i2);
        int size = View.MeasureSpec.getSize(i2);
        if (i3 > 0 && i != i3) {
            return false;
        }
        if (mode == Integer.MIN_VALUE) {
            return size >= i;
        }
        if (mode != 0) {
            return mode == 1073741824 && size == i;
        }
        return true;
    }

    @Override // com.google.android.flexbox.a
    public final void a(View view, int i, int i2, com.google.android.flexbox.c cVar) {
        calculateItemDecorationsForChild(view, aa);
        if (j()) {
            int rightDecorationWidth = getRightDecorationWidth(view) + getLeftDecorationWidth(view);
            cVar.e += rightDecorationWidth;
            cVar.f += rightDecorationWidth;
            return;
        }
        int bottomDecorationHeight = getBottomDecorationHeight(view) + getTopDecorationHeight(view);
        cVar.e += bottomDecorationHeight;
        cVar.f += bottomDecorationHeight;
    }

    /* JADX WARN: Removed duplicated region for block: B:70:0x01f0  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x01f7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int aa(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        int iR;
        int i2;
        if (getChildCount() != 0 && i != 0) {
            q();
            this.m.j = true;
            boolean z = !j() && this.e;
            int i3 = (!z ? i > 0 : i < 0) ? -1 : 1;
            int iAbs = Math.abs(i);
            this.m.i = i3;
            boolean zJ = j();
            int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(getWidth(), getWidthMode());
            int iMakeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(getHeight(), getHeightMode());
            boolean z2 = !zJ && this.e;
            com.google.android.flexbox.d dVar = this.j;
            if (i3 == 1) {
                View childAt = getChildAt(getChildCount() - 1);
                if (childAt != null) {
                    this.m.e = this.o.d(childAt);
                    int position = getPosition(childAt);
                    View viewV = v(childAt, (com.google.android.flexbox.c) this.i.get(dVar.c[position]));
                    d dVar2 = this.m;
                    dVar2.h = 1;
                    int i4 = position + 1;
                    dVar2.d = i4;
                    int[] iArr = dVar.c;
                    if (iArr.length <= i4) {
                        dVar2.c = -1;
                    } else {
                        dVar2.c = iArr[i4];
                    }
                    if (z2) {
                        dVar2.e = this.o.g(viewV);
                        this.m.f = this.o.m() + (-this.o.g(viewV));
                        d dVar3 = this.m;
                        dVar3.f = Math.max(dVar3.f, 0);
                    } else {
                        dVar2.e = this.o.d(viewV);
                        this.m.f = this.o.d(viewV) - this.o.i();
                    }
                    int i5 = this.m.c;
                    if ((i5 == -1 || i5 > this.i.size() - 1) && this.m.d <= this.l.b()) {
                        d dVar4 = this.m;
                        int i6 = iAbs - dVar4.f;
                        d.b bVar = this.z;
                        bVar.a = null;
                        bVar.b = 0;
                        if (i6 > 0) {
                            if (zJ) {
                                this.j.b(bVar, iMakeMeasureSpec, iMakeMeasureSpec2, i6, dVar4.d, -1, this.i);
                            } else {
                                this.j.b(bVar, iMakeMeasureSpec2, iMakeMeasureSpec, i6, dVar4.d, -1, this.i);
                                iMakeMeasureSpec2 = iMakeMeasureSpec2;
                                iMakeMeasureSpec = iMakeMeasureSpec;
                            }
                            dVar.h(iMakeMeasureSpec, iMakeMeasureSpec2, this.m.d);
                            dVar.u(this.m.d);
                        }
                    }
                    d dVar5 = this.m;
                    dVar5.a = iAbs - dVar5.f;
                }
                d dVar6 = this.m;
                iR = r(wVar, acVar, dVar6) + dVar6.f;
                if (iR >= 0) {
                    if (z) {
                        i2 = iAbs > iR ? (-i3) * iR : i;
                    } else if (iAbs > iR) {
                        i2 = i3 * iR;
                    }
                    this.o.r(-i2);
                    this.m.g = i2;
                    return i2;
                }
            } else {
                View childAt2 = getChildAt(0);
                if (childAt2 != null) {
                    this.m.e = this.o.g(childAt2);
                    int position2 = getPosition(childAt2);
                    View viewT = t(childAt2, (com.google.android.flexbox.c) this.i.get(dVar.c[position2]));
                    d dVar7 = this.m;
                    dVar7.h = 1;
                    int i7 = dVar.c[position2];
                    if (i7 == -1) {
                        i7 = 0;
                    }
                    if (i7 > 0) {
                        this.m.d = position2 - ((com.google.android.flexbox.c) this.i.get(i7 - 1)).h;
                    } else {
                        dVar7.d = -1;
                    }
                    d dVar8 = this.m;
                    dVar8.c = i7 > 0 ? i7 - 1 : 0;
                    if (z2) {
                        dVar8.e = this.o.d(viewT);
                        this.m.f = this.o.d(viewT) - this.o.i();
                        d dVar9 = this.m;
                        dVar9.f = Math.max(dVar9.f, 0);
                    } else {
                        dVar8.e = this.o.g(viewT);
                        this.m.f = this.o.m() + (-this.o.g(viewT));
                    }
                    d dVar52 = this.m;
                    dVar52.a = iAbs - dVar52.f;
                }
                d dVar62 = this.m;
                iR = r(wVar, acVar, dVar62) + dVar62.f;
                if (iR >= 0) {
                }
            }
        }
        return 0;
    }

    public final int ab(int i) {
        if (getChildCount() == 0 || i == 0) {
            return 0;
        }
        q();
        boolean zJ = j();
        View view = this.x;
        int width = zJ ? view.getWidth() : view.getHeight();
        int width2 = zJ ? getWidth() : getHeight();
        int layoutDirection = getLayoutDirection();
        b bVar = this.n;
        if (layoutDirection == 1) {
            int iAbs = Math.abs(i);
            if (i < 0) {
                return -Math.min((width2 + bVar.d) - width, iAbs);
            }
            int i2 = bVar.d;
            if (i2 + i > 0) {
                return -i2;
            }
        } else {
            if (i > 0) {
                return Math.min((width2 - bVar.d) - width, i);
            }
            int i3 = bVar.d;
            if (i3 + i < 0) {
                return -i3;
            }
        }
        return i;
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0067  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x00e2  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void ac(RecyclerView.w wVar, d dVar) {
        int childCount;
        int i;
        int childCount2;
        int i2;
        View childAt;
        int i3;
        if (dVar.j) {
            int i4 = dVar.i;
            com.google.android.flexbox.d dVar2 = this.j;
            int i5 = -1;
            if (i4 == -1) {
                if (dVar.f < 0 || (childCount2 = getChildCount()) == 0 || (childAt = getChildAt(childCount2 - 1)) == null || (i3 = dVar2.c[getPosition(childAt)]) == -1) {
                    return;
                }
                com.google.android.flexbox.c cVar = (com.google.android.flexbox.c) this.i.get(i3);
                int i6 = i2;
                while (true) {
                    if (i6 < 0) {
                        break;
                    }
                    View childAt2 = getChildAt(i6);
                    if (childAt2 != null) {
                        int i7 = dVar.f;
                        if (!j() && this.e) {
                            if (this.o.d(childAt2) > i7) {
                                break;
                            }
                        } else {
                            if (this.o.g(childAt2) < this.o.h() - i7) {
                                break;
                            }
                            if (cVar.o != getPosition(childAt2)) {
                                continue;
                            } else if (i3 <= 0) {
                                childCount2 = i6;
                                break;
                            } else {
                                i3 += dVar.i;
                                cVar = (com.google.android.flexbox.c) this.i.get(i3);
                                childCount2 = i6;
                            }
                        }
                    }
                    i6--;
                }
                while (i2 >= childCount2) {
                    removeAndRecycleViewAt(i2, wVar);
                    i2--;
                }
                return;
            }
            if (dVar.f >= 0 && (childCount = getChildCount()) != 0) {
                int i8 = 0;
                View childAt3 = getChildAt(0);
                if (childAt3 == null || (i = dVar2.c[getPosition(childAt3)]) == -1) {
                    return;
                }
                com.google.android.flexbox.c cVar2 = (com.google.android.flexbox.c) this.i.get(i);
                while (true) {
                    if (i8 >= childCount) {
                        break;
                    }
                    View childAt4 = getChildAt(i8);
                    if (childAt4 != null) {
                        int i9 = dVar.f;
                        if (!j() && this.e) {
                            if (this.o.h() - this.o.g(childAt4) > i9) {
                                break;
                            }
                        } else {
                            if (this.o.d(childAt4) > i9) {
                                break;
                            }
                            if (cVar2.p != getPosition(childAt4)) {
                                continue;
                            } else if (i >= this.i.size() - 1) {
                                i5 = i8;
                                break;
                            } else {
                                i += dVar.i;
                                cVar2 = (com.google.android.flexbox.c) this.i.get(i);
                                i5 = i8;
                            }
                        }
                    }
                    i8++;
                }
                while (i5 >= 0) {
                    removeAndRecycleViewAt(i5, wVar);
                    i5--;
                }
            }
        }
    }

    public final void ad() {
        int heightMode = j() ? getHeightMode() : getWidthMode();
        this.m.b = heightMode == 0 || heightMode == Integer.MIN_VALUE;
    }

    public final void ae(int i) {
        if (this.a != i) {
            removeAllViews();
            this.a = i;
            this.o = null;
            this.p = null;
            this.i.clear();
            b bVar = this.n;
            b.b(bVar);
            bVar.d = 0;
            requestLayout();
        }
    }

    public final boolean af(View view, int i, int i2, c cVar) {
        return (!view.isLayoutRequested() && isMeasurementCacheEnabled() && l(view.getWidth(), i, ((ViewGroup.MarginLayoutParams) cVar).width) && l(view.getHeight(), i2, ((ViewGroup.MarginLayoutParams) cVar).height)) ? false : true;
    }

    public final void ag(int i) {
        View viewW = w(getChildCount() - 1, -1);
        if (i >= (viewW != null ? getPosition(viewW) : -1)) {
            return;
        }
        int childCount = getChildCount();
        com.google.android.flexbox.d dVar = this.j;
        dVar.j(childCount);
        dVar.k(childCount);
        dVar.i(childCount);
        if (i >= dVar.c.length) {
            return;
        }
        this.y = i;
        View childAt = getChildAt(0);
        if (childAt == null) {
            return;
        }
        this.r = getPosition(childAt);
        if (j() || !this.e) {
            this.s = this.o.g(childAt) - this.o.m();
        } else {
            this.s = this.o.j() + this.o.d(childAt);
        }
    }

    public final void ah(b bVar, boolean z, boolean z2) {
        int i;
        if (z2) {
            ad();
        } else {
            this.m.b = false;
        }
        if (j() || !this.e) {
            this.m.a = this.o.i() - bVar.c;
        } else {
            this.m.a = bVar.c - getPaddingRight();
        }
        d dVar = this.m;
        dVar.d = bVar.a;
        dVar.h = 1;
        dVar.i = 1;
        dVar.e = bVar.c;
        dVar.f = Integer.MIN_VALUE;
        dVar.c = bVar.b;
        if (!z || this.i.size() <= 1 || (i = bVar.b) < 0 || i >= this.i.size() - 1) {
            return;
        }
        com.google.android.flexbox.c cVar = (com.google.android.flexbox.c) this.i.get(bVar.b);
        d dVar2 = this.m;
        dVar2.c++;
        dVar2.d += cVar.h;
    }

    public final void ai(b bVar, boolean z, boolean z2) {
        if (z2) {
            ad();
        } else {
            this.m.b = false;
        }
        if (j() || !this.e) {
            this.m.a = bVar.c - this.o.m();
        } else {
            this.m.a = (this.x.getWidth() - bVar.c) - this.o.m();
        }
        d dVar = this.m;
        dVar.d = bVar.a;
        dVar.h = 1;
        dVar.i = -1;
        dVar.e = bVar.c;
        dVar.f = Integer.MIN_VALUE;
        int i = bVar.b;
        dVar.c = i;
        if (!z || i <= 0) {
            return;
        }
        int size = this.i.size();
        int i2 = bVar.b;
        if (size > i2) {
            com.google.android.flexbox.c cVar = (com.google.android.flexbox.c) this.i.get(i2);
            d dVar2 = this.m;
            dVar2.c--;
            dVar2.d -= cVar.h;
        }
    }

    @Override // com.google.android.flexbox.a
    public final int b(int i, int i2, int i3) {
        return RecyclerView.o.getChildMeasureSpec(getWidth(), getWidthMode(), i2, i3, canScrollHorizontally());
    }

    @Override // com.google.android.flexbox.a
    public final View c(int i) {
        View view = (View) this.v.get(i);
        return view != null ? view : this.k.d(i);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final boolean canScrollHorizontally() {
        if (this.b == 0) {
            return j();
        }
        if (!j()) {
            return true;
        }
        int width = getWidth();
        View view = this.x;
        return width > (view != null ? view.getWidth() : 0);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final boolean canScrollVertically() {
        if (this.b == 0) {
            return !j();
        }
        if (!j()) {
            int height = getHeight();
            View view = this.x;
            if (height <= (view != null ? view.getHeight() : 0)) {
                return false;
            }
        }
        return true;
    }

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

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int computeHorizontalScrollExtent(RecyclerView.ac acVar) {
        return n(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int computeHorizontalScrollOffset(RecyclerView.ac acVar) {
        return o(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int computeHorizontalScrollRange(RecyclerView.ac acVar) {
        return p(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.ab.b
    public final PointF computeScrollVectorForPosition(int i) {
        View childAt;
        if (getChildCount() == 0 || (childAt = getChildAt(0)) == null) {
            return null;
        }
        int i2 = i < getPosition(childAt) ? -1 : 1;
        return j() ? new PointF(0.0f, i2) : new PointF(i2, 0.0f);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int computeVerticalScrollExtent(RecyclerView.ac acVar) {
        return n(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int computeVerticalScrollOffset(RecyclerView.ac acVar) {
        return o(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int computeVerticalScrollRange(RecyclerView.ac acVar) {
        return p(acVar);
    }

    @Override // com.google.android.flexbox.a
    public final int d(int i, int i2, int i3) {
        return RecyclerView.o.getChildMeasureSpec(getHeight(), getHeightMode(), i2, i3, canScrollVertically());
    }

    @Override // com.google.android.flexbox.a
    public final int e(View view) {
        int leftDecorationWidth;
        int rightDecorationWidth;
        if (j()) {
            leftDecorationWidth = getTopDecorationHeight(view);
            rightDecorationWidth = getBottomDecorationHeight(view);
        } else {
            leftDecorationWidth = getLeftDecorationWidth(view);
            rightDecorationWidth = getRightDecorationWidth(view);
        }
        return rightDecorationWidth + leftDecorationWidth;
    }

    @Override // com.google.android.flexbox.a
    public final void f(com.google.android.flexbox.c cVar) {
    }

    @Override // com.google.android.flexbox.a
    public final View g(int i) {
        return c(i);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final RecyclerView.p generateDefaultLayoutParams() {
        c cVar = new c(-2, -2);
        cVar.e = 0.0f;
        cVar.f = 1.0f;
        cVar.i = -1;
        cVar.j = -1.0f;
        cVar.m = 16777215;
        cVar.n = 16777215;
        return cVar;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final RecyclerView.p generateLayoutParams(Context context, AttributeSet attributeSet) {
        c cVar = new c(context, attributeSet);
        cVar.e = 0.0f;
        cVar.f = 1.0f;
        cVar.i = -1;
        cVar.j = -1.0f;
        cVar.m = 16777215;
        cVar.n = 16777215;
        return cVar;
    }

    @Override // com.google.android.flexbox.a
    public final int getAlignContent() {
        return 5;
    }

    @Override // com.google.android.flexbox.a
    public final int getAlignItems() {
        return this.c;
    }

    @Override // com.google.android.flexbox.a
    public final int getFlexDirection() {
        return this.a;
    }

    @Override // com.google.android.flexbox.a
    public final int getFlexItemCount() {
        return this.l.b();
    }

    @Override // com.google.android.flexbox.a
    public final List getFlexLinesInternal() {
        return this.i;
    }

    @Override // com.google.android.flexbox.a
    public final int getFlexWrap() {
        return this.b;
    }

    @Override // com.google.android.flexbox.a
    public final int getLargestMainSize() {
        if (this.i.size() == 0) {
            return 0;
        }
        int size = this.i.size();
        int iMax = Integer.MIN_VALUE;
        for (int i = 0; i < size; i++) {
            iMax = Math.max(iMax, ((com.google.android.flexbox.c) this.i.get(i)).e);
        }
        return iMax;
    }

    @Override // com.google.android.flexbox.a
    public final int getMaxLine() {
        return this.d;
    }

    @Override // com.google.android.flexbox.a
    public final int getSumOfCrossSize() {
        int size = this.i.size();
        int i = 0;
        for (int i2 = 0; i2 < size; i2++) {
            i += ((com.google.android.flexbox.c) this.i.get(i2)).g;
        }
        return i;
    }

    @Override // com.google.android.flexbox.a
    public final void h(int i, View view) {
        this.v.put(i, view);
    }

    @Override // com.google.android.flexbox.a
    public final int i(View view, int i, int i2) {
        int topDecorationHeight;
        int bottomDecorationHeight;
        if (j()) {
            topDecorationHeight = getLeftDecorationWidth(view);
            bottomDecorationHeight = getRightDecorationWidth(view);
        } else {
            topDecorationHeight = getTopDecorationHeight(view);
            bottomDecorationHeight = getBottomDecorationHeight(view);
        }
        return bottomDecorationHeight + topDecorationHeight;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final boolean isAutoMeasureEnabled() {
        return true;
    }

    @Override // com.google.android.flexbox.a
    public final boolean j() {
        int i = this.a;
        return i == 0 || i == 1;
    }

    public final int n(RecyclerView.ac acVar) {
        if (getChildCount() == 0) {
            return 0;
        }
        int iB = acVar.b();
        q();
        View viewS = s(iB);
        View viewU = u(iB);
        if (acVar.b() == 0 || viewS == null || viewU == null) {
            return 0;
        }
        return Math.min(this.o.n(), this.o.d(viewU) - this.o.g(viewS));
    }

    public final int o(RecyclerView.ac acVar) {
        if (getChildCount() == 0) {
            return 0;
        }
        int iB = acVar.b();
        View viewS = s(iB);
        View viewU = u(iB);
        if (acVar.b() == 0 || viewS == null || viewU == null) {
            return 0;
        }
        int position = getPosition(viewS);
        int position2 = getPosition(viewU);
        int iAbs = Math.abs(this.o.d(viewU) - this.o.g(viewS));
        int i = this.j.c[position];
        if (i == 0 || i == -1) {
            return 0;
        }
        return Math.round((i * (iAbs / ((r3[position2] - i) + 1))) + (this.o.m() - this.o.g(viewS)));
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onAdapterChanged(RecyclerView.g gVar, RecyclerView.g gVar2) {
        removeAllViews();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onAttachedToWindow(RecyclerView recyclerView) {
        super.onAttachedToWindow(recyclerView);
        this.x = (View) recyclerView.getParent();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onDetachedFromWindow(RecyclerView recyclerView, RecyclerView.w wVar) {
        onDetachedFromWindow(recyclerView);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsAdded(RecyclerView recyclerView, int i, int i2) {
        super.onItemsAdded(recyclerView, i, i2);
        ag(i);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsMoved(RecyclerView recyclerView, int i, int i2, int i3) {
        super.onItemsMoved(recyclerView, i, i2, i3);
        ag(Math.min(i, i2));
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsRemoved(RecyclerView recyclerView, int i, int i2) {
        super.onItemsRemoved(recyclerView, i, i2);
        ag(i);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsUpdated(RecyclerView recyclerView, int i, int i2, Object obj) {
        super.onItemsUpdated(recyclerView, i, i2, obj);
        ag(i);
    }

    /* JADX WARN: Removed duplicated region for block: B:111:0x01ad  */
    /* JADX WARN: Removed duplicated region for block: B:156:0x026e  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x00ee  */
    @Override // androidx.recyclerview.widget.RecyclerView.o
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onLayoutChildren(RecyclerView.w wVar, RecyclerView.ac acVar) {
        int i;
        View childAt;
        boolean z;
        int i2;
        boolean z2;
        int i3;
        int i4;
        int i5;
        this.k = wVar;
        this.l = acVar;
        int iB = acVar.b();
        if (iB == 0 && acVar.g) {
            return;
        }
        int layoutDirection = getLayoutDirection();
        int i6 = this.a;
        if (i6 == 0) {
            this.e = layoutDirection == 1;
            this.f = this.b == 2;
        } else if (i6 == 1) {
            this.e = layoutDirection != 1;
            this.f = this.b == 2;
        } else if (i6 == 2) {
            boolean z3 = layoutDirection == 1;
            this.e = z3;
            if (this.b == 2) {
                this.e = !z3;
            }
            this.f = false;
        } else if (i6 != 3) {
            this.e = false;
            this.f = false;
        } else {
            boolean z4 = layoutDirection == 1;
            this.e = z4;
            if (this.b == 2) {
                this.e = !z4;
            }
            this.f = true;
        }
        q();
        if (this.m == null) {
            d dVar = new d();
            dVar.h = 1;
            dVar.i = 1;
            this.m = dVar;
        }
        com.google.android.flexbox.d dVar2 = this.j;
        dVar2.j(iB);
        dVar2.k(iB);
        dVar2.i(iB);
        this.m.j = false;
        e eVar = this.q;
        if (eVar != null && (i5 = eVar.a) >= 0 && i5 < iB) {
            this.r = i5;
        }
        b bVar = this.n;
        if (!bVar.f || this.r != -1 || eVar != null) {
            b.b(bVar);
            e eVar2 = this.q;
            if (acVar.g || (i = this.r) == -1) {
                if (getChildCount() != 0) {
                    View viewU = bVar.e ? u(acVar.b()) : s(acVar.b());
                    if (viewU != null) {
                        FlexboxLayoutManager flexboxLayoutManager = FlexboxLayoutManager.this;
                        ak akVar = flexboxLayoutManager.b == 0 ? flexboxLayoutManager.p : flexboxLayoutManager.o;
                        if (flexboxLayoutManager.j() || !flexboxLayoutManager.e) {
                            if (bVar.e) {
                                bVar.c = akVar.o() + akVar.d(viewU);
                            } else {
                                bVar.c = akVar.g(viewU);
                            }
                        } else if (bVar.e) {
                            bVar.c = akVar.o() + akVar.g(viewU);
                        } else {
                            bVar.c = akVar.d(viewU);
                        }
                        int position = flexboxLayoutManager.getPosition(viewU);
                        bVar.a = position;
                        bVar.g = false;
                        int[] iArr = flexboxLayoutManager.j.c;
                        if (position == -1) {
                            position = 0;
                        }
                        int i7 = iArr[position];
                        if (i7 == -1) {
                            i7 = 0;
                        }
                        bVar.b = i7;
                        int size = flexboxLayoutManager.i.size();
                        int i8 = bVar.b;
                        if (size > i8) {
                            bVar.a = ((com.google.android.flexbox.c) flexboxLayoutManager.i.get(i8)).o;
                        }
                        if (!acVar.g && supportsPredictiveItemAnimations() && (this.o.g(viewU) >= this.o.i() || this.o.d(viewU) < this.o.m())) {
                            bVar.c = bVar.e ? this.o.i() : this.o.m();
                        }
                    } else {
                        b.a(bVar);
                        bVar.a = 0;
                        bVar.b = 0;
                    }
                    bVar.f = true;
                }
            } else if (i < 0 || i >= acVar.b()) {
                this.r = -1;
                this.s = Integer.MIN_VALUE;
                if (getChildCount() != 0) {
                }
            } else {
                int i9 = this.r;
                bVar.a = i9;
                bVar.b = dVar2.c[i9];
                e eVar3 = this.q;
                if (eVar3 != null) {
                    int iB2 = acVar.b();
                    int i10 = eVar3.a;
                    if (i10 >= 0 && i10 < iB2) {
                        bVar.c = this.o.m() + eVar2.b;
                        bVar.g = true;
                        bVar.b = -1;
                    } else if (this.s == Integer.MIN_VALUE) {
                        View viewFindViewByPosition = findViewByPosition(this.r);
                        if (viewFindViewByPosition == null) {
                            if (getChildCount() > 0 && (childAt = getChildAt(0)) != null) {
                                bVar.e = this.r < getPosition(childAt);
                            }
                            b.a(bVar);
                        } else if (this.o.e(viewFindViewByPosition) > this.o.n()) {
                            b.a(bVar);
                        } else if (this.o.g(viewFindViewByPosition) - this.o.m() < 0) {
                            bVar.c = this.o.m();
                            bVar.e = false;
                        } else if (this.o.i() - this.o.d(viewFindViewByPosition) < 0) {
                            bVar.c = this.o.i();
                            bVar.e = true;
                        } else {
                            bVar.c = bVar.e ? this.o.o() + this.o.d(viewFindViewByPosition) : this.o.g(viewFindViewByPosition);
                        }
                    } else if (j() || !this.e) {
                        bVar.c = this.o.m() + this.s;
                    } else {
                        bVar.c = this.s - this.o.j();
                    }
                    bVar.f = true;
                }
            }
        }
        detachAndScrapAttachedViews(wVar);
        if (bVar.e) {
            ai(bVar, false, true);
        } else {
            ah(bVar, false, true);
        }
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(getWidth(), getWidthMode());
        int iMakeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(getHeight(), getHeightMode());
        int width = getWidth();
        int height = getHeight();
        boolean zJ = j();
        Context context = this.w;
        if (zJ) {
            int i11 = this.t;
            z = (i11 == Integer.MIN_VALUE || i11 == width) ? false : true;
            d dVar3 = this.m;
            i2 = dVar3.b ? context.getResources().getDisplayMetrics().heightPixels : dVar3.a;
        } else {
            int i12 = this.u;
            z = (i12 == Integer.MIN_VALUE || i12 == height) ? false : true;
            d dVar4 = this.m;
            i2 = dVar4.b ? context.getResources().getDisplayMetrics().widthPixels : dVar4.a;
        }
        int i13 = i2;
        this.t = width;
        this.u = height;
        int i14 = this.y;
        d.b bVar2 = this.z;
        if (i14 != -1 || (this.r == -1 && !z)) {
            int iMin = i14 != -1 ? Math.min(i14, bVar.a) : bVar.a;
            bVar2.a = null;
            bVar2.b = 0;
            if (j()) {
                if (this.i.size() > 0) {
                    dVar2.d(iMin, this.i);
                    this.j.b(this.z, iMakeMeasureSpec, iMakeMeasureSpec2, i13, iMin, bVar.a, this.i);
                } else {
                    dVar2.i(iB);
                    this.j.b(this.z, iMakeMeasureSpec, iMakeMeasureSpec2, i13, 0, -1, this.i);
                }
            } else if (this.i.size() > 0) {
                dVar2.d(iMin, this.i);
                int i15 = iMin;
                this.j.b(this.z, iMakeMeasureSpec2, iMakeMeasureSpec, i13, i15, bVar.a, this.i);
                iMakeMeasureSpec2 = iMakeMeasureSpec2;
                iMakeMeasureSpec = iMakeMeasureSpec;
                iMin = i15;
            } else {
                dVar2.i(iB);
                this.j.b(this.z, iMakeMeasureSpec2, iMakeMeasureSpec, i13, 0, -1, this.i);
                iMakeMeasureSpec2 = iMakeMeasureSpec2;
                iMakeMeasureSpec = iMakeMeasureSpec;
            }
            this.i = bVar2.a;
            dVar2.h(iMakeMeasureSpec, iMakeMeasureSpec2, iMin);
            dVar2.u(iMin);
        } else if (!bVar.e) {
            this.i.clear();
            bVar2.a = null;
            bVar2.b = 0;
            if (j()) {
                this.j.b(this.z, iMakeMeasureSpec, iMakeMeasureSpec2, i13, 0, bVar.a, this.i);
            } else {
                this.j.b(this.z, iMakeMeasureSpec2, iMakeMeasureSpec, i13, 0, bVar.a, this.i);
                iMakeMeasureSpec2 = iMakeMeasureSpec2;
                iMakeMeasureSpec = iMakeMeasureSpec;
            }
            this.i = bVar2.a;
            dVar2.h(iMakeMeasureSpec, iMakeMeasureSpec2, 0);
            dVar2.u(0);
            int i16 = dVar2.c[bVar.a];
            bVar.b = i16;
            this.m.c = i16;
        }
        r(wVar, acVar, this.m);
        if (bVar.e) {
            i4 = this.m.e;
            z2 = true;
            ah(bVar, true, false);
            r(wVar, acVar, this.m);
            i3 = this.m.e;
        } else {
            z2 = true;
            i3 = this.m.e;
            ai(bVar, true, false);
            r(wVar, acVar, this.m);
            i4 = this.m.e;
        }
        if (getChildCount() > 0) {
            if (bVar.e) {
                z(y(i3, wVar, acVar, z2) + i4, wVar, acVar, false);
            } else {
                y(z(i4, wVar, acVar, z2) + i3, wVar, acVar, false);
            }
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onLayoutCompleted(RecyclerView.ac acVar) {
        this.q = null;
        this.r = -1;
        this.s = Integer.MIN_VALUE;
        this.y = -1;
        b.b(this.n);
        this.v.clear();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof e) {
            this.q = (e) parcelable;
            requestLayout();
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final Parcelable onSaveInstanceState() {
        e eVar = this.q;
        if (eVar != null) {
            e eVar2 = new e();
            eVar2.a = eVar.a;
            eVar2.b = eVar.b;
            return eVar2;
        }
        e eVar3 = new e();
        if (getChildCount() <= 0) {
            eVar3.a = -1;
            return eVar3;
        }
        View childAt = getChildAt(0);
        eVar3.a = getPosition(childAt);
        eVar3.b = this.o.g(childAt) - this.o.m();
        return eVar3;
    }

    public final int p(RecyclerView.ac acVar) {
        if (getChildCount() != 0) {
            int iB = acVar.b();
            View viewS = s(iB);
            View viewU = u(iB);
            if (acVar.b() != 0 && viewS != null && viewU != null) {
                View viewW = w(0, getChildCount());
                int position = viewW == null ? -1 : getPosition(viewW);
                return (int) ((Math.abs(this.o.d(viewU) - this.o.g(viewS)) / (((w(getChildCount() - 1, -1) != null ? getPosition(r4) : -1) - position) + 1)) * acVar.b());
            }
        }
        return 0;
    }

    public final void q() {
        if (this.o != null) {
            return;
        }
        if (j()) {
            if (this.b == 0) {
                this.o = ak.a(this);
                this.p = ak.c(this);
                return;
            } else {
                this.o = ak.c(this);
                this.p = ak.a(this);
                return;
            }
        }
        if (this.b == 0) {
            this.o = ak.c(this);
            this.p = ak.a(this);
        } else {
            this.o = ak.a(this);
            this.p = ak.c(this);
        }
    }

    public final int r(RecyclerView.w wVar, RecyclerView.ac acVar, d dVar) {
        int i;
        int i2;
        boolean z;
        int i3;
        int i4;
        boolean z2;
        Rect rect;
        int i5;
        int i6;
        int i7;
        float topDecorationHeight;
        boolean z3;
        com.google.android.flexbox.d dVar2;
        int i8;
        int i9;
        int i10;
        Rect rect2;
        int i11;
        int i12 = dVar.f;
        if (i12 != Integer.MIN_VALUE) {
            int i13 = dVar.a;
            if (i13 < 0) {
                dVar.f = i12 + i13;
            }
            ac(wVar, dVar);
        }
        int i14 = dVar.a;
        boolean zJ = j();
        int i15 = i14;
        int i16 = 0;
        while (true) {
            if (i15 <= 0 && !this.m.b) {
                break;
            }
            List list = this.i;
            int i17 = dVar.d;
            if (i17 < 0 || i17 >= acVar.b() || (i = dVar.c) < 0 || i >= list.size()) {
                break;
            }
            com.google.android.flexbox.c cVar = (com.google.android.flexbox.c) this.i.get(dVar.c);
            dVar.d = cVar.o;
            boolean zJ2 = j();
            b bVar = this.n;
            Rect rect3 = aa;
            com.google.android.flexbox.d dVar3 = this.j;
            if (zJ2) {
                int paddingLeft = getPaddingLeft();
                int paddingRight = getPaddingRight();
                int width = getWidth();
                int i18 = dVar.e;
                if (dVar.i == -1) {
                    i18 -= cVar.g;
                }
                int i19 = dVar.d;
                float f = bVar.d;
                float rightDecorationWidth = paddingLeft - f;
                float leftDecorationWidth = (width - paddingRight) - f;
                float fMax = Math.max(0.0f, 0.0f);
                int i20 = cVar.h;
                i2 = i14;
                int i21 = i18;
                int i22 = i19;
                int i23 = 0;
                while (i22 < i19 + i20) {
                    int i24 = i19;
                    View viewC = c(i22);
                    if (viewC == null) {
                        i8 = i23;
                        z3 = zJ;
                        dVar2 = dVar3;
                        i9 = i20;
                        i10 = i22;
                        rect2 = rect3;
                        i11 = i24;
                    } else {
                        z3 = zJ;
                        if (dVar.i == 1) {
                            calculateItemDecorationsForChild(viewC, rect3);
                            addView(viewC);
                        } else {
                            calculateItemDecorationsForChild(viewC, rect3);
                            addView(viewC, i23);
                            i23++;
                        }
                        dVar2 = dVar3;
                        long j = dVar3.d[i22];
                        int i25 = (int) j;
                        int i26 = (int) (j >> 32);
                        if (af(viewC, i25, i26, (c) viewC.getLayoutParams())) {
                            viewC.measure(i25, i26);
                        }
                        float leftDecorationWidth2 = rightDecorationWidth + getLeftDecorationWidth(viewC) + ((ViewGroup.MarginLayoutParams) r6).leftMargin;
                        float rightDecorationWidth2 = leftDecorationWidth - (getRightDecorationWidth(viewC) + ((ViewGroup.MarginLayoutParams) r6).rightMargin);
                        int topDecorationHeight2 = getTopDecorationHeight(viewC) + i21;
                        if (this.e) {
                            int iRound = Math.round(rightDecorationWidth2) - viewC.getMeasuredWidth();
                            Rect rect4 = rect3;
                            int iRound2 = Math.round(rightDecorationWidth2);
                            int measuredHeight = viewC.getMeasuredHeight() + topDecorationHeight2;
                            i9 = i20;
                            i10 = i22;
                            rect2 = rect4;
                            i8 = i23;
                            i11 = i24;
                            this.j.o(viewC, cVar, iRound, topDecorationHeight2, iRound2, measuredHeight);
                        } else {
                            i8 = i23;
                            i9 = i20;
                            i10 = i22;
                            rect2 = rect3;
                            i11 = i24;
                            this.j.o(viewC, cVar, Math.round(leftDecorationWidth2), topDecorationHeight2, viewC.getMeasuredWidth() + Math.round(leftDecorationWidth2), viewC.getMeasuredHeight() + topDecorationHeight2);
                        }
                        leftDecorationWidth = rightDecorationWidth2 - ((getLeftDecorationWidth(viewC) + (viewC.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) r6).leftMargin)) + fMax);
                        rightDecorationWidth = getRightDecorationWidth(viewC) + viewC.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) r6).rightMargin + fMax + leftDecorationWidth2;
                    }
                    i22 = i10 + 1;
                    i19 = i11;
                    dVar3 = dVar2;
                    zJ = z3;
                    i23 = i8;
                    i20 = i9;
                    rect3 = rect2;
                }
                z = zJ;
                dVar.c += this.m.i;
                i4 = cVar.g;
            } else {
                i2 = i14;
                z = zJ;
                Rect rect5 = rect3;
                boolean z4 = true;
                int paddingTop = getPaddingTop();
                int paddingBottom = getPaddingBottom();
                int height = getHeight();
                int i27 = dVar.e;
                if (dVar.i == -1) {
                    int i28 = cVar.g;
                    i3 = i27 + i28;
                    i27 -= i28;
                } else {
                    i3 = i27;
                }
                int i29 = dVar.d;
                float f2 = height - paddingBottom;
                float f3 = bVar.d;
                float bottomDecorationHeight = paddingTop - f3;
                float f4 = f2 - f3;
                float fMax2 = Math.max(0.0f, 0.0f);
                int i30 = cVar.h;
                int i31 = i29;
                int i32 = 0;
                while (i31 < i29 + i30) {
                    int i33 = i29;
                    View viewC2 = c(i31);
                    if (viewC2 == null) {
                        i5 = i30;
                        i6 = i33;
                        topDecorationHeight = f4;
                        z2 = z4;
                        rect = rect5;
                        i7 = i31;
                    } else {
                        float f5 = bottomDecorationHeight;
                        long j2 = dVar3.d[i31];
                        float f6 = f4;
                        int i34 = (int) j2;
                        int i35 = (int) (j2 >> 32);
                        if (af(viewC2, i34, i35, (c) viewC2.getLayoutParams())) {
                            viewC2.measure(i34, i35);
                        }
                        float topDecorationHeight3 = f5 + getTopDecorationHeight(viewC2) + ((ViewGroup.MarginLayoutParams) r4).topMargin;
                        float bottomDecorationHeight2 = f6 - (getBottomDecorationHeight(viewC2) + ((ViewGroup.MarginLayoutParams) r4).rightMargin);
                        z2 = true;
                        if (dVar.i == 1) {
                            rect = rect5;
                            calculateItemDecorationsForChild(viewC2, rect);
                            addView(viewC2);
                        } else {
                            rect = rect5;
                            calculateItemDecorationsForChild(viewC2, rect);
                            addView(viewC2, i32);
                            i32++;
                        }
                        int i36 = i32;
                        int leftDecorationWidth3 = getLeftDecorationWidth(viewC2) + i27;
                        int rightDecorationWidth3 = i3 - getRightDecorationWidth(viewC2);
                        int i37 = i31;
                        boolean z5 = this.e;
                        if (!z5) {
                            i5 = i30;
                            i6 = i33;
                            i7 = i37;
                            if (this.f) {
                                this.j.p(viewC2, cVar, z5, leftDecorationWidth3, Math.round(bottomDecorationHeight2) - viewC2.getMeasuredHeight(), viewC2.getMeasuredWidth() + leftDecorationWidth3, Math.round(bottomDecorationHeight2));
                            } else {
                                this.j.p(viewC2, cVar, z5, leftDecorationWidth3, Math.round(topDecorationHeight3), viewC2.getMeasuredWidth() + leftDecorationWidth3, viewC2.getMeasuredHeight() + Math.round(topDecorationHeight3));
                            }
                        } else if (this.f) {
                            i7 = i37;
                            i5 = i30;
                            i6 = i33;
                            this.j.p(viewC2, cVar, z5, rightDecorationWidth3 - viewC2.getMeasuredWidth(), Math.round(bottomDecorationHeight2) - viewC2.getMeasuredHeight(), rightDecorationWidth3, Math.round(bottomDecorationHeight2));
                        } else {
                            i5 = i30;
                            i6 = i33;
                            i7 = i37;
                            this.j.p(viewC2, cVar, z5, rightDecorationWidth3 - viewC2.getMeasuredWidth(), Math.round(topDecorationHeight3), rightDecorationWidth3, viewC2.getMeasuredHeight() + Math.round(topDecorationHeight3));
                        }
                        topDecorationHeight = bottomDecorationHeight2 - ((getTopDecorationHeight(viewC2) + (viewC2.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) r4).bottomMargin)) + fMax2);
                        bottomDecorationHeight = getBottomDecorationHeight(viewC2) + viewC2.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) r4).topMargin + fMax2 + topDecorationHeight3;
                        i32 = i36;
                    }
                    i31 = i7 + 1;
                    rect5 = rect;
                    z4 = z2;
                    f4 = topDecorationHeight;
                    i29 = i6;
                    i30 = i5;
                }
                dVar.c += this.m.i;
                i4 = cVar.g;
            }
            i16 += i4;
            if (z || !this.e) {
                dVar.e += cVar.g * dVar.i;
            } else {
                dVar.e -= cVar.g * dVar.i;
            }
            i15 -= cVar.g;
            i14 = i2;
            zJ = z;
        }
        int i38 = i14;
        int i39 = dVar.a - i16;
        dVar.a = i39;
        int i40 = dVar.f;
        if (i40 != Integer.MIN_VALUE) {
            int i41 = i40 + i16;
            dVar.f = i41;
            if (i39 < 0) {
                dVar.f = i41 + i39;
            }
            ac(wVar, dVar);
        }
        return i38 - dVar.a;
    }

    public final View s(int i) {
        View viewX = x(0, getChildCount(), i);
        if (viewX == null) {
            return null;
        }
        int i2 = this.j.c[getPosition(viewX)];
        if (i2 == -1) {
            return null;
        }
        return t(viewX, (com.google.android.flexbox.c) this.i.get(i2));
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int scrollHorizontallyBy(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (!j() || this.b == 0) {
            int iAa = aa(i, wVar, acVar);
            this.v.clear();
            return iAa;
        }
        int iAb = ab(i);
        this.n.d += iAb;
        this.p.r(-iAb);
        return iAb;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void scrollToPosition(int i) {
        this.r = i;
        this.s = Integer.MIN_VALUE;
        e eVar = this.q;
        if (eVar != null) {
            eVar.a = -1;
        }
        requestLayout();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int scrollVerticallyBy(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (j() || (this.b == 0 && !j())) {
            int iAa = aa(i, wVar, acVar);
            this.v.clear();
            return iAa;
        }
        int iAb = ab(i);
        this.n.d += iAb;
        this.p.r(-iAb);
        return iAb;
    }

    @Override // com.google.android.flexbox.a
    public final void setFlexLines(List list) {
        this.i = list;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.ac acVar, int i) {
        ad adVar = new ad(recyclerView.getContext());
        adVar.setTargetPosition(i);
        startSmoothScroll(adVar);
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x003b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final View t(View view, com.google.android.flexbox.c cVar) {
        boolean zJ = j();
        int i = cVar.h;
        for (int i2 = 1; i2 < i; i2++) {
            View childAt = getChildAt(i2);
            if (childAt != null && childAt.getVisibility() != 8) {
                if (!this.e || zJ) {
                    if (this.o.g(view) > this.o.g(childAt)) {
                        view = childAt;
                    }
                } else if (this.o.d(view) < this.o.d(childAt)) {
                }
            }
        }
        return view;
    }

    public final View u(int i) {
        View viewX = x(getChildCount() - 1, -1, i);
        if (viewX == null) {
            return null;
        }
        return v(viewX, (com.google.android.flexbox.c) this.i.get(this.j.c[getPosition(viewX)]));
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0047  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final View v(View view, com.google.android.flexbox.c cVar) {
        boolean zJ = j();
        int childCount = (getChildCount() - cVar.h) - 1;
        for (int childCount2 = getChildCount() - 2; childCount2 > childCount; childCount2--) {
            View childAt = getChildAt(childCount2);
            if (childAt != null && childAt.getVisibility() != 8) {
                if (!this.e || zJ) {
                    if (this.o.d(view) < this.o.d(childAt)) {
                        view = childAt;
                    }
                } else if (this.o.g(view) > this.o.g(childAt)) {
                }
            }
        }
        return view;
    }

    public final View w(int i, int i2) {
        int i3 = i2 > i ? 1 : -1;
        while (i != i2) {
            View childAt = getChildAt(i);
            int paddingLeft = getPaddingLeft();
            int paddingTop = getPaddingTop();
            int width = getWidth() - getPaddingRight();
            int height = getHeight() - getPaddingBottom();
            int decoratedLeft = getDecoratedLeft(childAt) - ((ViewGroup.MarginLayoutParams) ((RecyclerView.p) childAt.getLayoutParams())).leftMargin;
            int decoratedTop = getDecoratedTop(childAt) - ((ViewGroup.MarginLayoutParams) ((RecyclerView.p) childAt.getLayoutParams())).topMargin;
            int decoratedRight = getDecoratedRight(childAt) + ((ViewGroup.MarginLayoutParams) ((RecyclerView.p) childAt.getLayoutParams())).rightMargin;
            int decoratedBottom = getDecoratedBottom(childAt) + ((ViewGroup.MarginLayoutParams) ((RecyclerView.p) childAt.getLayoutParams())).bottomMargin;
            boolean z = decoratedLeft >= width || decoratedRight >= paddingLeft;
            boolean z2 = decoratedTop >= height || decoratedBottom >= paddingTop;
            if (z && z2) {
                return childAt;
            }
            i += i3;
        }
        return null;
    }

    public final View x(int i, int i2, int i3) {
        int position;
        q();
        if (this.m == null) {
            d dVar = new d();
            dVar.h = 1;
            dVar.i = 1;
            this.m = dVar;
        }
        int iM = this.o.m();
        int i4 = this.o.i();
        int i5 = i2 <= i ? -1 : 1;
        View view = null;
        View view2 = null;
        while (i != i2) {
            View childAt = getChildAt(i);
            if (childAt != null && (position = getPosition(childAt)) >= 0 && position < i3) {
                if (((RecyclerView.p) childAt.getLayoutParams()).a.isRemoved()) {
                    if (view2 == null) {
                        view2 = childAt;
                    }
                } else {
                    if (this.o.g(childAt) >= iM && this.o.d(childAt) <= i4) {
                        return childAt;
                    }
                    if (view == null) {
                        view = childAt;
                    }
                }
            }
            i += i5;
        }
        return view != null ? view : view2;
    }

    public final int y(int i, RecyclerView.w wVar, RecyclerView.ac acVar, boolean z) {
        int iAa;
        int i2;
        if (j() || !this.e) {
            int i3 = this.o.i() - i;
            if (i3 <= 0) {
                return 0;
            }
            iAa = -aa(-i3, wVar, acVar);
        } else {
            int iM = i - this.o.m();
            if (iM <= 0) {
                return 0;
            }
            iAa = aa(iM, wVar, acVar);
        }
        int i4 = i + iAa;
        if (!z || (i2 = this.o.i() - i4) <= 0) {
            return iAa;
        }
        this.o.r(i2);
        return i2 + iAa;
    }

    public final int z(int i, RecyclerView.w wVar, RecyclerView.ac acVar, boolean z) {
        int iAa;
        int iM;
        if (j() || !this.e) {
            int iM2 = i - this.o.m();
            if (iM2 <= 0) {
                return 0;
            }
            iAa = -aa(iM2, wVar, acVar);
        } else {
            int i2 = this.o.i() - i;
            if (i2 <= 0) {
                return 0;
            }
            iAa = aa(-i2, wVar, acVar);
        }
        int i3 = i + iAa;
        if (!z || (iM = i3 - this.o.m()) <= 0) {
            return iAa;
        }
        this.o.r(-iM);
        return iAa - iM;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsUpdated(RecyclerView recyclerView, int i, int i2) {
        super.onItemsUpdated(recyclerView, i, i2);
        ag(i);
    }
}
