package ῲ.ト.ῲ;

import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Locale;

/* renamed from: ῲ.ト.ῲ.㴹  reason: contains not printable characters */
/* compiled from: ScrollEventAdapter */
public final class C2205 extends RecyclerView.AbstractC0267 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final RecyclerView f7664 = this.f7668.f1804;

    /* renamed from: ඓ  reason: contains not printable characters */
    public int f7665;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public boolean f7666;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public int f7667;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final ViewPager2 f7668;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public C2206 f7669 = new C2206();

    /* renamed from: K  reason: contains not printable characters */
    public ViewPager2.AbstractC0314 f7670;

    /* renamed from: 㑃  reason: contains not printable characters */
    public boolean f7671;

    /* renamed from: 㳳  reason: contains not printable characters */
    public boolean f7672;

    /* renamed from: 㴹  reason: contains not printable characters */
    public int f7673;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final LinearLayoutManager f7674 = ((LinearLayoutManager) this.f7664.getLayoutManager());

    /* renamed from: 㿎  reason: contains not printable characters */
    public int f7675;

    /* renamed from: 䁗  reason: contains not printable characters */
    public boolean f7676;

    /* renamed from: ῲ.ト.ῲ.㴹$K  reason: contains not printable characters */
    /* compiled from: ScrollEventAdapter */
    public static final class C2206 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public int f7677;

        /* renamed from: ῲ  reason: contains not printable characters */
        public float f7678;

        /* renamed from: K  reason: contains not printable characters */
        public int f7679;

        /* renamed from: K  reason: contains not printable characters */
        public void m5835() {
            this.f7679 = -1;
            this.f7678 = 0.0f;
            this.f7677 = 0;
        }
    }

    public C2205(ViewPager2 viewPager2) {
        this.f7668 = viewPager2;
        m5833();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.AbstractC0267
    public void onScrollStateChanged(RecyclerView recyclerView, int i) {
        ViewPager2.AbstractC0314 r5;
        boolean z = true;
        if (!(this.f7665 == 1 && this.f7673 == 1) && i == 1) {
            this.f7676 = false;
            this.f7665 = 1;
            int i2 = this.f7667;
            if (i2 != -1) {
                this.f7675 = i2;
                this.f7667 = -1;
            } else if (this.f7675 == -1) {
                this.f7675 = this.f7674.findFirstVisibleItemPosition();
            }
            m5832(1);
            return;
        }
        int i3 = this.f7665;
        if (!(i3 == 1 || i3 == 4) || i != 2) {
            int i4 = this.f7665;
            if ((i4 == 1 || i4 == 4) && i == 0) {
                m5831();
                if (!this.f7666) {
                    int i5 = this.f7669.f7679;
                    if (!(i5 == -1 || (r5 = this.f7670) == null)) {
                        r5.onPageScrolled(i5, 0.0f, 0);
                    }
                } else {
                    C2206 k = this.f7669;
                    if (k.f7677 == 0) {
                        int i6 = this.f7675;
                        int i7 = k.f7679;
                        if (i6 != i7) {
                            m5834(i7);
                        }
                    } else {
                        z = false;
                    }
                }
                if (z) {
                    m5832(0);
                    m5833();
                }
            }
            if (this.f7665 == 2 && i == 0 && this.f7671) {
                m5831();
                C2206 k2 = this.f7669;
                if (k2.f7677 == 0) {
                    int i8 = this.f7667;
                    int i9 = k2.f7679;
                    if (i8 != i9) {
                        if (i9 == -1) {
                            i9 = 0;
                        }
                        m5834(i9);
                    }
                    m5832(0);
                    m5833();
                }
            }
        } else if (this.f7666) {
            m5832(2);
            this.f7672 = true;
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:9:0x001d, code lost:
        if ((r6 < 0) == r4.f7668.m1022()) goto L_0x0022;
     */
    /* JADX WARNING: Removed duplicated region for block: B:13:0x0025  */
    /* JADX WARNING: Removed duplicated region for block: B:19:0x003b  */
    @Override // androidx.recyclerview.widget.RecyclerView.AbstractC0267
    public void onScrolled(RecyclerView recyclerView, int i, int i2) {
        boolean z;
        int i3;
        int i4;
        int i5;
        this.f7666 = true;
        m5831();
        if (this.f7672) {
            this.f7672 = false;
            if (i2 <= 0) {
                if (i2 == 0) {
                }
                z = false;
                if (z) {
                    C2206 k = this.f7669;
                    if (k.f7677 != 0) {
                        i3 = k.f7679 + 1;
                        this.f7667 = i3;
                        i4 = this.f7675;
                        i5 = this.f7667;
                        if (i4 != i5) {
                            m5834(i5);
                        }
                    }
                }
                i3 = this.f7669.f7679;
                this.f7667 = i3;
                i4 = this.f7675;
                i5 = this.f7667;
                if (i4 != i5) {
                }
            }
            z = true;
            if (z) {
            }
            i3 = this.f7669.f7679;
            this.f7667 = i3;
            i4 = this.f7675;
            i5 = this.f7667;
            if (i4 != i5) {
            }
        } else if (this.f7665 == 0) {
            int i6 = this.f7669.f7679;
            if (i6 == -1) {
                i6 = 0;
            }
            m5834(i6);
        }
        int i7 = this.f7669.f7679;
        if (i7 == -1) {
            i7 = 0;
        }
        C2206 k2 = this.f7669;
        float f = k2.f7678;
        int i8 = k2.f7677;
        ViewPager2.AbstractC0314 r3 = this.f7670;
        if (r3 != null) {
            r3.onPageScrolled(i7, f, i8);
        }
        int i9 = this.f7669.f7679;
        int i10 = this.f7667;
        if ((i9 == i10 || i10 == -1) && this.f7669.f7677 == 0 && this.f7673 != 1) {
            m5832(0);
            m5833();
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:55:0x0135, code lost:
        if (r4[r2 - 1][1] >= r3) goto L_0x0138;
     */
    /* JADX WARNING: Removed duplicated region for block: B:63:0x014e  */
    /* JADX WARNING: Removed duplicated region for block: B:69:0x0162  */
    /* JADX WARNING: Removed duplicated region for block: B:72:0x0167  */
    /* JADX WARNING: Removed duplicated region for block: B:74:0x016f  */
    /* JADX WARNING: Removed duplicated region for block: B:88:0x015f A[SYNTHETIC] */
    /* renamed from: ῲ  reason: contains not printable characters */
    public final void m5831() {
        int i;
        boolean z;
        boolean z2;
        int childCount;
        int i2;
        boolean z3;
        ViewGroup.MarginLayoutParams marginLayoutParams;
        int i3;
        int i4;
        int i5;
        int i6;
        C2206 k = this.f7669;
        k.f7679 = this.f7674.findFirstVisibleItemPosition();
        int i7 = k.f7679;
        if (i7 == -1) {
            k.m5835();
            return;
        }
        View findViewByPosition = this.f7674.findViewByPosition(i7);
        if (findViewByPosition == null) {
            k.m5835();
            return;
        }
        int leftDecorationWidth = this.f7674.getLeftDecorationWidth(findViewByPosition);
        int rightDecorationWidth = this.f7674.getRightDecorationWidth(findViewByPosition);
        int topDecorationHeight = this.f7674.getTopDecorationHeight(findViewByPosition);
        int bottomDecorationHeight = this.f7674.getBottomDecorationHeight(findViewByPosition);
        ViewGroup.LayoutParams layoutParams = findViewByPosition.getLayoutParams();
        if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams marginLayoutParams2 = (ViewGroup.MarginLayoutParams) layoutParams;
            leftDecorationWidth += marginLayoutParams2.leftMargin;
            rightDecorationWidth += marginLayoutParams2.rightMargin;
            topDecorationHeight += marginLayoutParams2.topMargin;
            bottomDecorationHeight += marginLayoutParams2.bottomMargin;
        }
        int height = findViewByPosition.getHeight() + topDecorationHeight + bottomDecorationHeight;
        int width = rightDecorationWidth + findViewByPosition.getWidth() + leftDecorationWidth;
        if (this.f7674.getOrientation() == 0) {
            i = (findViewByPosition.getLeft() - leftDecorationWidth) - this.f7664.getPaddingLeft();
            if (this.f7668.m1022()) {
                i = -i;
            }
        } else {
            i = (findViewByPosition.getTop() - topDecorationHeight) - this.f7664.getPaddingTop();
            width = height;
        }
        k.f7677 = -i;
        int i8 = k.f7677;
        if (i8 < 0) {
            C2202 r1 = new C2202(this.f7674);
            int childCount2 = r1.f7663.getChildCount();
            if (childCount2 != 0) {
                boolean z4 = r1.f7663.getOrientation() == 0;
                int[][] iArr = (int[][]) Array.newInstance(int.class, childCount2, 2);
                for (int i9 = 0; i9 < childCount2; i9++) {
                    View childAt = r1.f7663.getChildAt(i9);
                    if (childAt != null) {
                        ViewGroup.LayoutParams layoutParams2 = childAt.getLayoutParams();
                        if (layoutParams2 instanceof ViewGroup.MarginLayoutParams) {
                            marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams2;
                        } else {
                            marginLayoutParams = C2202.f7662;
                        }
                        int[] iArr2 = iArr[i9];
                        if (z4) {
                            i4 = childAt.getLeft();
                            i3 = marginLayoutParams.leftMargin;
                        } else {
                            i4 = childAt.getTop();
                            i3 = marginLayoutParams.topMargin;
                        }
                        iArr2[0] = i4 - i3;
                        int[] iArr3 = iArr[i9];
                        if (z4) {
                            i6 = childAt.getRight();
                            i5 = marginLayoutParams.rightMargin;
                        } else {
                            i6 = childAt.getBottom();
                            i5 = marginLayoutParams.bottomMargin;
                        }
                        iArr3[1] = i6 + i5;
                    } else {
                        throw new IllegalStateException("null view contained in the view hierarchy");
                    }
                }
                Arrays.sort(iArr, new C2204(r1));
                int i10 = 1;
                while (true) {
                    if (i10 >= childCount2) {
                        int i11 = iArr[0][1] - iArr[0][0];
                        if (iArr[0][0] <= 0) {
                        }
                    } else if (iArr[i10 - 1][1] != iArr[i10][0]) {
                        break;
                    } else {
                        i10++;
                    }
                }
                z = false;
                if (!z || r1.f7663.getChildCount() <= 1) {
                    childCount = r1.f7663.getChildCount();
                    i2 = 0;
                    while (true) {
                        if (i2 < childCount) {
                            z3 = false;
                            break;
                        } else if (C2202.m5828(r1.f7663.getChildAt(i2))) {
                            z3 = true;
                            break;
                        } else {
                            i2++;
                        }
                    }
                    if (z3) {
                        z2 = true;
                        if (z2) {
                            throw new IllegalStateException("Page(s) contain a ViewGroup with a LayoutTransition (or animateLayoutChanges=\"true\"), which interferes with the scrolling animation. Make sure to call getLayoutTransition().setAnimateParentHierarchy(false) on all ViewGroups with a LayoutTransition before an animation is started.");
                        }
                        throw new IllegalStateException(String.format(Locale.US, "Page can only be offset by a positive amount, not by %d", Integer.valueOf(k.f7677)));
                    }
                }
                z2 = false;
                if (z2) {
                }
            }
            z = true;
            childCount = r1.f7663.getChildCount();
            i2 = 0;
            while (true) {
                if (i2 < childCount) {
                }
                i2++;
            }
            if (z3) {
            }
            z2 = false;
            if (z2) {
            }
        } else {
            k.f7678 = width == 0 ? 0.0f : ((float) i8) / ((float) width);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m5833() {
        this.f7665 = 0;
        this.f7673 = 0;
        this.f7669.m5835();
        this.f7675 = -1;
        this.f7667 = -1;
        this.f7672 = false;
        this.f7666 = false;
        this.f7676 = false;
        this.f7671 = false;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m5834(int i) {
        ViewPager2.AbstractC0314 r0 = this.f7670;
        if (r0 != null) {
            r0.onPageSelected(i);
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final void m5832(int i) {
        if ((this.f7665 != 3 || this.f7673 != 0) && this.f7673 != i) {
            this.f7673 = i;
            ViewPager2.AbstractC0314 r0 = this.f7670;
            if (r0 != null) {
                r0.onPageScrollStateChanged(i);
            }
        }
    }
}
