package ῲ.䀟.K;

import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import ῲ.ᨨ.㿎.AbstractC1871;
import ῲ.ᨨ.㿎.C1866;
import ῲ.䀟.K.C2344;

/* renamed from: ῲ.䀟.K.K  reason: contains not printable characters */
/* compiled from: AdapterHelper */
public class C2326 implements C2344.AbstractC2345 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final ArrayList<C2327> f8045 = new ArrayList<>();

    /* renamed from: ඓ  reason: contains not printable characters */
    public Runnable f8046;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final ArrayList<C2327> f8047 = new ArrayList<>();

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final C2344 f8048;

    /* renamed from: K  reason: contains not printable characters */
    public AbstractC1871<C2327> f8049 = new C1866(30);

    /* renamed from: 㴹  reason: contains not printable characters */
    public final boolean f8050;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final AbstractC2328 f8051;

    /* renamed from: 㿎  reason: contains not printable characters */
    public int f8052 = 0;

    /* renamed from: ῲ.䀟.K.K$ῲ  reason: contains not printable characters */
    /* compiled from: AdapterHelper */
    public static class C2327 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public Object f8053;

        /* renamed from: ῲ  reason: contains not printable characters */
        public int f8054;

        /* renamed from: K  reason: contains not printable characters */
        public int f8055;

        /* renamed from: 㸾  reason: contains not printable characters */
        public int f8056;

        public C2327(int i, int i2, int i3, Object obj) {
            this.f8055 = i;
            this.f8054 = i2;
            this.f8056 = i3;
            this.f8053 = obj;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null || C2327.class != obj.getClass()) {
                return false;
            }
            C2327 r5 = (C2327) obj;
            int i = this.f8055;
            if (i != r5.f8055) {
                return false;
            }
            if (i == 8 && Math.abs(this.f8056 - this.f8054) == 1 && this.f8056 == r5.f8054 && this.f8054 == r5.f8056) {
                return true;
            }
            if (this.f8056 != r5.f8056 || this.f8054 != r5.f8054) {
                return false;
            }
            Object obj2 = this.f8053;
            if (obj2 != null) {
                if (!obj2.equals(r5.f8053)) {
                    return false;
                }
            } else if (r5.f8053 != null) {
                return false;
            }
            return true;
        }

        public int hashCode() {
            return (((this.f8055 * 31) + this.f8054) * 31) + this.f8056;
        }

        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append(Integer.toHexString(System.identityHashCode(this)));
            sb.append("[");
            int i = this.f8055;
            sb.append(i != 1 ? i != 2 ? i != 4 ? i != 8 ? "??" : "mv" : "up" : "rm" : "add");
            sb.append(",s:");
            sb.append(this.f8054);
            sb.append("c:");
            sb.append(this.f8056);
            sb.append(",p:");
            sb.append(this.f8053);
            sb.append("]");
            return sb.toString();
        }
    }

    /* renamed from: ῲ.䀟.K.K$K  reason: contains not printable characters */
    /* compiled from: AdapterHelper */
    public interface AbstractC2328 {
    }

    public C2326(AbstractC2328 k) {
        this.f8051 = k;
        this.f8050 = false;
        this.f8048 = new C2344(this);
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public boolean m6080() {
        return this.f8047.size() > 0;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final void m6083(C2327 r6) {
        this.f8045.add(r6);
        int i = r6.f8055;
        if (i == 1) {
            AbstractC2328 k = this.f8051;
            RecyclerView.C0263 r0 = (RecyclerView.C0263) k;
            RecyclerView.this.offsetPositionRecordsForInsert(r6.f8054, r6.f8056);
            RecyclerView.this.mItemsAddedOrRemoved = true;
        } else if (i == 2) {
            AbstractC2328 k2 = this.f8051;
            RecyclerView.C0263 r02 = (RecyclerView.C0263) k2;
            RecyclerView.this.offsetPositionRecordsForRemove(r6.f8054, r6.f8056, false);
            RecyclerView.this.mItemsAddedOrRemoved = true;
        } else if (i == 4) {
            ((RecyclerView.C0263) this.f8051).m855(r6.f8054, r6.f8056, r6.f8053);
        } else if (i == 8) {
            AbstractC2328 k3 = this.f8051;
            RecyclerView.C0263 r03 = (RecyclerView.C0263) k3;
            RecyclerView.this.offsetPositionRecordsForMove(r6.f8054, r6.f8056);
            RecyclerView.this.mItemsAddedOrRemoved = true;
        } else {
            throw new IllegalArgumentException("Unknown update op type for " + r6);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6087() {
        int size = this.f8045.size();
        for (int i = 0; i < size; i++) {
            ((RecyclerView.C0263) this.f8051).m856(this.f8045.get(i));
        }
        m6088(this.f8045);
        this.f8052 = 0;
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public void m6095() {
        char c;
        boolean z;
        this.f8048.m6143(this.f8047);
        int size = this.f8047.size();
        for (int i = 0; i < size; i++) {
            C2327 r3 = this.f8047.get(i);
            int i2 = r3.f8055;
            if (i2 == 1) {
                m6083(r3);
            } else if (i2 == 2) {
                int i3 = r3.f8054;
                int i4 = r3.f8056 + i3;
                int i5 = i3;
                int i6 = 0;
                char c2 = 65535;
                while (i5 < i4) {
                    if (((RecyclerView.C0263) this.f8051).m854(i5) != null || m6091(i5)) {
                        if (c2 == 0) {
                            m6089(m6086(2, i3, i6, null));
                            z = true;
                        } else {
                            z = false;
                        }
                        c = 1;
                    } else {
                        if (c2 == 1) {
                            m6083(m6086(2, i3, i6, null));
                            z = true;
                        } else {
                            z = false;
                        }
                        c = 0;
                    }
                    if (z) {
                        i5 -= i6;
                        i4 -= i6;
                        i6 = 1;
                    } else {
                        i6++;
                    }
                    i5++;
                    c2 = c;
                }
                if (i6 != r3.f8056) {
                    if (!this.f8050) {
                        r3.f8053 = null;
                        this.f8049.m4836(r3);
                    }
                    r3 = m6086(2, i3, i6, null);
                }
                if (c2 == 0) {
                    m6089(r3);
                } else {
                    m6083(r3);
                }
            } else if (i2 == 4) {
                int i7 = r3.f8054;
                int i8 = r3.f8056 + i7;
                int i9 = i7;
                int i10 = 0;
                char c3 = 65535;
                while (i7 < i8) {
                    if (((RecyclerView.C0263) this.f8051).m854(i7) != null || m6091(i7)) {
                        if (c3 == 0) {
                            m6089(m6086(4, i9, i10, r3.f8053));
                            i9 = i7;
                            i10 = 0;
                        }
                        c3 = 1;
                    } else {
                        if (c3 == 1) {
                            m6083(m6086(4, i9, i10, r3.f8053));
                            i9 = i7;
                            i10 = 0;
                        }
                        c3 = 0;
                    }
                    i10++;
                    i7++;
                }
                if (i10 != r3.f8056) {
                    Object obj = r3.f8053;
                    if (!this.f8050) {
                        r3.f8053 = null;
                        this.f8049.m4836(r3);
                    }
                    r3 = m6086(4, i9, i10, obj);
                }
                if (c3 == 0) {
                    m6089(r3);
                } else {
                    m6083(r3);
                }
            } else if (i2 == 8) {
                m6083(r3);
            }
            Runnable runnable = this.f8046;
            if (runnable != null) {
                runnable.run();
            }
        }
        this.f8047.clear();
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public boolean m6081(int i, int i2) {
        if (i2 < 1) {
            return false;
        }
        this.f8047.add(m6086(2, i, i2, null));
        this.f8052 |= 2;
        if (this.f8047.size() == 1) {
            return true;
        }
        return false;
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public void m6079(C2327 r2) {
        if (!this.f8050) {
            r2.f8053 = null;
            this.f8049.m4836(r2);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m6089(C2327 r14) {
        int i;
        int i2 = r14.f8055;
        if (i2 == 1 || i2 == 8) {
            throw new IllegalArgumentException("should not dispatch add or move for pre layout");
        }
        int r0 = m6094(r14.f8054, i2);
        int i3 = r14.f8054;
        int i4 = r14.f8055;
        if (i4 == 2) {
            i = 0;
        } else if (i4 == 4) {
            i = 1;
        } else {
            throw new IllegalArgumentException("op should be remove or update." + r14);
        }
        int i5 = r0;
        int i6 = i3;
        int i7 = 1;
        for (int i8 = 1; i8 < r14.f8056; i8++) {
            int r9 = m6094((i * i8) + r14.f8054, r14.f8055);
            int i9 = r14.f8055;
            if (i9 == 2 ? r9 == i5 : i9 == 4 && r9 == i5 + 1) {
                i7++;
            } else {
                C2327 r7 = m6086(r14.f8055, i5, i7, r14.f8053);
                m6090(r7, i6);
                if (!this.f8050) {
                    r7.f8053 = null;
                    this.f8049.m4836(r7);
                }
                if (r14.f8055 == 4) {
                    i6 += i7;
                }
                i5 = r9;
                i7 = 1;
            }
        }
        Object obj = r14.f8053;
        if (!this.f8050) {
            r14.f8053 = null;
            this.f8049.m4836(r14);
        }
        if (i7 > 0) {
            C2327 r142 = m6086(r14.f8055, i5, i7, obj);
            m6090(r142, i6);
            if (!this.f8050) {
                r142.f8053 = null;
                this.f8049.m4836(r142);
            }
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public boolean m6084(int i, int i2) {
        if (i2 < 1) {
            return false;
        }
        this.f8047.add(m6086(1, i, i2, null));
        this.f8052 |= 1;
        if (this.f8047.size() == 1) {
            return true;
        }
        return false;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m6082() {
        m6087();
        int size = this.f8047.size();
        for (int i = 0; i < size; i++) {
            C2327 r3 = this.f8047.get(i);
            int i2 = r3.f8055;
            if (i2 == 1) {
                ((RecyclerView.C0263) this.f8051).m856(r3);
                RecyclerView.C0263 r4 = (RecyclerView.C0263) this.f8051;
                RecyclerView.this.offsetPositionRecordsForInsert(r3.f8054, r3.f8056);
                RecyclerView.this.mItemsAddedOrRemoved = true;
            } else if (i2 == 2) {
                ((RecyclerView.C0263) this.f8051).m856(r3);
                AbstractC2328 k = this.f8051;
                int i3 = r3.f8054;
                int i4 = r3.f8056;
                RecyclerView.C0263 r42 = (RecyclerView.C0263) k;
                RecyclerView.this.offsetPositionRecordsForRemove(i3, i4, true);
                RecyclerView recyclerView = RecyclerView.this;
                recyclerView.mItemsAddedOrRemoved = true;
                recyclerView.mState.f1509 += i4;
            } else if (i2 == 4) {
                ((RecyclerView.C0263) this.f8051).m856(r3);
                ((RecyclerView.C0263) this.f8051).m855(r3.f8054, r3.f8056, r3.f8053);
            } else if (i2 == 8) {
                ((RecyclerView.C0263) this.f8051).m856(r3);
                RecyclerView.C0263 r43 = (RecyclerView.C0263) this.f8051;
                RecyclerView.this.offsetPositionRecordsForMove(r3.f8054, r3.f8056);
                RecyclerView.this.mItemsAddedOrRemoved = true;
            }
            Runnable runnable = this.f8046;
            if (runnable != null) {
                runnable.run();
            }
        }
        m6088(this.f8047);
        this.f8052 = 0;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6090(C2327 r5, int i) {
        ((RecyclerView.C0263) this.f8051).m856(r5);
        int i2 = r5.f8055;
        if (i2 == 2) {
            AbstractC2328 k = this.f8051;
            int i3 = r5.f8056;
            RecyclerView.C0263 r0 = (RecyclerView.C0263) k;
            RecyclerView.this.offsetPositionRecordsForRemove(i, i3, true);
            RecyclerView recyclerView = RecyclerView.this;
            recyclerView.mItemsAddedOrRemoved = true;
            recyclerView.mState.f1509 += i3;
        } else if (i2 == 4) {
            RecyclerView.C0263 r02 = (RecyclerView.C0263) this.f8051;
            RecyclerView.this.viewRangeUpdate(i, r5.f8056, r5.f8053);
            RecyclerView.this.mItemsChanged = true;
        } else {
            throw new IllegalArgumentException("only remove and update ops can be dispatched in first pass");
        }
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public final int m6094(int i, int i2) {
        for (int size = this.f8045.size() - 1; size >= 0; size--) {
            C2327 r3 = this.f8045.get(size);
            int i3 = r3.f8055;
            if (i3 == 8) {
                int i4 = r3.f8054;
                int i5 = r3.f8056;
                if (i4 >= i5) {
                    i5 = i4;
                    i4 = i5;
                }
                if (i < i4 || i > i5) {
                    int i6 = r3.f8054;
                    if (i < i6) {
                        if (i2 == 1) {
                            r3.f8054 = i6 + 1;
                            r3.f8056++;
                        } else if (i2 == 2) {
                            r3.f8054 = i6 - 1;
                            r3.f8056--;
                        }
                    }
                } else {
                    int i7 = r3.f8054;
                    if (i4 == i7) {
                        if (i2 == 1) {
                            r3.f8056++;
                        } else if (i2 == 2) {
                            r3.f8056--;
                        }
                        i++;
                    } else {
                        if (i2 == 1) {
                            r3.f8054 = i7 + 1;
                        } else if (i2 == 2) {
                            r3.f8054 = i7 - 1;
                        }
                        i--;
                    }
                }
            } else {
                int i8 = r3.f8054;
                if (i8 <= i) {
                    if (i3 == 1) {
                        i -= r3.f8056;
                    } else if (i3 == 2) {
                        i += r3.f8056;
                    }
                } else if (i2 == 1) {
                    r3.f8054 = i8 + 1;
                } else if (i2 == 2) {
                    r3.f8054 = i8 - 1;
                }
            }
        }
        for (int size2 = this.f8045.size() - 1; size2 >= 0; size2--) {
            C2327 r0 = this.f8045.get(size2);
            if (r0.f8055 == 8) {
                int i9 = r0.f8056;
                if (i9 == r0.f8054 || i9 < 0) {
                    this.f8045.remove(size2);
                    if (!this.f8050) {
                        r0.f8053 = null;
                        this.f8049.m4836(r0);
                    }
                }
            } else if (r0.f8056 <= 0) {
                this.f8045.remove(size2);
                if (!this.f8050) {
                    r0.f8053 = null;
                    this.f8049.m4836(r0);
                }
            }
        }
        return i;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final boolean m6091(int i) {
        int size = this.f8045.size();
        for (int i2 = 0; i2 < size; i2++) {
            C2327 r3 = this.f8045.get(i2);
            int i3 = r3.f8055;
            if (i3 == 8) {
                if (m6085(r3.f8056, i2 + 1) == i) {
                    return true;
                }
            } else if (i3 == 1) {
                int i4 = r3.f8054;
                int i5 = r3.f8056 + i4;
                while (i4 < i5) {
                    if (m6085(i4, i2 + 1) == i) {
                        return true;
                    }
                    i4++;
                }
                continue;
            } else {
                continue;
            }
        }
        return false;
    }

    /* renamed from: K  reason: contains not printable characters */
    public int m6085(int i, int i2) {
        int size = this.f8045.size();
        while (i2 < size) {
            C2327 r1 = this.f8045.get(i2);
            int i3 = r1.f8055;
            if (i3 == 8) {
                int i4 = r1.f8054;
                if (i4 == i) {
                    i = r1.f8056;
                } else {
                    if (i4 < i) {
                        i--;
                    }
                    if (r1.f8056 <= i) {
                        i++;
                    }
                }
            } else {
                int i5 = r1.f8054;
                if (i5 > i) {
                    continue;
                } else if (i3 == 2) {
                    int i6 = r1.f8056;
                    if (i < i5 + i6) {
                        return -1;
                    }
                    i -= i6;
                } else if (i3 == 1) {
                    i += r1.f8056;
                }
            }
            i2++;
        }
        return i;
    }

    /* renamed from: K  reason: contains not printable characters */
    public boolean m6093(int i, int i2, Object obj) {
        if (i2 < 1) {
            return false;
        }
        this.f8047.add(m6086(4, i, i2, obj));
        this.f8052 |= 4;
        if (this.f8047.size() == 1) {
            return true;
        }
        return false;
    }

    /* renamed from: K  reason: contains not printable characters */
    public boolean m6092(int i, int i2, int i3) {
        if (i == i2) {
            return false;
        }
        if (i3 == 1) {
            this.f8047.add(m6086(8, i, i2, null));
            this.f8052 |= 8;
            if (this.f8047.size() == 1) {
                return true;
            }
            return false;
        }
        throw new IllegalArgumentException("Moving more than 1 item is not supported yet");
    }

    /* renamed from: K  reason: contains not printable characters */
    public C2327 m6086(int i, int i2, int i3, Object obj) {
        C2327 r0 = this.f8049.m4835();
        if (r0 == null) {
            return new C2327(i, i2, i3, obj);
        }
        r0.f8055 = i;
        r0.f8054 = i2;
        r0.f8056 = i3;
        r0.f8053 = obj;
        return r0;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6088(List<C2327> list) {
        int size = list.size();
        for (int i = 0; i < size; i++) {
            m6079(list.get(i));
        }
        list.clear();
    }
}
