package d.p.b;

import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import d.h.j.y;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public class b {
    public final InterfaceC0045b a;

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

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

    public static class a {
        public long a = 0;

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

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

        public int b(int i2) {
            long j2;
            a aVar = this.f3239b;
            if (aVar == null) {
                if (i2 >= 64) {
                    j2 = this.a;
                }
                return Long.bitCount(j2);
            }
            if (i2 >= 64) {
                return Long.bitCount(this.a) + aVar.b(i2 - 64);
            }
            j2 = this.a & ((1 << i2) - 1);
            return Long.bitCount(j2);
        }

        public final void c() {
            if (this.f3239b == null) {
                this.f3239b = new a();
            }
        }

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

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

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

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

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

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

    /* JADX INFO: renamed from: d.p.b.b$b, reason: collision with other inner class name */
    public interface InterfaceC0045b {
    }

    public b(InterfaceC0045b interfaceC0045b) {
        this.a = interfaceC0045b;
    }

    public void a(View view, int i2, boolean z2) {
        int iB = i2 < 0 ? ((v) this.a).b() : f(i2);
        this.f3237b.e(iB, z2);
        if (z2) {
            i(view);
        }
        v vVar = (v) this.a;
        vVar.a.addView(view, iB);
        RecyclerView recyclerView = vVar.a;
        Objects.requireNonNull(recyclerView);
        RecyclerView.K(view);
        recyclerView.S();
    }

    public void b(View view, int i2, ViewGroup.LayoutParams layoutParams, boolean z2) {
        int iB = i2 < 0 ? ((v) this.a).b() : f(i2);
        this.f3237b.e(iB, z2);
        if (z2) {
            i(view);
        }
        v vVar = (v) this.a;
        Objects.requireNonNull(vVar);
        RecyclerView.z zVarK = RecyclerView.K(view);
        if (zVarK != null) {
            if (!zVarK.n() && !zVarK.t()) {
                StringBuilder sb = new StringBuilder();
                sb.append("Called attach on a child which is not detached: ");
                sb.append(zVarK);
                throw new IllegalArgumentException(g.a.a.a.a.g(vVar.a, sb));
            }
            zVarK.f842k &= -257;
        }
        vVar.a.attachViewToParent(view, iB, layoutParams);
    }

    public void c(int i2) {
        RecyclerView.z zVarK;
        int iF = f(i2);
        this.f3237b.f(iF);
        v vVar = (v) this.a;
        View childAt = vVar.a.getChildAt(iF);
        if (childAt != null && (zVarK = RecyclerView.K(childAt)) != null) {
            if (zVarK.n() && !zVarK.t()) {
                StringBuilder sb = new StringBuilder();
                sb.append("called detach on an already detached child ");
                sb.append(zVarK);
                throw new IllegalArgumentException(g.a.a.a.a.g(vVar.a, sb));
            }
            zVarK.b(256);
        }
        vVar.a.detachViewFromParent(iF);
    }

    public View d(int i2) {
        return ((v) this.a).a(f(i2));
    }

    public int e() {
        return ((v) this.a).b() - this.f3238c.size();
    }

    public final int f(int i2) {
        if (i2 < 0) {
            return -1;
        }
        int iB = ((v) this.a).b();
        int i3 = i2;
        while (i3 < iB) {
            int iB2 = i2 - (i3 - this.f3237b.b(i3));
            if (iB2 == 0) {
                while (this.f3237b.d(i3)) {
                    i3++;
                }
                return i3;
            }
            i3 += iB2;
        }
        return -1;
    }

    public View g(int i2) {
        return ((v) this.a).a.getChildAt(i2);
    }

    public int h() {
        return ((v) this.a).b();
    }

    public final void i(View view) {
        this.f3238c.add(view);
        v vVar = (v) this.a;
        Objects.requireNonNull(vVar);
        RecyclerView.z zVarK = RecyclerView.K(view);
        if (zVarK != null) {
            RecyclerView recyclerView = vVar.a;
            int iC = zVarK.f849r;
            if (iC == -1) {
                View view2 = zVarK.f833b;
                AtomicInteger atomicInteger = d.h.j.y.a;
                iC = y.c.c(view2);
            }
            zVarK.f848q = iC;
            recyclerView.j0(zVarK, 4);
        }
    }

    public int j(View view) {
        int iIndexOfChild = ((v) this.a).a.indexOfChild(view);
        if (iIndexOfChild == -1 || this.f3237b.d(iIndexOfChild)) {
            return -1;
        }
        return iIndexOfChild - this.f3237b.b(iIndexOfChild);
    }

    public boolean k(View view) {
        return this.f3238c.contains(view);
    }

    public final boolean l(View view) {
        if (!this.f3238c.remove(view)) {
            return false;
        }
        v vVar = (v) this.a;
        Objects.requireNonNull(vVar);
        RecyclerView.z zVarK = RecyclerView.K(view);
        if (zVarK == null) {
            return true;
        }
        vVar.a.j0(zVarK, zVarK.f848q);
        zVarK.f848q = 0;
        return true;
    }

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