package androidx.recyclerview.widget; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.i; import java.util.ArrayList; import java.util.List; /* loaded from: classes.dex */ class a implements i.a { /* renamed from: a, reason: collision with root package name */ private y.e f2372a; /* renamed from: b, reason: collision with root package name */ final ArrayList f2373b; /* renamed from: c, reason: collision with root package name */ final ArrayList f2374c; /* renamed from: d, reason: collision with root package name */ final InterfaceC0033a f2375d; /* renamed from: e, reason: collision with root package name */ Runnable f2376e; /* renamed from: f, reason: collision with root package name */ final boolean f2377f; /* renamed from: g, reason: collision with root package name */ final i f2378g; /* renamed from: h, reason: collision with root package name */ private int f2379h; /* renamed from: androidx.recyclerview.widget.a$a, reason: collision with other inner class name */ interface InterfaceC0033a { void a(int i10, int i11); void b(b bVar); void c(int i10, int i11, Object obj); void d(b bVar); RecyclerView.d0 e(int i10); void f(int i10, int i11); void g(int i10, int i11); void h(int i10, int i11); } static class b { /* renamed from: a, reason: collision with root package name */ int f2380a; /* renamed from: b, reason: collision with root package name */ int f2381b; /* renamed from: c, reason: collision with root package name */ Object f2382c; /* renamed from: d, reason: collision with root package name */ int f2383d; b(int i10, int i11, int i12, Object obj) { this.f2380a = i10; this.f2381b = i11; this.f2383d = i12; this.f2382c = obj; } String a() { int i10 = this.f2380a; return i10 != 1 ? i10 != 2 ? i10 != 4 ? i10 != 8 ? "??" : "mv" : "up" : "rm" : "add"; } public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } b bVar = (b) obj; int i10 = this.f2380a; if (i10 != bVar.f2380a) { return false; } if (i10 == 8 && Math.abs(this.f2383d - this.f2381b) == 1 && this.f2383d == bVar.f2381b && this.f2381b == bVar.f2383d) { return true; } if (this.f2383d != bVar.f2383d || this.f2381b != bVar.f2381b) { return false; } Object obj2 = this.f2382c; if (obj2 != null) { if (!obj2.equals(bVar.f2382c)) { return false; } } else if (bVar.f2382c != null) { return false; } return true; } public int hashCode() { return (((this.f2380a * 31) + this.f2381b) * 31) + this.f2383d; } public String toString() { return Integer.toHexString(System.identityHashCode(this)) + "[" + a() + ",s:" + this.f2381b + "c:" + this.f2383d + ",p:" + this.f2382c + "]"; } } a(InterfaceC0033a interfaceC0033a) { this(interfaceC0033a, false); } private void c(b bVar) { r(bVar); } private void d(b bVar) { r(bVar); } private void f(b bVar) { boolean z10; char c10; int i10 = bVar.f2381b; int i11 = bVar.f2383d + i10; char c11 = 65535; int i12 = i10; int i13 = 0; while (i12 < i11) { if (this.f2375d.e(i12) != null || h(i12)) { if (c11 == 0) { k(b(2, i10, i13, null)); z10 = true; } else { z10 = false; } c10 = 1; } else { if (c11 == 1) { r(b(2, i10, i13, null)); z10 = true; } else { z10 = false; } c10 = 0; } if (z10) { i12 -= i13; i11 -= i13; i13 = 1; } else { i13++; } i12++; c11 = c10; } if (i13 != bVar.f2383d) { a(bVar); bVar = b(2, i10, i13, null); } if (c11 == 0) { k(bVar); } else { r(bVar); } } private void g(b bVar) { int i10 = bVar.f2381b; int i11 = bVar.f2383d + i10; int i12 = i10; char c10 = 65535; int i13 = 0; while (i10 < i11) { if (this.f2375d.e(i10) != null || h(i10)) { if (c10 == 0) { k(b(4, i12, i13, bVar.f2382c)); i12 = i10; i13 = 0; } c10 = 1; } else { if (c10 == 1) { r(b(4, i12, i13, bVar.f2382c)); i12 = i10; i13 = 0; } c10 = 0; } i13++; i10++; } if (i13 != bVar.f2383d) { Object obj = bVar.f2382c; a(bVar); bVar = b(4, i12, i13, obj); } if (c10 == 0) { k(bVar); } else { r(bVar); } } private boolean h(int i10) { int size = this.f2374c.size(); for (int i11 = 0; i11 < size; i11++) { b bVar = (b) this.f2374c.get(i11); int i12 = bVar.f2380a; if (i12 == 8) { if (n(bVar.f2383d, i11 + 1) == i10) { return true; } } else if (i12 == 1) { int i13 = bVar.f2381b; int i14 = bVar.f2383d + i13; while (i13 < i14) { if (n(i13, i11 + 1) == i10) { return true; } i13++; } } else { continue; } } return false; } private void k(b bVar) { int i10; int i11 = bVar.f2380a; if (i11 == 1 || i11 == 8) { throw new IllegalArgumentException("should not dispatch add or move for pre layout"); } int v10 = v(bVar.f2381b, i11); int i12 = bVar.f2381b; int i13 = bVar.f2380a; if (i13 == 2) { i10 = 0; } else { if (i13 != 4) { throw new IllegalArgumentException("op should be remove or update." + bVar); } i10 = 1; } int i14 = 1; for (int i15 = 1; i15 < bVar.f2383d; i15++) { int v11 = v(bVar.f2381b + (i10 * i15), bVar.f2380a); int i16 = bVar.f2380a; if (i16 == 2 ? v11 == v10 : i16 == 4 && v11 == v10 + 1) { i14++; } else { b b10 = b(i16, v10, i14, bVar.f2382c); l(b10, i12); a(b10); if (bVar.f2380a == 4) { i12 += i14; } v10 = v11; i14 = 1; } } Object obj = bVar.f2382c; a(bVar); if (i14 > 0) { b b11 = b(bVar.f2380a, v10, i14, obj); l(b11, i12); a(b11); } } private void r(b bVar) { this.f2374c.add(bVar); int i10 = bVar.f2380a; if (i10 == 1) { this.f2375d.g(bVar.f2381b, bVar.f2383d); return; } if (i10 == 2) { this.f2375d.f(bVar.f2381b, bVar.f2383d); return; } if (i10 == 4) { this.f2375d.c(bVar.f2381b, bVar.f2383d, bVar.f2382c); } else { if (i10 == 8) { this.f2375d.a(bVar.f2381b, bVar.f2383d); return; } throw new IllegalArgumentException("Unknown update op type for " + bVar); } } private int v(int i10, int i11) { int i12; int i13; for (int size = this.f2374c.size() - 1; size >= 0; size--) { b bVar = (b) this.f2374c.get(size); int i14 = bVar.f2380a; if (i14 == 8) { int i15 = bVar.f2381b; int i16 = bVar.f2383d; if (i15 < i16) { i13 = i15; i12 = i16; } else { i12 = i15; i13 = i16; } if (i10 < i13 || i10 > i12) { if (i10 < i15) { if (i11 == 1) { bVar.f2381b = i15 + 1; bVar.f2383d = i16 + 1; } else if (i11 == 2) { bVar.f2381b = i15 - 1; bVar.f2383d = i16 - 1; } } } else if (i13 == i15) { if (i11 == 1) { bVar.f2383d = i16 + 1; } else if (i11 == 2) { bVar.f2383d = i16 - 1; } i10++; } else { if (i11 == 1) { bVar.f2381b = i15 + 1; } else if (i11 == 2) { bVar.f2381b = i15 - 1; } i10--; } } else { int i17 = bVar.f2381b; if (i17 <= i10) { if (i14 == 1) { i10 -= bVar.f2383d; } else if (i14 == 2) { i10 += bVar.f2383d; } } else if (i11 == 1) { bVar.f2381b = i17 + 1; } else if (i11 == 2) { bVar.f2381b = i17 - 1; } } } for (int size2 = this.f2374c.size() - 1; size2 >= 0; size2--) { b bVar2 = (b) this.f2374c.get(size2); if (bVar2.f2380a == 8) { int i18 = bVar2.f2383d; if (i18 == bVar2.f2381b || i18 < 0) { this.f2374c.remove(size2); a(bVar2); } } else if (bVar2.f2383d <= 0) { this.f2374c.remove(size2); a(bVar2); } } return i10; } @Override // androidx.recyclerview.widget.i.a public void a(b bVar) { if (this.f2377f) { return; } bVar.f2382c = null; this.f2372a.a(bVar); } @Override // androidx.recyclerview.widget.i.a public b b(int i10, int i11, int i12, Object obj) { b bVar = (b) this.f2372a.b(); if (bVar == null) { return new b(i10, i11, i12, obj); } bVar.f2380a = i10; bVar.f2381b = i11; bVar.f2383d = i12; bVar.f2382c = obj; return bVar; } public int e(int i10) { int size = this.f2373b.size(); for (int i11 = 0; i11 < size; i11++) { b bVar = (b) this.f2373b.get(i11); int i12 = bVar.f2380a; if (i12 != 1) { if (i12 == 2) { int i13 = bVar.f2381b; if (i13 <= i10) { int i14 = bVar.f2383d; if (i13 + i14 > i10) { return -1; } i10 -= i14; } else { continue; } } else if (i12 == 8) { int i15 = bVar.f2381b; if (i15 == i10) { i10 = bVar.f2383d; } else { if (i15 < i10) { i10--; } if (bVar.f2383d <= i10) { i10++; } } } } else if (bVar.f2381b <= i10) { i10 += bVar.f2383d; } } return i10; } void i() { int size = this.f2374c.size(); for (int i10 = 0; i10 < size; i10++) { this.f2375d.d((b) this.f2374c.get(i10)); } t(this.f2374c); this.f2379h = 0; } void j() { i(); int size = this.f2373b.size(); for (int i10 = 0; i10 < size; i10++) { b bVar = (b) this.f2373b.get(i10); int i11 = bVar.f2380a; if (i11 == 1) { this.f2375d.d(bVar); this.f2375d.g(bVar.f2381b, bVar.f2383d); } else if (i11 == 2) { this.f2375d.d(bVar); this.f2375d.h(bVar.f2381b, bVar.f2383d); } else if (i11 == 4) { this.f2375d.d(bVar); this.f2375d.c(bVar.f2381b, bVar.f2383d, bVar.f2382c); } else if (i11 == 8) { this.f2375d.d(bVar); this.f2375d.a(bVar.f2381b, bVar.f2383d); } Runnable runnable = this.f2376e; if (runnable != null) { runnable.run(); } } t(this.f2373b); this.f2379h = 0; } void l(b bVar, int i10) { this.f2375d.b(bVar); int i11 = bVar.f2380a; if (i11 == 2) { this.f2375d.h(i10, bVar.f2383d); } else { if (i11 != 4) { throw new IllegalArgumentException("only remove and update ops can be dispatched in first pass"); } this.f2375d.c(i10, bVar.f2383d, bVar.f2382c); } } int m(int i10) { return n(i10, 0); } int n(int i10, int i11) { int size = this.f2374c.size(); while (i11 < size) { b bVar = (b) this.f2374c.get(i11); int i12 = bVar.f2380a; if (i12 == 8) { int i13 = bVar.f2381b; if (i13 == i10) { i10 = bVar.f2383d; } else { if (i13 < i10) { i10--; } if (bVar.f2383d <= i10) { i10++; } } } else { int i14 = bVar.f2381b; if (i14 > i10) { continue; } else if (i12 == 2) { int i15 = bVar.f2383d; if (i10 < i14 + i15) { return -1; } i10 -= i15; } else if (i12 == 1) { i10 += bVar.f2383d; } } i11++; } return i10; } boolean o(int i10) { return (i10 & this.f2379h) != 0; } boolean p() { return this.f2373b.size() > 0; } boolean q() { return (this.f2374c.isEmpty() || this.f2373b.isEmpty()) ? false : true; } void s() { this.f2378g.b(this.f2373b); int size = this.f2373b.size(); for (int i10 = 0; i10 < size; i10++) { b bVar = (b) this.f2373b.get(i10); int i11 = bVar.f2380a; if (i11 == 1) { c(bVar); } else if (i11 == 2) { f(bVar); } else if (i11 == 4) { g(bVar); } else if (i11 == 8) { d(bVar); } Runnable runnable = this.f2376e; if (runnable != null) { runnable.run(); } } this.f2373b.clear(); } void t(List list) { int size = list.size(); for (int i10 = 0; i10 < size; i10++) { a((b) list.get(i10)); } list.clear(); } void u() { t(this.f2373b); t(this.f2374c); this.f2379h = 0; } a(InterfaceC0033a interfaceC0033a, boolean z10) { this.f2372a = new y.f(30); this.f2373b = new ArrayList(); this.f2374c = new ArrayList(); this.f2379h = 0; this.f2375d = interfaceC0033a; this.f2377f = z10; this.f2378g = new i(this); } }