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; /* loaded from: classes.dex */ class ChildHelper { final Callback a; final Bucket b = new Bucket(); final List c = new ArrayList(); interface Callback { int a(); View a(int i); void a(View view); void a(View view, int i); void a(View view, int i, ViewGroup.LayoutParams layoutParams); int b(View view); void b(); void b(int i); RecyclerView.ViewHolder c(View view); void c(int i); void d(View view); } ChildHelper(Callback callback) { this.a = callback; } private int f(int i) { if (i < 0) { return -1; } int a = this.a.a(); int i2 = i; while (i2 < a) { int b = i - (i2 - this.b.b(i2)); if (b == 0) { while (this.b.c(i2)) { i2++; } return i2; } i2 += b; } return -1; } private void g(View view) { this.c.add(view); this.a.a(view); } private boolean h(View view) { if (!this.c.remove(view)) { return false; } this.a.d(view); return true; } void a(View view, boolean z) { a(view, -1, z); } View b(int i) { int size = this.c.size(); for (int i2 = 0; i2 < size; i2++) { View view = this.c.get(i2); RecyclerView.ViewHolder c = this.a.c(view); if (c.getLayoutPosition() == i && !c.isInvalid() && !c.isRemoved()) { return view; } } return null; } View c(int i) { return this.a.a(f(i)); } void d(View view) { int b = this.a.b(view); if (b < 0) { return; } if (this.b.d(b)) { h(view); } this.a.c(b); } void e(int i) { int f = f(i); View a = this.a.a(f); if (a == null) { return; } if (this.b.d(f)) { h(a); } this.a.c(f); } public String toString() { return this.b.toString() + ", hidden list:" + this.c.size(); } static class Bucket { long a = 0; Bucket b; Bucket() { } private void b() { if (this.b == null) { this.b = new Bucket(); } } void a(int i) { if (i < 64) { this.a &= ~(1 << i); return; } Bucket bucket = this.b; if (bucket != null) { bucket.a(i - 64); } } boolean c(int i) { if (i < 64) { return (this.a & (1 << i)) != 0; } b(); return this.b.c(i - 64); } boolean d(int i) { if (i >= 64) { b(); return this.b.d(i - 64); } long j = 1 << i; boolean z = (this.a & j) != 0; this.a &= ~j; long j2 = j - 1; long j3 = this.a; this.a = Long.rotateRight(j3 & (~j2), 1) | (j3 & j2); Bucket bucket = this.b; if (bucket != null) { if (bucket.c(0)) { e(63); } this.b.d(0); } return z; } void e(int i) { if (i < 64) { this.a |= 1 << i; } else { b(); this.b.e(i - 64); } } public String toString() { if (this.b == null) { return Long.toBinaryString(this.a); } return this.b.toString() + "xx" + Long.toBinaryString(this.a); } int b(int i) { Bucket bucket = this.b; if (bucket == null) { if (i >= 64) { return Long.bitCount(this.a); } return Long.bitCount(this.a & ((1 << i) - 1)); } if (i < 64) { return Long.bitCount(this.a & ((1 << i) - 1)); } return bucket.b(i - 64) + Long.bitCount(this.a); } void a() { this.a = 0L; Bucket bucket = this.b; if (bucket != null) { bucket.a(); } } void a(int i, boolean z) { if (i >= 64) { b(); this.b.a(i - 64, z); return; } boolean z2 = (this.a & Long.MIN_VALUE) != 0; long j = (1 << i) - 1; long j2 = this.a; this.a = ((j2 & (~j)) << 1) | (j2 & j); if (z) { e(i); } else { a(i); } if (z2 || this.b != null) { b(); this.b.a(0, z2); } } } void a(View view, int i, boolean z) { int a = i < 0 ? this.a.a() : f(i); this.b.a(a, z); if (z) { g(view); } this.a.a(view, a); } void c() { this.b.a(); for (int size = this.c.size() - 1; size >= 0; size--) { this.a.d(this.c.get(size)); this.c.remove(size); } this.a.b(); } void f(View view) { int b = this.a.b(view); if (b >= 0) { if (this.b.c(b)) { this.b.a(b); h(view); return; } else { throw new RuntimeException("trying to unhide a view that was not hidden" + view); } } throw new IllegalArgumentException("view is not a child, cannot hide " + view); } View d(int i) { return this.a.a(i); } boolean e(View view) { int b = this.a.b(view); if (b == -1) { h(view); return true; } if (!this.b.c(b)) { return false; } this.b.d(b); h(view); this.a.c(b); return true; } void a(View view, int i, ViewGroup.LayoutParams layoutParams, boolean z) { int f; if (i < 0) { f = this.a.a(); } else { f = f(i); } this.b.a(f, z); if (z) { g(view); } this.a.a(view, f, layoutParams); } int b() { return this.a.a(); } int b(View view) { int b = this.a.b(view); if (b == -1 || this.b.c(b)) { return -1; } return b - this.b.b(b); } boolean c(View view) { return this.c.contains(view); } int a() { return this.a.a() - this.c.size(); } void a(int i) { int f = f(i); this.b.d(f); this.a.b(f); } void a(View view) { int b = this.a.b(view); if (b >= 0) { this.b.e(b); g(view); } else { throw new IllegalArgumentException("view is not a child, cannot hide " + view); } } }