what-the-bank/sources/com/google/android/material/carousel/CarouselLayoutManager.java

592 lines
19 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.android.material.carousel;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import o.C11786els;
import o.C16381npu;
import o.C17052tZT;
import o.C6217cMa;
import o.GRG;
import o.InterfaceC0312Dxl;
import o.Rez;
import o.WiE;
import o.kpA;
import o.scC;
/* loaded from: classes2.dex */
public class CarouselLayoutManager extends RecyclerView.tOB implements InterfaceC0312Dxl {
private C16381npu b;
int d;
private int f;
private int j;
private boolean h = false;
private final RVV i = new RVV();
private int a = 0;
private scC c = new kpA();
WiE e = null;
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final boolean d() {
return true;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class IeS {
HBt a;
View d;
float e;
IeS(View view, float f, HBt hBt) {
this.d = view;
this.e = f;
this.a = hBt;
}
}
public CarouselLayoutManager() {
RecyclerView recyclerView = this.s;
if (recyclerView != null) {
recyclerView.requestLayout();
}
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final RecyclerView.saX e() {
return new RecyclerView.saX(-2, -2);
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final void d(RecyclerView.AcL acL) {
super.d(acL);
if (i_() == 0) {
this.a = 0;
} else {
this.a = ((RecyclerView.saX) f(0).getLayoutParams()).g.getLayoutPosition();
}
}
private void e(RecyclerView.huo huoVar, int i) {
int e = e(i);
while (i >= 0) {
IeS e2 = e(huoVar, e, i);
if (e(e2.e, e2.a)) {
return;
}
e = e(e, (int) this.b.b);
if (!b(e2.e, e2.a)) {
a(e2.d, 0, e2.e);
}
i--;
}
}
private void e(RecyclerView.huo huoVar, RecyclerView.AcL acL, int i) {
int e = e(i);
while (true) {
if (i >= (acL.c ? acL.i - acL.b : acL.h)) {
return;
}
IeS e2 = e(huoVar, e, i);
if (b(e2.e, e2.a)) {
return;
}
e = b(e, (int) this.b.b);
if (!e(e2.e, e2.a)) {
a(e2.d, -1, e2.e);
}
i++;
}
}
private boolean e(float f, HBt hBt) {
int b = b((int) f, (int) (d(f, hBt) / 2.0f));
if (ViewCompat.m(this.s) == 1) {
if (b <= this.w) {
return false;
}
} else if (b >= 0) {
return false;
}
return true;
}
private boolean b(float f, HBt hBt) {
int e = e((int) f, (int) (d(f, hBt) / 2.0f));
if (ViewCompat.m(this.s) == 1) {
if (e >= 0) {
return false;
}
} else if (e <= this.w) {
return false;
}
return true;
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final void It_(View view, Rect rect) {
super.It_(view, rect);
float centerX = rect.centerX();
float width = (rect.width() - d(centerX, e(this.b.c, centerX, true))) / 2.0f;
rect.set((int) (rect.left + width), rect.top, (int) (rect.right - width), rect.bottom);
}
private static HBt e(List<C16381npu.LWm> list, float f, boolean z) {
float f2 = Float.MAX_VALUE;
int i = -1;
int i2 = -1;
int i3 = -1;
int i4 = -1;
float f3 = -3.4028235E38f;
float f4 = Float.MAX_VALUE;
float f5 = Float.MAX_VALUE;
for (int i5 = 0; i5 < list.size(); i5++) {
C16381npu.LWm lWm = list.get(i5);
float f6 = z ? lWm.a : lWm.c;
float abs = Math.abs(f6 - f);
if (f6 <= f && abs <= f2) {
i = i5;
f2 = abs;
}
if (f6 > f && abs <= f4) {
i3 = i5;
f4 = abs;
}
if (f6 <= f5) {
i2 = i5;
f5 = f6;
}
if (f6 > f3) {
i4 = i5;
f3 = f6;
}
}
if (i == -1) {
i = i2;
}
if (i3 == -1) {
i3 = i4;
}
return new HBt(list.get(i), list.get(i3));
}
private float a(View view, float f, HBt hBt) {
float b = C6217cMa.b(hBt.a.a, hBt.c.a, hBt.a.c, hBt.c.c, f);
if (hBt.c != this.b.c.get(0)) {
if (hBt.a != this.b.c.get(r2.size() - 1)) {
return b;
}
}
RecyclerView.saX sax = (RecyclerView.saX) view.getLayoutParams();
return b + ((f - hBt.c.c) * ((1.0f - hBt.c.e) + ((((ViewGroup.MarginLayoutParams) sax).rightMargin + ((ViewGroup.MarginLayoutParams) sax).leftMargin) / this.b.b)));
}
private static float d(float f, HBt hBt) {
return C6217cMa.b(hBt.a.d, hBt.c.d, hBt.a.a, hBt.c.a, f);
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final void o(View view) {
float f;
if (!(view instanceof GRG)) {
throw new IllegalStateException("All children of a RecyclerView using CarouselLayoutManager must use MaskableFrameLayout as their root ViewGroup.");
}
RecyclerView.saX sax = (RecyclerView.saX) view.getLayoutParams();
Rect rect = new Rect();
RecyclerView recyclerView = this.s;
if (recyclerView == null) {
rect.set(0, 0, 0, 0);
} else {
rect.set(recyclerView.Ab_(view));
}
int i = rect.left;
int i2 = rect.right;
int i3 = rect.top;
int i4 = rect.bottom;
WiE wiE = this.e;
if (wiE == null) {
f = ((ViewGroup.LayoutParams) sax).width;
} else {
f = wiE.c.b;
}
int d = d(this.w, this.x, getPaddingLeft() + getPaddingRight() + ((ViewGroup.MarginLayoutParams) sax).leftMargin + ((ViewGroup.MarginLayoutParams) sax).rightMargin + i + i2, (int) f, true);
int i5 = this.l;
int i6 = this.m;
int paddingTop = getPaddingTop();
int paddingBottom = getPaddingBottom();
view.measure(d, d(i5, i6, paddingTop + paddingBottom + ((ViewGroup.MarginLayoutParams) sax).topMargin + ((ViewGroup.MarginLayoutParams) sax).bottomMargin + i3 + i4, ((ViewGroup.LayoutParams) sax).height, c()));
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final void Iu_(AccessibilityEvent accessibilityEvent) {
super.Iu_(accessibilityEvent);
if (i_() > 0) {
accessibilityEvent.setFromIndex(((RecyclerView.saX) f(0).getLayoutParams()).g.getLayoutPosition());
accessibilityEvent.setToIndex(((RecyclerView.saX) f(i_() - 1).getLayoutParams()).g.getLayoutPosition());
}
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final void d(RecyclerView recyclerView, int i) {
C11786els c11786els = new C11786els(this, recyclerView.getContext()) { // from class: com.google.android.material.carousel.CarouselLayoutManager.2
private CarouselLayoutManager a;
{
this.a = this;
}
@Override // o.C11786els
public final int a(View view, int i2) {
CarouselLayoutManager carouselLayoutManager = this.a;
return (int) (this.a.d - carouselLayoutManager.a(carouselLayoutManager.e.c, CarouselLayoutManager.f(view)));
}
@Override // androidx.recyclerview.widget.RecyclerView.CeN
public final PointF Iw_(int i2) {
if (this.a.e == null) {
return null;
}
CarouselLayoutManager carouselLayoutManager = this.a;
return new PointF(carouselLayoutManager.a(carouselLayoutManager.e.c, i2) - this.a.d, BitmapDescriptorFactory.HUE_RED);
}
};
c11786els.f = i;
b(c11786els);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class HBt {
final C16381npu.LWm a;
final C16381npu.LWm c;
HBt(C16381npu.LWm lWm, C16381npu.LWm lWm2) {
if (lWm.c > lWm2.c) {
throw new IllegalArgumentException();
}
this.a = lWm;
this.c = lWm2;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class RVV extends RecyclerView.ZqN {
private final Paint d;
List<C16381npu.LWm> e;
RVV() {
Paint paint = new Paint();
this.d = paint;
this.e = Collections.unmodifiableList(new ArrayList());
paint.setStrokeWidth(5.0f);
paint.setColor(-65281);
}
@Override // androidx.recyclerview.widget.RecyclerView.ZqN
public final void NS_(Canvas canvas, RecyclerView recyclerView, RecyclerView.AcL acL) {
super.NS_(canvas, recyclerView, acL);
this.d.setStrokeWidth(recyclerView.getResources().getDimension(C17052tZT.HBt.m3_carousel_debug_keyline_width));
for (C16381npu.LWm lWm : this.e) {
this.d.setColor(Rez.a(lWm.e));
float f = lWm.a;
float paddingTop = ((CarouselLayoutManager) recyclerView.x).getPaddingTop();
float f2 = lWm.a;
CarouselLayoutManager carouselLayoutManager = (CarouselLayoutManager) recyclerView.x;
canvas.drawLine(f, paddingTop, f2, carouselLayoutManager.l - carouselLayoutManager.getPaddingBottom(), this.d);
}
}
}
private void a(View view, int i, float f) {
float f2 = this.b.b / 2.0f;
d(view, i);
b(view, (int) (f - f2), getPaddingTop(), (int) (f + f2), this.l - getPaddingBottom());
}
private int b(int i, int i2) {
return ViewCompat.m(this.s) != 1 ? i + i2 : i - i2;
}
private int e(int i, int i2) {
return ViewCompat.m(this.s) != 1 ? i - i2 : i + i2;
}
private int e(int i) {
return b((ViewCompat.m(this.s) != 1 ? 0 : this.w) - this.d, (int) (this.b.b * i));
}
private void c(RecyclerView.huo huoVar, RecyclerView.AcL acL) {
while (i_() > 0) {
View f = f(0);
Rect rect = new Rect();
super.It_(f, rect);
float centerX = rect.centerX();
if (!e(centerX, e(this.b.c, centerX, true))) {
break;
}
this.k.d(f);
huoVar.c(f);
}
while (i_() - 1 >= 0) {
View f2 = f(i_() - 1);
Rect rect2 = new Rect();
super.It_(f2, rect2);
float centerX2 = rect2.centerX();
if (!b(centerX2, e(this.b.c, centerX2, true))) {
break;
}
this.k.d(f2);
huoVar.c(f2);
}
if (i_() == 0) {
e(huoVar, this.a - 1);
e(huoVar, acL, this.a);
} else {
int layoutPosition = ((RecyclerView.saX) f(0).getLayoutParams()).g.getLayoutPosition();
int layoutPosition2 = ((RecyclerView.saX) f(i_() - 1).getLayoutParams()).g.getLayoutPosition();
e(huoVar, layoutPosition - 1);
e(huoVar, acL, layoutPosition2 + 1);
}
}
private int i() {
if (ViewCompat.m(this.s) != 1) {
return 0;
}
return this.w;
}
private IeS e(RecyclerView.huo huoVar, float f, int i) {
float f2 = this.b.b / 2.0f;
View d = huoVar.d(i);
o(d);
float b = b((int) f, (int) f2);
HBt e = e(this.b.c, b, false);
return new IeS(d, a(d, b, e), e);
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final int f(RecyclerView.AcL acL) {
return (int) this.e.c.b;
}
@Override // o.InterfaceC0312Dxl
public final int a() {
return this.w;
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final void e(RecyclerView.huo huoVar, RecyclerView.AcL acL) {
C16381npu c16381npu;
C16381npu.LWm lWm;
C16381npu c16381npu2;
C16381npu.LWm lWm2;
boolean z = false;
if ((acL.c ? acL.i - acL.b : acL.h) <= 0) {
c(huoVar);
this.a = 0;
return;
}
boolean z2 = ViewCompat.m(this.s) == 1;
boolean z3 = this.e == null;
if (z3) {
View d = huoVar.d(0);
o(d);
C16381npu d2 = this.c.d(this, d);
if (z2) {
C16381npu.RVV rvv = new C16381npu.RVV(d2.b);
float f = d2.c.get(0).a - (d2.c.get(0).d / 2.0f);
int size = d2.c.size() - 1;
while (size >= 0) {
C16381npu.LWm lWm3 = d2.c.get(size);
rvv.b((lWm3.d / 2.0f) + f, lWm3.e, lWm3.d, (size < d2.d || size > d2.a) ? z : true);
f += lWm3.d;
size--;
z = false;
}
d2 = rvv.c();
}
this.e = new WiE(d2, WiE.d(d2), WiE.d(this, d2));
}
WiE wiE = this.e;
boolean z4 = ViewCompat.m(this.s) == 1;
if (z4) {
List<C16381npu> list = wiE.i;
c16381npu = list.get(list.size() - 1);
} else {
List<C16381npu> list2 = wiE.a;
c16381npu = list2.get(list2.size() - 1);
}
if (!z4) {
lWm = c16381npu.c.get(c16381npu.d);
} else {
lWm = c16381npu.c.get(c16381npu.a);
}
int paddingStart = (int) (((getPaddingStart() * (z4 ? 1 : -1)) + i()) - e((int) lWm.c, (int) (c16381npu.b / 2.0f)));
WiE wiE2 = this.e;
boolean z5 = ViewCompat.m(this.s) == 1;
if (z5) {
List<C16381npu> list3 = wiE2.a;
c16381npu2 = list3.get(list3.size() - 1);
} else {
List<C16381npu> list4 = wiE2.i;
c16381npu2 = list4.get(list4.size() - 1);
}
if (z5) {
lWm2 = c16381npu2.c.get(c16381npu2.d);
} else {
lWm2 = c16381npu2.c.get(c16381npu2.a);
}
float paddingEnd = ((((acL.c ? acL.i - acL.b : acL.h) - 1) * c16381npu2.b) + getPaddingEnd()) * (z5 ? -1.0f : 1.0f);
float i = lWm2.c - i();
int i2 = Math.abs(i) > Math.abs(paddingEnd) ? 0 : (int) ((paddingEnd - i) + ((ViewCompat.m(this.s) != 1 ? this.w : 0) - lWm2.c));
int i3 = z2 ? i2 : paddingStart;
this.f = i3;
if (z2) {
i2 = paddingStart;
}
this.j = i2;
if (z3) {
this.d = paddingStart;
} else {
int i4 = this.d;
this.d = i4 + (i4 < i3 ? i3 - i4 : i4 > i2 ? i2 - i4 : 0);
}
int i5 = this.a;
int i6 = acL.c ? acL.i - acL.b : acL.h;
if (i5 < 0) {
i6 = 0;
} else if (i5 <= i6) {
i6 = i5;
}
this.a = i6;
j();
a(huoVar);
c(huoVar, acL);
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final boolean Iv_(RecyclerView recyclerView, View view, Rect rect, boolean z, boolean z2) {
WiE wiE = this.e;
if (wiE == null) {
return false;
}
int a = a(wiE.c, ((RecyclerView.saX) view.getLayoutParams()).g.getLayoutPosition()) - this.d;
if (z2 || a == 0) {
return false;
}
recyclerView.scrollBy(a, 0);
return true;
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final void b(int i) {
WiE wiE = this.e;
if (wiE == null) {
return;
}
this.d = a(wiE.c, i);
int max = Math.max(0, r() - 1);
if (i < 0) {
i = 0;
} else if (i > max) {
i = max;
}
this.a = i;
j();
RecyclerView recyclerView = this.s;
if (recyclerView != null) {
recyclerView.requestLayout();
}
}
final int a(C16381npu c16381npu, int i) {
if (ViewCompat.m(this.s) == 1) {
return (int) (((this.w - c16381npu.c.get(c16381npu.a).c) - (i * c16381npu.b)) - (c16381npu.b / 2.0f));
}
return (int) (((i * c16381npu.b) - c16381npu.c.get(c16381npu.d).c) + (c16381npu.b / 2.0f));
}
private void j() {
C16381npu c16381npu;
int i = this.j;
int i2 = this.f;
if (i > i2) {
WiE wiE = this.e;
float f = this.d;
float f2 = i2;
float f3 = i;
float f4 = wiE.e + f2;
float f5 = f3 - wiE.d;
if (f < f4) {
c16381npu = WiE.a(wiE.a, C6217cMa.b(1.0f, BitmapDescriptorFactory.HUE_RED, f2, f4, f), wiE.b);
} else if (f > f5) {
c16381npu = WiE.a(wiE.i, C6217cMa.b(BitmapDescriptorFactory.HUE_RED, 1.0f, f5, f3, f), wiE.h);
} else {
c16381npu = wiE.c;
}
} else if (ViewCompat.m(this.s) != 1) {
List<C16381npu> list = this.e.a;
c16381npu = list.get(list.size() - 1);
} else {
List<C16381npu> list2 = this.e.i;
c16381npu = list2.get(list2.size() - 1);
}
this.b = c16381npu;
this.i.e = Collections.unmodifiableList(c16381npu.c);
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final int b(int i, RecyclerView.huo huoVar, RecyclerView.AcL acL) {
if (i_() == 0 || i == 0) {
return 0;
}
int i2 = this.d;
int i3 = this.f;
int i4 = this.j;
int i5 = i2 + i;
if (i5 < i3) {
i = i3 - i2;
} else if (i5 > i4) {
i = i4 - i2;
}
this.d = i2 + i;
j();
float f = this.b.b / 2.0f;
int e = e(((RecyclerView.saX) f(0).getLayoutParams()).g.getLayoutPosition());
Rect rect = new Rect();
for (int i6 = 0; i6 < i_(); i6++) {
View f2 = f(i6);
float b = b(e, (int) f);
float a = a(f2, b, e(this.b.c, b, false));
super.It_(f2, rect);
f2.offsetLeftAndRight((int) (a - (rect.left + f)));
e = b(e, (int) this.b.b);
}
c(huoVar, acL);
return i;
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final int e(RecyclerView.AcL acL) {
return this.j - this.f;
}
@Override // androidx.recyclerview.widget.RecyclerView.tOB
public final int b(RecyclerView.AcL acL) {
return this.d;
}
}