package i0;

import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.Base64;
import android.util.Xml;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import tv.danmaku.ijk.media.player.IjkEventListener;

/* JADX INFO: loaded from: classes.dex */
public abstract class i {
    public static List a(Resources resources, int i10) {
        if (i10 == 0) {
            return Collections.emptyList();
        }
        TypedArray typedArrayObtainTypedArray = resources.obtainTypedArray(i10);
        try {
            if (typedArrayObtainTypedArray.length() == 0) {
                return Collections.emptyList();
            }
            ArrayList arrayList = new ArrayList();
            if (typedArrayObtainTypedArray.getType(0) == 1) {
                for (int i11 = 0; i11 < typedArrayObtainTypedArray.length(); i11++) {
                    int resourceId = typedArrayObtainTypedArray.getResourceId(i11, 0);
                    if (resourceId != 0) {
                        String[] stringArray = resources.getStringArray(resourceId);
                        ArrayList arrayList2 = new ArrayList();
                        for (String str : stringArray) {
                            arrayList2.add(Base64.decode(str, 0));
                        }
                        arrayList.add(arrayList2);
                    }
                }
            } else {
                String[] stringArray2 = resources.getStringArray(i10);
                ArrayList arrayList3 = new ArrayList();
                for (String str2 : stringArray2) {
                    arrayList3.add(Base64.decode(str2, 0));
                }
                arrayList.add(arrayList3);
            }
            return arrayList;
        } finally {
            typedArrayObtainTypedArray.recycle();
        }
    }

    public static void b(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
        int i10 = 1;
        while (i10 > 0) {
            int next = xmlPullParser.next();
            if (next == 2) {
                i10++;
            } else if (next == 3) {
                i10--;
            }
        }
    }

    @Nullable
    public static e parse(@NonNull XmlPullParser xmlPullParser, @NonNull Resources resources) throws XmlPullParserException, IOException {
        int next;
        do {
            next = xmlPullParser.next();
            if (next == 2) {
                break;
            }
        } while (next != 1);
        if (next == 2) {
            return readFamilies(xmlPullParser, resources);
        }
        throw new XmlPullParserException("No start tag found");
    }

    @Nullable
    private static e readFamilies(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        xmlPullParser.require(2, null, "font-family");
        if (xmlPullParser.getName().equals("font-family")) {
            return readFamily(xmlPullParser, resources);
        }
        b(xmlPullParser);
        return null;
    }

    @Nullable
    private static e readFamily(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        TypedArray typedArrayObtainAttributes = resources.obtainAttributes(Xml.asAttributeSet(xmlPullParser), e0.h.FontFamily);
        String string = typedArrayObtainAttributes.getString(e0.h.FontFamily_fontProviderAuthority);
        String string2 = typedArrayObtainAttributes.getString(e0.h.FontFamily_fontProviderPackage);
        String string3 = typedArrayObtainAttributes.getString(e0.h.FontFamily_fontProviderQuery);
        String string4 = typedArrayObtainAttributes.getString(e0.h.FontFamily_fontProviderFallbackQuery);
        int resourceId = typedArrayObtainAttributes.getResourceId(e0.h.FontFamily_fontProviderCerts, 0);
        int integer = typedArrayObtainAttributes.getInteger(e0.h.FontFamily_fontProviderFetchStrategy, 1);
        int integer2 = typedArrayObtainAttributes.getInteger(e0.h.FontFamily_fontProviderFetchTimeout, IjkEventListener.BUFFERING_START);
        String string5 = typedArrayObtainAttributes.getString(e0.h.FontFamily_fontProviderSystemFontFamily);
        typedArrayObtainAttributes.recycle();
        if (string != null && string2 != null && string3 != null) {
            while (xmlPullParser.next() != 3) {
                b(xmlPullParser);
            }
            List listA = a(resources, resourceId);
            return new h(new n0.e(string, string2, string3, listA), string4 != null ? new n0.e(string, string2, string4, listA) : null, integer, integer2, string5);
        }
        ArrayList arrayList = new ArrayList();
        while (xmlPullParser.next() != 3) {
            if (xmlPullParser.getEventType() == 2) {
                if (xmlPullParser.getName().equals("font")) {
                    TypedArray typedArrayObtainAttributes2 = resources.obtainAttributes(Xml.asAttributeSet(xmlPullParser), e0.h.FontFamilyFont);
                    int i10 = e0.h.FontFamilyFont_fontWeight;
                    if (!typedArrayObtainAttributes2.hasValue(i10)) {
                        i10 = e0.h.FontFamilyFont_android_fontWeight;
                    }
                    int i11 = typedArrayObtainAttributes2.getInt(i10, IjkEventListener.VIDEO_SIZE_CHANGED);
                    int i12 = e0.h.FontFamilyFont_fontStyle;
                    if (!typedArrayObtainAttributes2.hasValue(i12)) {
                        i12 = e0.h.FontFamilyFont_android_fontStyle;
                    }
                    boolean z10 = 1 == typedArrayObtainAttributes2.getInt(i12, 0);
                    int i13 = e0.h.FontFamilyFont_ttcIndex;
                    if (!typedArrayObtainAttributes2.hasValue(i13)) {
                        i13 = e0.h.FontFamilyFont_android_ttcIndex;
                    }
                    int i14 = e0.h.FontFamilyFont_fontVariationSettings;
                    if (!typedArrayObtainAttributes2.hasValue(i14)) {
                        i14 = e0.h.FontFamilyFont_android_fontVariationSettings;
                    }
                    String string6 = typedArrayObtainAttributes2.getString(i14);
                    int i15 = typedArrayObtainAttributes2.getInt(i13, 0);
                    int i16 = e0.h.FontFamilyFont_font;
                    if (!typedArrayObtainAttributes2.hasValue(i16)) {
                        i16 = e0.h.FontFamilyFont_android_font;
                    }
                    int resourceId2 = typedArrayObtainAttributes2.getResourceId(i16, 0);
                    String string7 = typedArrayObtainAttributes2.getString(i16);
                    typedArrayObtainAttributes2.recycle();
                    while (xmlPullParser.next() != 3) {
                        b(xmlPullParser);
                    }
                    arrayList.add(new g(string7, i11, z10, string6, i15, resourceId2));
                } else {
                    b(xmlPullParser);
                }
            }
        }
        if (arrayList.isEmpty()) {
            return null;
        }
        return new f((g[]) arrayList.toArray(new g[0]));
    }
}
