package androidx.recyclerview.widget;

import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.ViewPropertyAnimator;
import androidx.recyclerview.widget.RecyclerView;
import defpackage.sia;
import defpackage.vw2;
import java.util.ArrayList;
import java.util.List;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes.dex */
public class s extends aq {
    public static TimeInterpolator s;
    public ArrayList h;
    public ArrayList i;
    public ArrayList j;
    public ArrayList k;
    public ArrayList l;
    public ArrayList m;
    public ArrayList n;
    public ArrayList o;
    public ArrayList p;
    public ArrayList q;
    public ArrayList r;

    public static class a {
        public RecyclerView.ag a;
        public RecyclerView.ag b;
        public int c;
        public int d;
        public int e;
        public int f;

        public final String toString() {
            StringBuilder sb = new StringBuilder("ChangeInfo{oldHolder=");
            sb.append(this.a);
            sb.append(", newHolder=");
            sb.append(this.b);
            sb.append(", fromX=");
            sb.append(this.c);
            sb.append(", fromY=");
            sb.append(this.d);
            sb.append(", toX=");
            sb.append(this.e);
            sb.append(", toY=");
            return vw2.n(sb, this.f, '}');
        }
    }

    public static class b {
        public RecyclerView.ag a;
        public int b;
        public int c;
        public int d;
        public int e;
    }

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

    @Override // androidx.recyclerview.widget.RecyclerView.l
    public final boolean g(RecyclerView.ag agVar, List list) {
        return !list.isEmpty() || f(agVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.l
    public final void i(RecyclerView.ag agVar) {
        ArrayList arrayList = this.l;
        ArrayList arrayList2 = this.m;
        ArrayList arrayList3 = this.n;
        View view = agVar.itemView;
        view.animate().cancel();
        ArrayList arrayList4 = this.j;
        int size = arrayList4.size();
        while (true) {
            size--;
            if (size < 0) {
                break;
            }
            if (((b) arrayList4.get(size)).a == agVar) {
                view.setTranslationY(0.0f);
                view.setTranslationX(0.0f);
                h(agVar);
                arrayList4.remove(size);
            }
        }
        s(this.k, agVar);
        if (this.h.remove(agVar)) {
            view.setAlpha(1.0f);
            h(agVar);
        }
        if (this.i.remove(agVar)) {
            view.setAlpha(1.0f);
            h(agVar);
        }
        for (int size2 = arrayList3.size() - 1; size2 >= 0; size2--) {
            ArrayList arrayList5 = (ArrayList) arrayList3.get(size2);
            s(arrayList5, agVar);
            if (arrayList5.isEmpty()) {
                arrayList3.remove(size2);
            }
        }
        for (int size3 = arrayList2.size() - 1; size3 >= 0; size3--) {
            ArrayList arrayList6 = (ArrayList) arrayList2.get(size3);
            int size4 = arrayList6.size() - 1;
            while (true) {
                if (size4 < 0) {
                    break;
                }
                if (((b) arrayList6.get(size4)).a == agVar) {
                    view.setTranslationY(0.0f);
                    view.setTranslationX(0.0f);
                    h(agVar);
                    arrayList6.remove(size4);
                    if (arrayList6.isEmpty()) {
                        arrayList2.remove(size3);
                    }
                } else {
                    size4--;
                }
            }
        }
        for (int size5 = arrayList.size() - 1; size5 >= 0; size5--) {
            ArrayList arrayList7 = (ArrayList) arrayList.get(size5);
            if (arrayList7.remove(agVar)) {
                view.setAlpha(1.0f);
                h(agVar);
                if (arrayList7.isEmpty()) {
                    arrayList.remove(size5);
                }
            }
        }
        this.q.remove(agVar);
        this.o.remove(agVar);
        this.r.remove(agVar);
        this.p.remove(agVar);
        r();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.l
    public final void j() {
        ArrayList arrayList = this.n;
        ArrayList arrayList2 = this.l;
        ArrayList arrayList3 = this.m;
        ArrayList arrayList4 = this.k;
        ArrayList arrayList5 = this.i;
        ArrayList arrayList6 = this.h;
        ArrayList arrayList7 = this.j;
        int size = arrayList7.size();
        while (true) {
            size--;
            if (size < 0) {
                break;
            }
            b bVar = (b) arrayList7.get(size);
            View view = bVar.a.itemView;
            view.setTranslationY(0.0f);
            view.setTranslationX(0.0f);
            h(bVar.a);
            arrayList7.remove(size);
        }
        for (int size2 = arrayList6.size() - 1; size2 >= 0; size2--) {
            h((RecyclerView.ag) arrayList6.get(size2));
            arrayList6.remove(size2);
        }
        int size3 = arrayList5.size();
        while (true) {
            size3--;
            if (size3 < 0) {
                break;
            }
            RecyclerView.ag agVar = (RecyclerView.ag) arrayList5.get(size3);
            agVar.itemView.setAlpha(1.0f);
            h(agVar);
            arrayList5.remove(size3);
        }
        for (int size4 = arrayList4.size() - 1; size4 >= 0; size4--) {
            a aVar = (a) arrayList4.get(size4);
            RecyclerView.ag agVar2 = aVar.a;
            if (agVar2 != null) {
                t(aVar, agVar2);
            }
            RecyclerView.ag agVar3 = aVar.b;
            if (agVar3 != null) {
                t(aVar, agVar3);
            }
        }
        arrayList4.clear();
        if (k()) {
            for (int size5 = arrayList3.size() - 1; size5 >= 0; size5--) {
                ArrayList arrayList8 = (ArrayList) arrayList3.get(size5);
                for (int size6 = arrayList8.size() - 1; size6 >= 0; size6--) {
                    b bVar2 = (b) arrayList8.get(size6);
                    View view2 = bVar2.a.itemView;
                    view2.setTranslationY(0.0f);
                    view2.setTranslationX(0.0f);
                    h(bVar2.a);
                    arrayList8.remove(size6);
                    if (arrayList8.isEmpty()) {
                        arrayList3.remove(arrayList8);
                    }
                }
            }
            for (int size7 = arrayList2.size() - 1; size7 >= 0; size7--) {
                ArrayList arrayList9 = (ArrayList) arrayList2.get(size7);
                for (int size8 = arrayList9.size() - 1; size8 >= 0; size8--) {
                    RecyclerView.ag agVar4 = (RecyclerView.ag) arrayList9.get(size8);
                    agVar4.itemView.setAlpha(1.0f);
                    h(agVar4);
                    arrayList9.remove(size8);
                    if (arrayList9.isEmpty()) {
                        arrayList2.remove(arrayList9);
                    }
                }
            }
            for (int size9 = arrayList.size() - 1; size9 >= 0; size9--) {
                ArrayList arrayList10 = (ArrayList) arrayList.get(size9);
                for (int size10 = arrayList10.size() - 1; size10 >= 0; size10--) {
                    a aVar2 = (a) arrayList10.get(size10);
                    RecyclerView.ag agVar5 = aVar2.a;
                    if (agVar5 != null) {
                        t(aVar2, agVar5);
                    }
                    RecyclerView.ag agVar6 = aVar2.b;
                    if (agVar6 != null) {
                        t(aVar2, agVar6);
                    }
                    if (arrayList10.isEmpty()) {
                        arrayList.remove(arrayList10);
                    }
                }
            }
            q(this.q);
            q(this.p);
            q(this.o);
            q(this.r);
            ArrayList arrayList11 = this.b;
            int size11 = arrayList11.size();
            for (int i = 0; i < size11; i++) {
                ((RecyclerView.l.b) arrayList11.get(i)).a();
            }
            arrayList11.clear();
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.l
    public final boolean k() {
        return (this.i.isEmpty() && this.k.isEmpty() && this.j.isEmpty() && this.h.isEmpty() && this.p.isEmpty() && this.q.isEmpty() && this.o.isEmpty() && this.r.isEmpty() && this.m.isEmpty() && this.l.isEmpty() && this.n.isEmpty()) ? false : true;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.l
    public final void l() {
        long j = this.d;
        ArrayList<RecyclerView.ag> arrayList = this.h;
        boolean zIsEmpty = arrayList.isEmpty();
        ArrayList arrayList2 = this.j;
        boolean zIsEmpty2 = arrayList2.isEmpty();
        ArrayList arrayList3 = this.k;
        boolean zIsEmpty3 = arrayList3.isEmpty();
        ArrayList arrayList4 = this.i;
        boolean zIsEmpty4 = arrayList4.isEmpty();
        if (zIsEmpty && zIsEmpty2 && zIsEmpty4 && zIsEmpty3) {
            return;
        }
        for (RecyclerView.ag agVar : arrayList) {
            View view = agVar.itemView;
            ViewPropertyAnimator viewPropertyAnimatorAnimate = view.animate();
            this.q.add(agVar);
            viewPropertyAnimatorAnimate.setDuration(j).alpha(0.0f).setListener(new n(view, viewPropertyAnimatorAnimate, this, agVar)).start();
            arrayList = arrayList;
        }
        arrayList.clear();
        if (!zIsEmpty2) {
            ArrayList arrayList5 = new ArrayList();
            arrayList5.addAll(arrayList2);
            this.m.add(arrayList5);
            arrayList2.clear();
            k kVar = new k(this, arrayList5);
            if (zIsEmpty) {
                kVar.run();
            } else {
                View view2 = ((b) arrayList5.get(0)).a.itemView;
                WeakHashMap weakHashMap = sia.a;
                view2.postOnAnimationDelayed(kVar, j);
            }
        }
        if (!zIsEmpty3) {
            ArrayList arrayList6 = new ArrayList();
            arrayList6.addAll(arrayList3);
            this.n.add(arrayList6);
            arrayList3.clear();
            l lVar = new l(this, arrayList6);
            if (zIsEmpty) {
                lVar.run();
            } else {
                View view3 = ((a) arrayList6.get(0)).a.itemView;
                WeakHashMap weakHashMap2 = sia.a;
                view3.postOnAnimationDelayed(lVar, j);
            }
        }
        if (zIsEmpty4) {
            return;
        }
        ArrayList arrayList7 = new ArrayList();
        arrayList7.addAll(arrayList4);
        this.l.add(arrayList7);
        arrayList4.clear();
        m mVar = new m(this, arrayList7);
        if (zIsEmpty && zIsEmpty2 && zIsEmpty3) {
            mVar.run();
            return;
        }
        if (zIsEmpty) {
            j = 0;
        }
        long jMax = Math.max(!zIsEmpty2 ? this.e : 0L, zIsEmpty3 ? 0L : this.f) + j;
        View view4 = ((RecyclerView.ag) arrayList7.get(0)).itemView;
        WeakHashMap weakHashMap3 = sia.a;
        view4.postOnAnimationDelayed(mVar, jMax);
    }

    @Override // androidx.recyclerview.widget.aq
    public final void m(RecyclerView.ag agVar) {
        u(agVar);
        agVar.itemView.setAlpha(0.0f);
        this.i.add(agVar);
    }

    @Override // androidx.recyclerview.widget.aq
    public final boolean n(RecyclerView.ag agVar, RecyclerView.ag agVar2, int i, int i2, int i3, int i4) {
        if (agVar == agVar2) {
            return o(agVar, i, i2, i3, i4);
        }
        float translationX = agVar.itemView.getTranslationX();
        float translationY = agVar.itemView.getTranslationY();
        float alpha = agVar.itemView.getAlpha();
        u(agVar);
        int i5 = (int) ((i3 - i) - translationX);
        int i6 = (int) ((i4 - i2) - translationY);
        agVar.itemView.setTranslationX(translationX);
        agVar.itemView.setTranslationY(translationY);
        agVar.itemView.setAlpha(alpha);
        if (agVar2 != null) {
            u(agVar2);
            agVar2.itemView.setTranslationX(-i5);
            agVar2.itemView.setTranslationY(-i6);
            agVar2.itemView.setAlpha(0.0f);
        }
        ArrayList arrayList = this.k;
        a aVar = new a();
        aVar.a = agVar;
        aVar.b = agVar2;
        aVar.c = i;
        aVar.d = i2;
        aVar.e = i3;
        aVar.f = i4;
        arrayList.add(aVar);
        return true;
    }

    @Override // androidx.recyclerview.widget.aq
    public final boolean o(RecyclerView.ag agVar, int i, int i2, int i3, int i4) {
        View view = agVar.itemView;
        int translationX = i + ((int) view.getTranslationX());
        int translationY = i2 + ((int) agVar.itemView.getTranslationY());
        u(agVar);
        int i5 = i3 - translationX;
        int i6 = i4 - translationY;
        if (i5 == 0 && i6 == 0) {
            h(agVar);
            return false;
        }
        if (i5 != 0) {
            view.setTranslationX(-i5);
        }
        if (i6 != 0) {
            view.setTranslationY(-i6);
        }
        ArrayList arrayList = this.j;
        b bVar = new b();
        bVar.a = agVar;
        bVar.b = translationX;
        bVar.c = translationY;
        bVar.d = i3;
        bVar.e = i4;
        arrayList.add(bVar);
        return true;
    }

    @Override // androidx.recyclerview.widget.aq
    public final void p(RecyclerView.ag agVar) {
        u(agVar);
        this.h.add(agVar);
    }

    public final void r() {
        if (k()) {
            return;
        }
        ArrayList arrayList = this.b;
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            ((RecyclerView.l.b) arrayList.get(i)).a();
        }
        arrayList.clear();
    }

    public final void s(ArrayList arrayList, RecyclerView.ag agVar) {
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            a aVar = (a) arrayList.get(size);
            if (t(aVar, agVar) && aVar.a == null && aVar.b == null) {
                arrayList.remove(aVar);
            }
        }
    }

    public final boolean t(a aVar, RecyclerView.ag agVar) {
        if (aVar.b == agVar) {
            aVar.b = null;
        } else {
            if (aVar.a != agVar) {
                return false;
            }
            aVar.a = null;
        }
        agVar.itemView.setAlpha(1.0f);
        agVar.itemView.setTranslationX(0.0f);
        agVar.itemView.setTranslationY(0.0f);
        h(agVar);
        return true;
    }

    public final void u(RecyclerView.ag agVar) {
        if (s == null) {
            s = new ValueAnimator().getInterpolator();
        }
        agVar.itemView.animate().setInterpolator(s);
        i(agVar);
    }
}
