package androidx.leanback.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.constraintlayout.widget.ConstraintLayout;
import e0.C0853a;
import java.util.ArrayList;
import n1.InterfaceC1250b;

/* JADX INFO: loaded from: classes.dex */
public final class Q0 implements InterfaceC1250b, z0.g {

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

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

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Object f8514s;

    public Q0(Context context, XmlResourceParser xmlResourceParser) {
        this.f8514s = new ArrayList();
        this.f8513r = -1;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(Xml.asAttributeSet(xmlResourceParser), x.n.f18493g);
        int indexCount = typedArrayObtainStyledAttributes.getIndexCount();
        for (int i = 0; i < indexCount; i++) {
            int index = typedArrayObtainStyledAttributes.getIndex(i);
            if (index == 0) {
                this.f8512q = typedArrayObtainStyledAttributes.getResourceId(index, this.f8512q);
            } else if (index == 1) {
                int resourceId = typedArrayObtainStyledAttributes.getResourceId(index, this.f8513r);
                this.f8513r = resourceId;
                String resourceTypeName = context.getResources().getResourceTypeName(resourceId);
                context.getResources().getResourceName(resourceId);
                if ("layout".equals(resourceTypeName)) {
                    new x.k().b((ConstraintLayout) LayoutInflater.from(context).inflate(resourceId, (ViewGroup) null));
                }
            }
        }
        typedArrayObtainStyledAttributes.recycle();
    }

    @Override // n1.InterfaceC1250b
    public int a() {
        return this.f8512q;
    }

    @Override // n1.InterfaceC1250b
    public int b() {
        return this.f8513r;
    }

    @Override // z0.g
    public z0.h c() {
        return new z0.n(this.f8512q, this.f8513r, (C0853a) this.f8514s);
    }

    @Override // n1.InterfaceC1250b
    public int d() {
        int i = this.f8512q;
        return i == -1 ? ((x0.o) this.f8514s).x() : i;
    }

    public void e() {
        int i;
        int i5 = this.f8512q;
        if (i5 != 2) {
            if (i5 != 3 && i5 != 1) {
                this.f8514s = null;
                return;
            }
            N1.B0 b02 = (N1.B0) this.f8514s;
            if (b02 == null || b02.l() != Integer.MAX_VALUE) {
                this.f8514s = new N1.B0(Integer.MAX_VALUE);
                return;
            }
            return;
        }
        if (this.f8513r <= 0) {
            throw new IllegalArgumentException();
        }
        N1.B0 b03 = (N1.B0) this.f8514s;
        if (b03 != null) {
            synchronized (((d3.E) b03.f4422g)) {
                i = b03.f4417b;
            }
            if (i == this.f8513r) {
                return;
            }
        }
        this.f8514s = new N1.B0(this.f8513r);
    }

    public boolean f() {
        int i = this.f8513r;
        if (i == 0) {
            return false;
        }
        if (i > 0) {
            this.f8513r = i - 1;
        } else {
            this.f8513r = i + 1;
        }
        return true;
    }

    public boolean g() {
        return this.f8513r != 0;
    }

    public boolean h() {
        if (!g()) {
            return true;
        }
        i6.c cVar = (i6.c) this.f8514s;
        if (cVar.i) {
            return false;
        }
        if (cVar.p()) {
            if (!cVar.m() || this.f8513r >= 0) {
                return cVar.l() && this.f8513r > 0;
            }
            return true;
        }
        if (!cVar.l() || this.f8513r >= 0) {
            return cVar.m() && this.f8513r > 0;
        }
        return true;
    }

    public Q0(int i) {
        switch (i) {
            case Z.g.DOUBLE_FIELD_NUMBER /* 7 */:
                this.f8514s = new C0853a(27);
                this.f8512q = 8000;
                this.f8513r = 8000;
                break;
            default:
                this.f8514s = new Q0[256];
                this.f8512q = 0;
                this.f8513r = 0;
                break;
        }
    }
}
