package androidx.recyclerview.widget;

import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
public final class f {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final e f3692a;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public View f3696e;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f3695d = 0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final d f3693b = new d(0);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ArrayList f3694c = new ArrayList();

    public f(c1 c1Var) {
        this.f3692a = c1Var;
    }

    public final void a(View view, int i10, boolean z10) {
        e eVar = this.f3692a;
        int childCount = i10 < 0 ? ((c1) eVar).f3680a.getChildCount() : f(i10);
        this.f3693b.e(childCount, z10);
        if (z10) {
            i(view);
        }
        RecyclerView recyclerView = ((c1) eVar).f3680a;
        recyclerView.addView(view, childCount);
        recyclerView.dispatchChildAttached(view);
    }

    public final void b(View view, int i10, ViewGroup.LayoutParams layoutParams, boolean z10) {
        e eVar = this.f3692a;
        int childCount = i10 < 0 ? ((c1) eVar).f3680a.getChildCount() : f(i10);
        this.f3693b.e(childCount, z10);
        if (z10) {
            i(view);
        }
        c1 c1Var = (c1) eVar;
        c1Var.getClass();
        j2 childViewHolderInt = RecyclerView.getChildViewHolderInt(view);
        RecyclerView recyclerView = c1Var.f3680a;
        if (childViewHolderInt != null) {
            if (!childViewHolderInt.isTmpDetached() && !childViewHolderInt.shouldIgnore()) {
                StringBuilder sb = new StringBuilder("Called attach on a child which is not detached: ");
                sb.append(childViewHolderInt);
                throw new IllegalArgumentException(defpackage.e.d(recyclerView, sb));
            }
            if (RecyclerView.sVerboseLoggingEnabled) {
                childViewHolderInt.toString();
            }
            childViewHolderInt.clearTmpDetachFlag();
        } else if (RecyclerView.sDebugAssertionsEnabled) {
            StringBuilder sb2 = new StringBuilder("No ViewHolder found for child: ");
            sb2.append(view);
            sb2.append(", index: ");
            sb2.append(childCount);
            throw new IllegalArgumentException(defpackage.e.d(recyclerView, sb2));
        }
        recyclerView.attachViewToParent(view, childCount, layoutParams);
    }

    public final void c(int i10) {
        int iF = f(i10);
        this.f3693b.f(iF);
        RecyclerView recyclerView = ((c1) this.f3692a).f3680a;
        View childAt = recyclerView.getChildAt(iF);
        if (childAt != null) {
            j2 childViewHolderInt = RecyclerView.getChildViewHolderInt(childAt);
            if (childViewHolderInt != null) {
                if (childViewHolderInt.isTmpDetached() && !childViewHolderInt.shouldIgnore()) {
                    StringBuilder sb = new StringBuilder("called detach on an already detached child ");
                    sb.append(childViewHolderInt);
                    throw new IllegalArgumentException(defpackage.e.d(recyclerView, sb));
                }
                if (RecyclerView.sVerboseLoggingEnabled) {
                    childViewHolderInt.toString();
                }
                childViewHolderInt.addFlags(256);
            }
        } else if (RecyclerView.sDebugAssertionsEnabled) {
            StringBuilder sb2 = new StringBuilder("No view at offset ");
            sb2.append(iF);
            throw new IllegalArgumentException(defpackage.e.d(recyclerView, sb2));
        }
        recyclerView.detachViewFromParent(iF);
    }

    public final View d(int i10) {
        return ((c1) this.f3692a).f3680a.getChildAt(f(i10));
    }

    public final int e() {
        return ((c1) this.f3692a).f3680a.getChildCount() - this.f3694c.size();
    }

    public final int f(int i10) {
        if (i10 < 0) {
            return -1;
        }
        int childCount = ((c1) this.f3692a).f3680a.getChildCount();
        int i11 = i10;
        while (i11 < childCount) {
            d dVar = this.f3693b;
            int iB = i10 - (i11 - dVar.b(i11));
            if (iB == 0) {
                while (dVar.d(i11)) {
                    i11++;
                }
                return i11;
            }
            i11 += iB;
        }
        return -1;
    }

    public final View g(int i10) {
        return ((c1) this.f3692a).f3680a.getChildAt(i10);
    }

    public final int h() {
        return ((c1) this.f3692a).f3680a.getChildCount();
    }

    public final void i(View view) {
        this.f3694c.add(view);
        c1 c1Var = (c1) this.f3692a;
        c1Var.getClass();
        j2 childViewHolderInt = RecyclerView.getChildViewHolderInt(view);
        if (childViewHolderInt != null) {
            childViewHolderInt.onEnteredHiddenState(c1Var.f3680a);
        }
    }

    public final int j(View view) {
        int iIndexOfChild = ((c1) this.f3692a).f3680a.indexOfChild(view);
        if (iIndexOfChild == -1) {
            return -1;
        }
        d dVar = this.f3693b;
        if (dVar.d(iIndexOfChild)) {
            return -1;
        }
        return iIndexOfChild - dVar.b(iIndexOfChild);
    }

    public final boolean k(View view) {
        return this.f3694c.contains(view);
    }

    public final void l(int i10) {
        e eVar = this.f3692a;
        int i11 = this.f3695d;
        if (i11 == 1) {
            throw new IllegalStateException("Cannot call removeView(At) within removeView(At)");
        }
        if (i11 == 2) {
            throw new IllegalStateException("Cannot call removeView(At) within removeViewIfHidden");
        }
        try {
            int iF = f(i10);
            View childAt = ((c1) eVar).f3680a.getChildAt(iF);
            if (childAt == null) {
                this.f3695d = 0;
                this.f3696e = null;
                return;
            }
            this.f3695d = 1;
            this.f3696e = childAt;
            if (this.f3693b.f(iF)) {
                m(childAt);
            }
            ((c1) eVar).b(iF);
            this.f3695d = 0;
            this.f3696e = null;
        } catch (Throwable th) {
            this.f3695d = 0;
            this.f3696e = null;
            throw th;
        }
    }

    public final void m(View view) {
        if (this.f3694c.remove(view)) {
            c1 c1Var = (c1) this.f3692a;
            c1Var.getClass();
            j2 childViewHolderInt = RecyclerView.getChildViewHolderInt(view);
            if (childViewHolderInt != null) {
                childViewHolderInt.onLeftHiddenState(c1Var.f3680a);
            }
        }
    }

    public final String toString() {
        return this.f3693b.toString() + ", hidden list:" + this.f3694c.size();
    }
}
