package androidx.recyclerview.widget; import android.R; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.graphics.drawable.StateListDrawable; import android.view.MotionEvent; import androidx.core.view.n0; import androidx.recyclerview.widget.RecyclerView; import com.google.android.gms.common.ConnectionResult; /* loaded from: classes.dex */ class d extends RecyclerView.n implements RecyclerView.s { private static final int[] D = {R.attr.state_pressed}; private static final int[] E = new int[0]; int A; private final Runnable B; private final RecyclerView.t C; /* renamed from: a, reason: collision with root package name */ private final int f2440a; /* renamed from: b, reason: collision with root package name */ private final int f2441b; /* renamed from: c, reason: collision with root package name */ final StateListDrawable f2442c; /* renamed from: d, reason: collision with root package name */ final Drawable f2443d; /* renamed from: e, reason: collision with root package name */ private final int f2444e; /* renamed from: f, reason: collision with root package name */ private final int f2445f; /* renamed from: g, reason: collision with root package name */ private final StateListDrawable f2446g; /* renamed from: h, reason: collision with root package name */ private final Drawable f2447h; /* renamed from: i, reason: collision with root package name */ private final int f2448i; /* renamed from: j, reason: collision with root package name */ private final int f2449j; /* renamed from: k, reason: collision with root package name */ int f2450k; /* renamed from: l, reason: collision with root package name */ int f2451l; /* renamed from: m, reason: collision with root package name */ float f2452m; /* renamed from: n, reason: collision with root package name */ int f2453n; /* renamed from: o, reason: collision with root package name */ int f2454o; /* renamed from: p, reason: collision with root package name */ float f2455p; /* renamed from: s, reason: collision with root package name */ private RecyclerView f2458s; /* renamed from: z, reason: collision with root package name */ final ValueAnimator f2465z; /* renamed from: q, reason: collision with root package name */ private int f2456q = 0; /* renamed from: r, reason: collision with root package name */ private int f2457r = 0; /* renamed from: t, reason: collision with root package name */ private boolean f2459t = false; /* renamed from: u, reason: collision with root package name */ private boolean f2460u = false; /* renamed from: v, reason: collision with root package name */ private int f2461v = 0; /* renamed from: w, reason: collision with root package name */ private int f2462w = 0; /* renamed from: x, reason: collision with root package name */ private final int[] f2463x = new int[2]; /* renamed from: y, reason: collision with root package name */ private final int[] f2464y = new int[2]; class a implements Runnable { a() { } @Override // java.lang.Runnable public void run() { d.this.q(500); } } class b extends RecyclerView.t { b() { } @Override // androidx.recyclerview.widget.RecyclerView.t public void b(RecyclerView recyclerView, int i10, int i11) { d.this.B(recyclerView.computeHorizontalScrollOffset(), recyclerView.computeVerticalScrollOffset()); } } private class c extends AnimatorListenerAdapter { /* renamed from: a, reason: collision with root package name */ private boolean f2468a = false; c() { } @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener public void onAnimationCancel(Animator animator) { this.f2468a = true; } @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener public void onAnimationEnd(Animator animator) { if (this.f2468a) { this.f2468a = false; return; } if (((Float) d.this.f2465z.getAnimatedValue()).floatValue() == 0.0f) { d dVar = d.this; dVar.A = 0; dVar.y(0); } else { d dVar2 = d.this; dVar2.A = 2; dVar2.v(); } } } /* renamed from: androidx.recyclerview.widget.d$d, reason: collision with other inner class name */ private class C0036d implements ValueAnimator.AnimatorUpdateListener { C0036d() { } @Override // android.animation.ValueAnimator.AnimatorUpdateListener public void onAnimationUpdate(ValueAnimator valueAnimator) { int floatValue = (int) (((Float) valueAnimator.getAnimatedValue()).floatValue() * 255.0f); d.this.f2442c.setAlpha(floatValue); d.this.f2443d.setAlpha(floatValue); d.this.v(); } } d(RecyclerView recyclerView, StateListDrawable stateListDrawable, Drawable drawable, StateListDrawable stateListDrawable2, Drawable drawable2, int i10, int i11, int i12) { ValueAnimator ofFloat = ValueAnimator.ofFloat(0.0f, 1.0f); this.f2465z = ofFloat; this.A = 0; this.B = new a(); this.C = new b(); this.f2442c = stateListDrawable; this.f2443d = drawable; this.f2446g = stateListDrawable2; this.f2447h = drawable2; this.f2444e = Math.max(i10, stateListDrawable.getIntrinsicWidth()); this.f2445f = Math.max(i10, drawable.getIntrinsicWidth()); this.f2448i = Math.max(i10, stateListDrawable2.getIntrinsicWidth()); this.f2449j = Math.max(i10, drawable2.getIntrinsicWidth()); this.f2440a = i11; this.f2441b = i12; stateListDrawable.setAlpha(255); drawable.setAlpha(255); ofFloat.addListener(new c()); ofFloat.addUpdateListener(new C0036d()); j(recyclerView); } private void C(float f10) { int[] p10 = p(); float max = Math.max(p10[0], Math.min(p10[1], f10)); if (Math.abs(this.f2451l - max) < 2.0f) { return; } int x10 = x(this.f2452m, max, p10, this.f2458s.computeVerticalScrollRange(), this.f2458s.computeVerticalScrollOffset(), this.f2457r); if (x10 != 0) { this.f2458s.scrollBy(0, x10); } this.f2452m = max; } private void k() { this.f2458s.removeCallbacks(this.B); } private void l() { this.f2458s.removeItemDecoration(this); this.f2458s.removeOnItemTouchListener(this); this.f2458s.removeOnScrollListener(this.C); k(); } private void m(Canvas canvas) { int i10 = this.f2457r; int i11 = this.f2448i; int i12 = this.f2454o; int i13 = this.f2453n; this.f2446g.setBounds(0, 0, i13, i11); this.f2447h.setBounds(0, 0, this.f2456q, this.f2449j); canvas.translate(0.0f, i10 - i11); this.f2447h.draw(canvas); canvas.translate(i12 - (i13 / 2), 0.0f); this.f2446g.draw(canvas); canvas.translate(-r2, -r0); } private void n(Canvas canvas) { int i10 = this.f2456q; int i11 = this.f2444e; int i12 = i10 - i11; int i13 = this.f2451l; int i14 = this.f2450k; int i15 = i13 - (i14 / 2); this.f2442c.setBounds(0, 0, i11, i14); this.f2443d.setBounds(0, 0, this.f2445f, this.f2457r); if (!s()) { canvas.translate(i12, 0.0f); this.f2443d.draw(canvas); canvas.translate(0.0f, i15); this.f2442c.draw(canvas); canvas.translate(-i12, -i15); return; } this.f2443d.draw(canvas); canvas.translate(this.f2444e, i15); canvas.scale(-1.0f, 1.0f); this.f2442c.draw(canvas); canvas.scale(1.0f, 1.0f); canvas.translate(-this.f2444e, -i15); } private int[] o() { int[] iArr = this.f2464y; int i10 = this.f2441b; iArr[0] = i10; iArr[1] = this.f2456q - i10; return iArr; } private int[] p() { int[] iArr = this.f2463x; int i10 = this.f2441b; iArr[0] = i10; iArr[1] = this.f2457r - i10; return iArr; } private void r(float f10) { int[] o10 = o(); float max = Math.max(o10[0], Math.min(o10[1], f10)); if (Math.abs(this.f2454o - max) < 2.0f) { return; } int x10 = x(this.f2455p, max, o10, this.f2458s.computeHorizontalScrollRange(), this.f2458s.computeHorizontalScrollOffset(), this.f2456q); if (x10 != 0) { this.f2458s.scrollBy(x10, 0); } this.f2455p = max; } private boolean s() { return n0.B(this.f2458s) == 1; } private void w(int i10) { k(); this.f2458s.postDelayed(this.B, i10); } private int x(float f10, float f11, int[] iArr, int i10, int i11, int i12) { int i13 = iArr[1] - iArr[0]; if (i13 == 0) { return 0; } int i14 = i10 - i12; int i15 = (int) (((f11 - f10) / i13) * i14); int i16 = i11 + i15; if (i16 >= i14 || i16 < 0) { return 0; } return i15; } private void z() { this.f2458s.addItemDecoration(this); this.f2458s.addOnItemTouchListener(this); this.f2458s.addOnScrollListener(this.C); } public void A() { int i10 = this.A; if (i10 != 0) { if (i10 != 3) { return; } else { this.f2465z.cancel(); } } this.A = 1; ValueAnimator valueAnimator = this.f2465z; valueAnimator.setFloatValues(((Float) valueAnimator.getAnimatedValue()).floatValue(), 1.0f); this.f2465z.setDuration(500L); this.f2465z.setStartDelay(0L); this.f2465z.start(); } void B(int i10, int i11) { int computeVerticalScrollRange = this.f2458s.computeVerticalScrollRange(); int i12 = this.f2457r; this.f2459t = computeVerticalScrollRange - i12 > 0 && i12 >= this.f2440a; int computeHorizontalScrollRange = this.f2458s.computeHorizontalScrollRange(); int i13 = this.f2456q; boolean z10 = computeHorizontalScrollRange - i13 > 0 && i13 >= this.f2440a; this.f2460u = z10; boolean z11 = this.f2459t; if (!z11 && !z10) { if (this.f2461v != 0) { y(0); return; } return; } if (z11) { float f10 = i12; this.f2451l = (int) ((f10 * (i11 + (f10 / 2.0f))) / computeVerticalScrollRange); this.f2450k = Math.min(i12, (i12 * i12) / computeVerticalScrollRange); } if (this.f2460u) { float f11 = i13; this.f2454o = (int) ((f11 * (i10 + (f11 / 2.0f))) / computeHorizontalScrollRange); this.f2453n = Math.min(i13, (i13 * i13) / computeHorizontalScrollRange); } int i14 = this.f2461v; if (i14 == 0 || i14 == 1) { y(1); } } @Override // androidx.recyclerview.widget.RecyclerView.s public void a(RecyclerView recyclerView, MotionEvent motionEvent) { if (this.f2461v == 0) { return; } if (motionEvent.getAction() == 0) { boolean u10 = u(motionEvent.getX(), motionEvent.getY()); boolean t10 = t(motionEvent.getX(), motionEvent.getY()); if (u10 || t10) { if (t10) { this.f2462w = 1; this.f2455p = (int) motionEvent.getX(); } else if (u10) { this.f2462w = 2; this.f2452m = (int) motionEvent.getY(); } y(2); return; } return; } if (motionEvent.getAction() == 1 && this.f2461v == 2) { this.f2452m = 0.0f; this.f2455p = 0.0f; y(1); this.f2462w = 0; return; } if (motionEvent.getAction() == 2 && this.f2461v == 2) { A(); if (this.f2462w == 1) { r(motionEvent.getX()); } if (this.f2462w == 2) { C(motionEvent.getY()); } } } @Override // androidx.recyclerview.widget.RecyclerView.s public boolean b(RecyclerView recyclerView, MotionEvent motionEvent) { int i10 = this.f2461v; if (i10 == 1) { boolean u10 = u(motionEvent.getX(), motionEvent.getY()); boolean t10 = t(motionEvent.getX(), motionEvent.getY()); if (motionEvent.getAction() != 0) { return false; } if (!u10 && !t10) { return false; } if (t10) { this.f2462w = 1; this.f2455p = (int) motionEvent.getX(); } else if (u10) { this.f2462w = 2; this.f2452m = (int) motionEvent.getY(); } y(2); } else if (i10 != 2) { return false; } return true; } @Override // androidx.recyclerview.widget.RecyclerView.s public void c(boolean z10) { } @Override // androidx.recyclerview.widget.RecyclerView.n public void i(Canvas canvas, RecyclerView recyclerView, RecyclerView.a0 a0Var) { if (this.f2456q != this.f2458s.getWidth() || this.f2457r != this.f2458s.getHeight()) { this.f2456q = this.f2458s.getWidth(); this.f2457r = this.f2458s.getHeight(); y(0); } else if (this.A != 0) { if (this.f2459t) { n(canvas); } if (this.f2460u) { m(canvas); } } } public void j(RecyclerView recyclerView) { RecyclerView recyclerView2 = this.f2458s; if (recyclerView2 == recyclerView) { return; } if (recyclerView2 != null) { l(); } this.f2458s = recyclerView; if (recyclerView != null) { z(); } } void q(int i10) { int i11 = this.A; if (i11 == 1) { this.f2465z.cancel(); } else if (i11 != 2) { return; } this.A = 3; ValueAnimator valueAnimator = this.f2465z; valueAnimator.setFloatValues(((Float) valueAnimator.getAnimatedValue()).floatValue(), 0.0f); this.f2465z.setDuration(i10); this.f2465z.start(); } boolean t(float f10, float f11) { if (f11 >= this.f2457r - this.f2448i) { int i10 = this.f2454o; int i11 = this.f2453n; if (f10 >= i10 - (i11 / 2) && f10 <= i10 + (i11 / 2)) { return true; } } return false; } boolean u(float f10, float f11) { if (!s() ? f10 >= this.f2456q - this.f2444e : f10 <= this.f2444e / 2) { int i10 = this.f2451l; int i11 = this.f2450k; if (f11 >= i10 - (i11 / 2) && f11 <= i10 + (i11 / 2)) { return true; } } return false; } void v() { this.f2458s.invalidate(); } void y(int i10) { if (i10 == 2 && this.f2461v != 2) { this.f2442c.setState(D); k(); } if (i10 == 0) { v(); } else { A(); } if (this.f2461v == 2 && i10 != 2) { this.f2442c.setState(E); w(1200); } else if (i10 == 1) { w(ConnectionResult.DRIVE_EXTERNAL_STORAGE_REQUIRED); } this.f2461v = i10; } }