package androidx.recyclerview.widget;

import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: compiled from: ChildHelper.java */
/* JADX INFO: loaded from: classes.dex */
class b {
    final InterfaceC0016b a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    final a f1090b = new a();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    final List<View> f1091c = new ArrayList();

    /* JADX INFO: compiled from: ChildHelper.java */
    static class a {
        long a = 0;

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

        a() {
        }

        private void c() {
            if (this.f1092b == null) {
                this.f1092b = new a();
            }
        }

        void a(int i2) {
            if (i2 < 64) {
                this.a &= ~(1 << i2);
                return;
            }
            a aVar = this.f1092b;
            if (aVar != null) {
                aVar.a(i2 - 64);
            }
        }

        int b(int i2) {
            a aVar = this.f1092b;
            return aVar == null ? i2 >= 64 ? Long.bitCount(this.a) : Long.bitCount(this.a & ((1 << i2) - 1)) : i2 < 64 ? Long.bitCount(this.a & ((1 << i2) - 1)) : aVar.b(i2 - 64) + Long.bitCount(this.a);
        }

        boolean d(int i2) {
            if (i2 < 64) {
                return (this.a & (1 << i2)) != 0;
            }
            c();
            return this.f1092b.d(i2 - 64);
        }

        void e(int i2, boolean z) {
            if (i2 >= 64) {
                c();
                this.f1092b.e(i2 - 64, z);
                return;
            }
            boolean z2 = (this.a & Long.MIN_VALUE) != 0;
            long j2 = (1 << i2) - 1;
            long j3 = this.a;
            this.a = ((j3 & (~j2)) << 1) | (j3 & j2);
            if (z) {
                h(i2);
            } else {
                a(i2);
            }
            if (z2 || this.f1092b != null) {
                c();
                this.f1092b.e(0, z2);
            }
        }

        boolean f(int i2) {
            if (i2 >= 64) {
                c();
                return this.f1092b.f(i2 - 64);
            }
            long j2 = 1 << i2;
            boolean z = (this.a & j2) != 0;
            long j3 = this.a & (~j2);
            this.a = j3;
            long j4 = j2 - 1;
            this.a = (j3 & j4) | Long.rotateRight((~j4) & j3, 1);
            a aVar = this.f1092b;
            if (aVar != null) {
                if (aVar.d(0)) {
                    h(63);
                }
                this.f1092b.f(0);
            }
            return z;
        }

        void g() {
            this.a = 0L;
            a aVar = this.f1092b;
            if (aVar != null) {
                aVar.g();
            }
        }

        void h(int i2) {
            if (i2 < 64) {
                this.a |= 1 << i2;
            } else {
                c();
                this.f1092b.h(i2 - 64);
            }
        }

        public String toString() {
            if (this.f1092b == null) {
                return Long.toBinaryString(this.a);
            }
            return this.f1092b.toString() + "xx" + Long.toBinaryString(this.a);
        }
    }

    /* JADX INFO: renamed from: androidx.recyclerview.widget.b$b, reason: collision with other inner class name */
    /* JADX INFO: compiled from: ChildHelper.java */
    interface InterfaceC0016b {
        View a(int i2);

        void b(View view);

        RecyclerView.d0 c(View view);

        void d(int i2);

        void e(View view);

        void f(View view, int i2);

        int g();

        void h(int i2);

        void i();

        void j(View view, int i2, ViewGroup.LayoutParams layoutParams);

        int k(View view);
    }

    b(InterfaceC0016b interfaceC0016b) {
        this.a = interfaceC0016b;
    }

    private int h(int i2) {
        if (i2 < 0) {
            return -1;
        }
        int iG = this.a.g();
        int i3 = i2;
        while (i3 < iG) {
            int iB = i2 - (i3 - this.f1090b.b(i3));
            if (iB == 0) {
                while (this.f1090b.d(i3)) {
                    i3++;
                }
                return i3;
            }
            i3 += iB;
        }
        return -1;
    }

    private void l(View view) {
        this.f1091c.add(view);
        this.a.b(view);
    }

    private boolean t(View view) {
        if (!this.f1091c.remove(view)) {
            return false;
        }
        this.a.e(view);
        return true;
    }

    void a(View view, int i2, boolean z) {
        int iG = i2 < 0 ? this.a.g() : h(i2);
        this.f1090b.e(iG, z);
        if (z) {
            l(view);
        }
        this.a.f(view, iG);
    }

    void b(View view, boolean z) {
        a(view, -1, z);
    }

    void c(View view, int i2, ViewGroup.LayoutParams layoutParams, boolean z) {
        int iG = i2 < 0 ? this.a.g() : h(i2);
        this.f1090b.e(iG, z);
        if (z) {
            l(view);
        }
        this.a.j(view, iG, layoutParams);
    }

    void d(int i2) {
        int iH = h(i2);
        this.f1090b.f(iH);
        this.a.d(iH);
    }

    View e(int i2) {
        int size = this.f1091c.size();
        for (int i3 = 0; i3 < size; i3++) {
            View view = this.f1091c.get(i3);
            RecyclerView.d0 d0VarC = this.a.c(view);
            if (d0VarC.getLayoutPosition() == i2 && !d0VarC.isInvalid() && !d0VarC.isRemoved()) {
                return view;
            }
        }
        return null;
    }

    View f(int i2) {
        return this.a.a(h(i2));
    }

    int g() {
        return this.a.g() - this.f1091c.size();
    }

    View i(int i2) {
        return this.a.a(i2);
    }

    int j() {
        return this.a.g();
    }

    void k(View view) {
        int iK = this.a.k(view);
        if (iK >= 0) {
            this.f1090b.h(iK);
            l(view);
        } else {
            throw new IllegalArgumentException("view is not a child, cannot hide " + view);
        }
    }

    int m(View view) {
        int iK = this.a.k(view);
        if (iK == -1 || this.f1090b.d(iK)) {
            return -1;
        }
        return iK - this.f1090b.b(iK);
    }

    boolean n(View view) {
        return this.f1091c.contains(view);
    }

    void o() {
        this.f1090b.g();
        for (int size = this.f1091c.size() - 1; size >= 0; size--) {
            this.a.e(this.f1091c.get(size));
            this.f1091c.remove(size);
        }
        this.a.i();
    }

    void p(View view) {
        int iK = this.a.k(view);
        if (iK < 0) {
            return;
        }
        if (this.f1090b.f(iK)) {
            t(view);
        }
        this.a.h(iK);
    }

    void q(int i2) {
        int iH = h(i2);
        View viewA = this.a.a(iH);
        if (viewA == null) {
            return;
        }
        if (this.f1090b.f(iH)) {
            t(viewA);
        }
        this.a.h(iH);
    }

    boolean r(View view) {
        int iK = this.a.k(view);
        if (iK == -1) {
            t(view);
            return true;
        }
        if (!this.f1090b.d(iK)) {
            return false;
        }
        this.f1090b.f(iK);
        t(view);
        this.a.h(iK);
        return true;
    }

    void s(View view) {
        int iK = this.a.k(view);
        if (iK < 0) {
            throw new IllegalArgumentException("view is not a child, cannot hide " + view);
        }
        if (this.f1090b.d(iK)) {
            this.f1090b.a(iK);
            t(view);
        } else {
            throw new RuntimeException("trying to unhide a view that was not hidden" + view);
        }
    }

    public String toString() {
        return this.f1090b.toString() + ", hidden list:" + this.f1091c.size();
    }
}
