package androidx.recyclerview.widget;

import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.view.View;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
public final class p extends m2 {

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public static TimeInterpolator f3834s;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public ArrayList f3835h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public ArrayList f3836i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public ArrayList f3837j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public ArrayList f3838k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public ArrayList f3839l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public ArrayList f3840m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public ArrayList f3841n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public ArrayList f3842o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public ArrayList f3843p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public ArrayList f3844q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public ArrayList f3845r;

    public static void h(ArrayList arrayList) {
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            ((j2) arrayList.get(size)).itemView.animate().cancel();
        }
    }

    @Override // androidx.recyclerview.widget.l1
    public final void d(j2 j2Var) {
        View view = j2Var.itemView;
        view.animate().cancel();
        ArrayList arrayList = this.f3837j;
        int size = arrayList.size();
        while (true) {
            size--;
            if (size < 0) {
                break;
            }
            if (((o) arrayList.get(size)).f3820a == j2Var) {
                view.setTranslationY(0.0f);
                view.setTranslationX(0.0f);
                c(j2Var);
                arrayList.remove(size);
            }
        }
        j(j2Var, this.f3838k);
        if (this.f3835h.remove(j2Var)) {
            view.setAlpha(1.0f);
            c(j2Var);
        }
        if (this.f3836i.remove(j2Var)) {
            view.setAlpha(1.0f);
            c(j2Var);
        }
        ArrayList arrayList2 = this.f3841n;
        for (int size2 = arrayList2.size() - 1; size2 >= 0; size2--) {
            ArrayList arrayList3 = (ArrayList) arrayList2.get(size2);
            j(j2Var, arrayList3);
            if (arrayList3.isEmpty()) {
                arrayList2.remove(size2);
            }
        }
        ArrayList arrayList4 = this.f3840m;
        for (int size3 = arrayList4.size() - 1; size3 >= 0; size3--) {
            ArrayList arrayList5 = (ArrayList) arrayList4.get(size3);
            int size4 = arrayList5.size() - 1;
            while (true) {
                if (size4 < 0) {
                    break;
                }
                if (((o) arrayList5.get(size4)).f3820a == j2Var) {
                    view.setTranslationY(0.0f);
                    view.setTranslationX(0.0f);
                    c(j2Var);
                    arrayList5.remove(size4);
                    if (arrayList5.isEmpty()) {
                        arrayList4.remove(size3);
                    }
                } else {
                    size4--;
                }
            }
        }
        ArrayList arrayList6 = this.f3839l;
        for (int size5 = arrayList6.size() - 1; size5 >= 0; size5--) {
            ArrayList arrayList7 = (ArrayList) arrayList6.get(size5);
            if (arrayList7.remove(j2Var)) {
                view.setAlpha(1.0f);
                c(j2Var);
                if (arrayList7.isEmpty()) {
                    arrayList6.remove(size5);
                }
            }
        }
        this.f3844q.remove(j2Var);
        this.f3842o.remove(j2Var);
        this.f3845r.remove(j2Var);
        this.f3843p.remove(j2Var);
        i();
    }

    @Override // androidx.recyclerview.widget.l1
    public final void e() {
        ArrayList arrayList = this.f3837j;
        int size = arrayList.size();
        while (true) {
            size--;
            if (size < 0) {
                break;
            }
            o oVar = (o) arrayList.get(size);
            View view = oVar.f3820a.itemView;
            view.setTranslationY(0.0f);
            view.setTranslationX(0.0f);
            c(oVar.f3820a);
            arrayList.remove(size);
        }
        ArrayList arrayList2 = this.f3835h;
        for (int size2 = arrayList2.size() - 1; size2 >= 0; size2--) {
            c((j2) arrayList2.get(size2));
            arrayList2.remove(size2);
        }
        ArrayList arrayList3 = this.f3836i;
        int size3 = arrayList3.size();
        while (true) {
            size3--;
            if (size3 < 0) {
                break;
            }
            j2 j2Var = (j2) arrayList3.get(size3);
            j2Var.itemView.setAlpha(1.0f);
            c(j2Var);
            arrayList3.remove(size3);
        }
        ArrayList arrayList4 = this.f3838k;
        for (int size4 = arrayList4.size() - 1; size4 >= 0; size4--) {
            n nVar = (n) arrayList4.get(size4);
            j2 j2Var2 = nVar.f3784a;
            if (j2Var2 != null) {
                k(nVar, j2Var2);
            }
            j2 j2Var3 = nVar.f3785b;
            if (j2Var3 != null) {
                k(nVar, j2Var3);
            }
        }
        arrayList4.clear();
        if (f()) {
            ArrayList arrayList5 = this.f3840m;
            for (int size5 = arrayList5.size() - 1; size5 >= 0; size5--) {
                ArrayList arrayList6 = (ArrayList) arrayList5.get(size5);
                for (int size6 = arrayList6.size() - 1; size6 >= 0; size6--) {
                    o oVar2 = (o) arrayList6.get(size6);
                    View view2 = oVar2.f3820a.itemView;
                    view2.setTranslationY(0.0f);
                    view2.setTranslationX(0.0f);
                    c(oVar2.f3820a);
                    arrayList6.remove(size6);
                    if (arrayList6.isEmpty()) {
                        arrayList5.remove(arrayList6);
                    }
                }
            }
            ArrayList arrayList7 = this.f3839l;
            for (int size7 = arrayList7.size() - 1; size7 >= 0; size7--) {
                ArrayList arrayList8 = (ArrayList) arrayList7.get(size7);
                for (int size8 = arrayList8.size() - 1; size8 >= 0; size8--) {
                    j2 j2Var4 = (j2) arrayList8.get(size8);
                    j2Var4.itemView.setAlpha(1.0f);
                    c(j2Var4);
                    arrayList8.remove(size8);
                    if (arrayList8.isEmpty()) {
                        arrayList7.remove(arrayList8);
                    }
                }
            }
            ArrayList arrayList9 = this.f3841n;
            for (int size9 = arrayList9.size() - 1; size9 >= 0; size9--) {
                ArrayList arrayList10 = (ArrayList) arrayList9.get(size9);
                for (int size10 = arrayList10.size() - 1; size10 >= 0; size10--) {
                    n nVar2 = (n) arrayList10.get(size10);
                    j2 j2Var5 = nVar2.f3784a;
                    if (j2Var5 != null) {
                        k(nVar2, j2Var5);
                    }
                    j2 j2Var6 = nVar2.f3785b;
                    if (j2Var6 != null) {
                        k(nVar2, j2Var6);
                    }
                    if (arrayList10.isEmpty()) {
                        arrayList9.remove(arrayList10);
                    }
                }
            }
            h(this.f3844q);
            h(this.f3843p);
            h(this.f3842o);
            h(this.f3845r);
            ArrayList arrayList11 = this.f3772b;
            if (arrayList11.size() > 0) {
                com.google.android.gms.measurement.internal.u1.x(arrayList11.get(0));
                throw null;
            }
            arrayList11.clear();
        }
    }

    @Override // androidx.recyclerview.widget.l1
    public final boolean f() {
        return (this.f3836i.isEmpty() && this.f3838k.isEmpty() && this.f3837j.isEmpty() && this.f3835h.isEmpty() && this.f3843p.isEmpty() && this.f3844q.isEmpty() && this.f3842o.isEmpty() && this.f3845r.isEmpty() && this.f3840m.isEmpty() && this.f3839l.isEmpty() && this.f3841n.isEmpty()) ? false : true;
    }

    @Override // androidx.recyclerview.widget.m2
    public final boolean g(j2 j2Var, int i10, int i11, int i12, int i13) {
        View view = j2Var.itemView;
        int translationX = i10 + ((int) view.getTranslationX());
        int translationY = i11 + ((int) j2Var.itemView.getTranslationY());
        l(j2Var);
        int i14 = i12 - translationX;
        int i15 = i13 - translationY;
        if (i14 == 0 && i15 == 0) {
            c(j2Var);
            return false;
        }
        if (i14 != 0) {
            view.setTranslationX(-i14);
        }
        if (i15 != 0) {
            view.setTranslationY(-i15);
        }
        ArrayList arrayList = this.f3837j;
        o oVar = new o();
        oVar.f3820a = j2Var;
        oVar.f3821b = translationX;
        oVar.f3822c = translationY;
        oVar.f3823d = i12;
        oVar.f3824e = i13;
        arrayList.add(oVar);
        return true;
    }

    public final void i() {
        if (f()) {
            return;
        }
        ArrayList arrayList = this.f3772b;
        if (arrayList.size() <= 0) {
            arrayList.clear();
        } else {
            com.google.android.gms.measurement.internal.u1.x(arrayList.get(0));
            throw null;
        }
    }

    public final void j(j2 j2Var, ArrayList arrayList) {
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            n nVar = (n) arrayList.get(size);
            if (k(nVar, j2Var) && nVar.f3784a == null && nVar.f3785b == null) {
                arrayList.remove(nVar);
            }
        }
    }

    public final boolean k(n nVar, j2 j2Var) {
        if (nVar.f3785b == j2Var) {
            nVar.f3785b = null;
        } else {
            if (nVar.f3784a != j2Var) {
                return false;
            }
            nVar.f3784a = null;
        }
        j2Var.itemView.setAlpha(1.0f);
        j2Var.itemView.setTranslationX(0.0f);
        j2Var.itemView.setTranslationY(0.0f);
        c(j2Var);
        return true;
    }

    public final void l(j2 j2Var) {
        if (f3834s == null) {
            f3834s = new ValueAnimator().getInterpolator();
        }
        j2Var.itemView.animate().setInterpolator(f3834s);
        d(j2Var);
    }
}
