package c.b;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewParent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import c.b.f.j1;
import c.b.f.t0;
import c.e.b.h.d;
import c.e.b.h.f;
import c.e.b.h.h;
import c.e.b.h.l.n;
import c.f.c.b.e;
import c.f.c.b.k;
import java.util.ArrayList;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes.dex */
public final class a {
    /* JADX WARN: Removed duplicated region for block: B:131:0x0200 A[PHI: r7 r21
      0x0200: PHI (r7v4 boolean) = (r7v2 boolean), (r7v54 boolean) binds: [B:130:0x01fe, B:121:0x01eb] A[DONT_GENERATE, DONT_INLINE]
      0x0200: PHI (r21v3 boolean) = (r21v1 boolean), (r21v6 boolean) binds: [B:130:0x01fe, B:121:0x01eb] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:133:0x0206 A[PHI: r7 r21
      0x0206: PHI (r7v52 boolean) = (r7v2 boolean), (r7v54 boolean) binds: [B:130:0x01fe, B:121:0x01eb] A[DONT_GENERATE, DONT_INLINE]
      0x0206: PHI (r21v5 boolean) = (r21v1 boolean), (r21v6 boolean) binds: [B:130:0x01fe, B:121:0x01eb] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:181:0x02d5  */
    /* JADX WARN: Removed duplicated region for block: B:201:0x032b  */
    /* JADX WARN: Removed duplicated region for block: B:207:0x0355  */
    /* JADX WARN: Removed duplicated region for block: B:293:0x0520  */
    /* JADX WARN: Removed duplicated region for block: B:405:0x071d  */
    /* JADX WARN: Removed duplicated region for block: B:406:0x0720  */
    /* JADX WARN: Removed duplicated region for block: B:409:0x0726  */
    /* JADX WARN: Removed duplicated region for block: B:410:0x0729  */
    /* JADX WARN: Removed duplicated region for block: B:412:0x072d  */
    /* JADX WARN: Removed duplicated region for block: B:416:0x073c  */
    /* JADX WARN: Removed duplicated region for block: B:418:0x073f  */
    /* JADX WARN: Removed duplicated region for block: B:420:0x0745 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:430:0x0762 A[ADDED_TO_REGION, REMOVE, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0126  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x014e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static void a(c.e.b.h.e r36, c.e.b.d r37, java.util.ArrayList<c.e.b.h.d> r38, int r39) {
        /*
            Method dump skipped, instruction units count: 1904
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.a.a(c.e.b.h.e, c.e.b.d, java.util.ArrayList, int):void");
    }

    public static n b(d dVar, int i2, ArrayList<n> arrayList, n nVar) {
        int i3;
        int i4 = i2 == 0 ? dVar.j0 : dVar.k0;
        if (i4 != -1 && (nVar == null || i4 != nVar.f1175c)) {
            int i5 = 0;
            while (true) {
                if (i5 >= arrayList.size()) {
                    break;
                }
                n nVar2 = arrayList.get(i5);
                if (nVar2.f1175c == i4) {
                    if (nVar != null) {
                        nVar.d(i2, nVar2);
                        arrayList.remove(nVar);
                    }
                    nVar = nVar2;
                } else {
                    i5++;
                }
            }
        } else if (i4 != -1) {
            return nVar;
        }
        if (nVar == null) {
            if (dVar instanceof h) {
                h hVar = (h) dVar;
                int i6 = 0;
                while (true) {
                    if (i6 >= hVar.m0) {
                        i3 = -1;
                        break;
                    }
                    d dVar2 = hVar.l0[i6];
                    if ((i2 == 0 && (i3 = dVar2.j0) != -1) || (i2 == 1 && (i3 = dVar2.k0) != -1)) {
                        break;
                    }
                    i6++;
                }
                if (i3 != -1) {
                    int i7 = 0;
                    while (true) {
                        if (i7 >= arrayList.size()) {
                            break;
                        }
                        n nVar3 = arrayList.get(i7);
                        if (nVar3.f1175c == i3) {
                            nVar = nVar3;
                            break;
                        }
                        i7++;
                    }
                }
            }
            if (nVar == null) {
                nVar = new n(i2);
            }
            arrayList.add(nVar);
        }
        if (nVar.a(dVar)) {
            if (dVar instanceof f) {
                f fVar = (f) dVar;
                fVar.o0.b(fVar.p0 == 0 ? 1 : 0, arrayList, nVar);
            }
            if (i2 == 0) {
                dVar.j0 = nVar.f1175c;
                dVar.D.b(i2, arrayList, nVar);
                dVar.F.b(i2, arrayList, nVar);
            } else {
                dVar.k0 = nVar.f1175c;
                dVar.E.b(i2, arrayList, nVar);
                dVar.H.b(i2, arrayList, nVar);
                dVar.G.b(i2, arrayList, nVar);
            }
            dVar.K.b(i2, arrayList, nVar);
        }
        return nVar;
    }

    public static n c(ArrayList<n> arrayList, int i2) {
        int size = arrayList.size();
        for (int i3 = 0; i3 < size; i3++) {
            n nVar = arrayList.get(i3);
            if (i2 == nVar.f1175c) {
                return nVar;
            }
        }
        return null;
    }

    public static ColorStateList d(Context context, int i2) {
        ColorStateList colorStateListA;
        ColorStateList colorStateList;
        k.c cVar;
        Object obj = c.f.c.a.a;
        Resources resources = context.getResources();
        Resources.Theme theme = context.getTheme();
        k.d dVar = new k.d(resources, theme);
        synchronized (k.f1316c) {
            SparseArray<k.c> sparseArray = k.f1315b.get(dVar);
            colorStateListA = null;
            if (sparseArray == null || sparseArray.size() <= 0 || (cVar = sparseArray.get(i2)) == null) {
                colorStateList = null;
            } else if (!cVar.f1317b.equals(resources.getConfiguration()) || (!(theme == null && cVar.f1318c == 0) && (theme == null || cVar.f1318c != theme.hashCode()))) {
                sparseArray.remove(i2);
                colorStateList = null;
            } else {
                colorStateList = cVar.a;
            }
        }
        if (colorStateList != null) {
            return colorStateList;
        }
        ThreadLocal<TypedValue> threadLocal = k.a;
        TypedValue typedValue = threadLocal.get();
        if (typedValue == null) {
            typedValue = new TypedValue();
            threadLocal.set(typedValue);
        }
        resources.getValue(i2, typedValue, true);
        int i3 = typedValue.type;
        if (!(i3 >= 28 && i3 <= 31)) {
            try {
                colorStateListA = e.a(resources, resources.getXml(i2), theme);
            } catch (Exception e2) {
                Log.w("ResourcesCompat", "Failed to inflate ColorStateList, leaving it to the framework", e2);
            }
        }
        if (colorStateListA == null) {
            return k.b.b(resources, i2, theme);
        }
        synchronized (k.f1316c) {
            WeakHashMap<k.d, SparseArray<k.c>> weakHashMap = k.f1315b;
            SparseArray<k.c> sparseArray2 = weakHashMap.get(dVar);
            if (sparseArray2 == null) {
                sparseArray2 = new SparseArray<>();
                weakHashMap.put(dVar, sparseArray2);
            }
            sparseArray2.append(i2, new k.c(colorStateListA, dVar.a.getConfiguration(), theme));
        }
        return colorStateListA;
    }

    public static Drawable e(Context context, int i2) {
        return t0.c().e(context, i2);
    }

    public static InputConnection f(InputConnection inputConnection, EditorInfo editorInfo, View view) {
        if (inputConnection != null && editorInfo.hintText == null) {
            ViewParent parent = view.getParent();
            while (true) {
                if (!(parent instanceof View)) {
                    break;
                }
                if (parent instanceof j1) {
                    editorInfo.hintText = ((j1) parent).a();
                    break;
                }
                parent = parent.getParent();
            }
        }
        return inputConnection;
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x004f A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static void g(android.content.Context r6, java.lang.String r7) {
        /*
            java.lang.String r0 = "locales"
            java.lang.String r1 = "AppLocalesStorageHelper"
            java.lang.String r2 = ""
            boolean r2 = r7.equals(r2)
            java.lang.String r3 = "androidx.appcompat.app.AppCompatDelegate.application_locales_record_file"
            if (r2 == 0) goto L12
            r6.deleteFile(r3)
            return
        L12:
            r2 = 0
            java.io.FileOutputStream r6 = r6.openFileOutput(r3, r2)     // Catch: java.io.FileNotFoundException -> L74
            org.xmlpull.v1.XmlSerializer r2 = android.util.Xml.newSerializer()
            r3 = 0
            r2.setOutput(r6, r3)     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            java.lang.String r4 = "UTF-8"
            java.lang.Boolean r5 = java.lang.Boolean.TRUE     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            r2.startDocument(r4, r5)     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            r2.startTag(r3, r0)     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            java.lang.String r4 = "application_locales"
            r2.attribute(r3, r4, r7)     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            r2.endTag(r3, r0)     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            r2.endDocument()     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            java.lang.StringBuilder r0 = new java.lang.StringBuilder     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            r0.<init>()     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            java.lang.String r2 = "Storing App Locales : app-locales: "
            r0.append(r2)     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            r0.append(r7)     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            java.lang.String r2 = " persisted successfully."
            r0.append(r2)     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            java.lang.String r0 = r0.toString()     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            android.util.Log.d(r1, r0)     // Catch: java.lang.Throwable -> L53 java.lang.Exception -> L55
            if (r6 == 0) goto L6d
        L4f:
            r6.close()     // Catch: java.io.IOException -> L6d
            goto L6d
        L53:
            r7 = move-exception
            goto L6e
        L55:
            r0 = move-exception
            java.lang.StringBuilder r2 = new java.lang.StringBuilder     // Catch: java.lang.Throwable -> L53
            r2.<init>()     // Catch: java.lang.Throwable -> L53
            java.lang.String r3 = "Storing App Locales : Failed to persist app-locales: "
            r2.append(r3)     // Catch: java.lang.Throwable -> L53
            r2.append(r7)     // Catch: java.lang.Throwable -> L53
            java.lang.String r7 = r2.toString()     // Catch: java.lang.Throwable -> L53
            android.util.Log.w(r1, r7, r0)     // Catch: java.lang.Throwable -> L53
            if (r6 == 0) goto L6d
            goto L4f
        L6d:
            return
        L6e:
            if (r6 == 0) goto L73
            r6.close()     // Catch: java.io.IOException -> L73
        L73:
            throw r7
        L74:
            r6 = 1
            java.lang.Object[] r6 = new java.lang.Object[r6]
            r6[r2] = r3
            java.lang.String r7 = "Storing App Locales : FileNotFoundException: Cannot open file %s for writing "
            java.lang.String r6 = java.lang.String.format(r7, r6)
            android.util.Log.w(r1, r6)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.a.g(android.content.Context, java.lang.String):void");
    }

    /* JADX WARN: Code restructure failed: missing block: B:17:0x0039, code lost:
    
        r2 = r4.getAttributeValue(null, "application_locales");
     */
    /* JADX WARN: Removed duplicated region for block: B:44:0x004c A[EXC_TOP_SPLITTER, PHI: r2
      0x004c: PHI (r2v2 java.lang.String) = (r2v0 java.lang.String), (r2v4 java.lang.String) binds: [B:23:0x004a, B:18:0x0040] A[DONT_GENERATE, DONT_INLINE], SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static java.lang.String h(android.content.Context r9) {
        /*
            java.lang.String r0 = "androidx.appcompat.app.AppCompatDelegate.application_locales_record_file"
            java.lang.String r1 = "AppLocalesStorageHelper"
            java.lang.String r2 = ""
            java.io.FileInputStream r3 = r9.openFileInput(r0)     // Catch: java.io.FileNotFoundException -> L65
            org.xmlpull.v1.XmlPullParser r4 = android.util.Xml.newPullParser()     // Catch: java.lang.Throwable -> L43 java.lang.Throwable -> L45
            java.lang.String r5 = "UTF-8"
            r4.setInput(r3, r5)     // Catch: java.lang.Throwable -> L43 java.lang.Throwable -> L45
            int r5 = r4.getDepth()     // Catch: java.lang.Throwable -> L43 java.lang.Throwable -> L45
        L17:
            int r6 = r4.next()     // Catch: java.lang.Throwable -> L43 java.lang.Throwable -> L45
            r7 = 1
            if (r6 == r7) goto L40
            r7 = 3
            if (r6 != r7) goto L27
            int r8 = r4.getDepth()     // Catch: java.lang.Throwable -> L43 java.lang.Throwable -> L45
            if (r8 <= r5) goto L40
        L27:
            if (r6 == r7) goto L17
            r7 = 4
            if (r6 != r7) goto L2d
            goto L17
        L2d:
            java.lang.String r6 = r4.getName()     // Catch: java.lang.Throwable -> L43 java.lang.Throwable -> L45
            java.lang.String r7 = "locales"
            boolean r6 = r6.equals(r7)     // Catch: java.lang.Throwable -> L43 java.lang.Throwable -> L45
            if (r6 == 0) goto L17
            r5 = 0
            java.lang.String r6 = "application_locales"
            java.lang.String r2 = r4.getAttributeValue(r5, r6)     // Catch: java.lang.Throwable -> L43 java.lang.Throwable -> L45
        L40:
            if (r3 == 0) goto L4f
            goto L4c
        L43:
            r9 = move-exception
            goto L5f
        L45:
            java.lang.String r4 = "Reading app Locales : Unable to parse through file :androidx.appcompat.app.AppCompatDelegate.application_locales_record_file"
            android.util.Log.w(r1, r4)     // Catch: java.lang.Throwable -> L43
            if (r3 == 0) goto L4f
        L4c:
            r3.close()     // Catch: java.io.IOException -> L4f
        L4f:
            boolean r3 = r2.isEmpty()
            if (r3 != 0) goto L5b
            java.lang.String r9 = "Reading app Locales : Locales read from file: androidx.appcompat.app.AppCompatDelegate.application_locales_record_file , appLocales: "
            d.b.a.a.a.N(r9, r2, r1)
            goto L5e
        L5b:
            r9.deleteFile(r0)
        L5e:
            return r2
        L5f:
            if (r3 == 0) goto L64
            r3.close()     // Catch: java.io.IOException -> L64
        L64:
            throw r9
        L65:
            java.lang.String r9 = "Reading app Locales : Locales record file not found: androidx.appcompat.app.AppCompatDelegate.application_locales_record_file"
            android.util.Log.w(r1, r9)
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.a.h(android.content.Context):java.lang.String");
    }

    public static boolean i(d.a aVar, d.a aVar2, d.a aVar3, d.a aVar4) {
        d.a aVar5;
        d.a aVar6;
        d.a aVar7 = d.a.FIXED;
        return (aVar3 == aVar7 || aVar3 == (aVar6 = d.a.WRAP_CONTENT) || (aVar3 == d.a.MATCH_PARENT && aVar != aVar6)) || (aVar4 == aVar7 || aVar4 == (aVar5 = d.a.WRAP_CONTENT) || (aVar4 == d.a.MATCH_PARENT && aVar2 != aVar5));
    }
}
