package j;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
import android.util.Xml;
import android.view.InflateException;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.SubMenu;
import java.io.IOException;
import k.s;
import l.p1;
import l.p3;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: loaded from: classes.dex */
public final class k extends MenuInflater {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final Class[] f28483e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final Class[] f28484f;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object[] f28485a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object[] f28486b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Context f28487c;

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

    static {
        Class[] clsArr = {Context.class};
        f28483e = clsArr;
        f28484f = clsArr;
    }

    public k(Context context) {
        super(context);
        this.f28487c = context;
        Object[] objArr = {context};
        this.f28485a = objArr;
        this.f28486b = objArr;
    }

    public static Object a(Context context) {
        return (!(context instanceof Activity) && (context instanceof ContextWrapper)) ? a(((ContextWrapper) context).getBaseContext()) : context;
    }

    /* JADX WARN: Removed duplicated region for block: B:19:0x0048  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void b(XmlResourceParser xmlResourceParser, AttributeSet attributeSet, Menu menu) throws XmlPullParserException, IOException {
        int i10;
        j jVar = new j(this, menu);
        int eventType = xmlResourceParser.getEventType();
        while (true) {
            i10 = 2;
            if (eventType == 2) {
                String name = xmlResourceParser.getName();
                if (!name.equals("menu")) {
                    throw new RuntimeException("Expecting menu, got ".concat(name));
                }
                eventType = xmlResourceParser.next();
            } else {
                eventType = xmlResourceParser.next();
                if (eventType == 1) {
                    break;
                }
            }
        }
        boolean z10 = false;
        boolean z11 = false;
        String str = null;
        while (!z10) {
            if (eventType == 1) {
                throw new RuntimeException("Unexpected end of document");
            }
            if (eventType != i10) {
                if (eventType == 3) {
                    String name2 = xmlResourceParser.getName();
                    if (z11 && name2.equals(str)) {
                        z11 = false;
                        str = null;
                    } else if (name2.equals("group")) {
                        jVar.f28458b = 0;
                        jVar.f28459c = 0;
                        jVar.f28460d = 0;
                        jVar.f28461e = 0;
                        jVar.f28462f = true;
                        jVar.f28463g = true;
                    } else if (name2.equals("item")) {
                        if (!jVar.f28464h) {
                            androidx.core.view.e eVar = jVar.f28482z;
                            if (eVar == null || !((s) eVar).f28935d.hasSubMenu()) {
                                jVar.f28464h = true;
                                jVar.b(jVar.f28457a.add(jVar.f28458b, jVar.f28465i, jVar.f28466j, jVar.f28467k));
                            } else {
                                jVar.f28464h = true;
                                jVar.b(jVar.f28457a.addSubMenu(jVar.f28458b, jVar.f28465i, jVar.f28466j, jVar.f28467k).getItem());
                            }
                        }
                    } else if (name2.equals("menu")) {
                        z10 = true;
                    }
                }
            } else if (!z11) {
                String name3 = xmlResourceParser.getName();
                boolean zEquals = name3.equals("group");
                k kVar = jVar.E;
                if (zEquals) {
                    TypedArray typedArrayObtainStyledAttributes = kVar.f28487c.obtainStyledAttributes(attributeSet, d.j.MenuGroup);
                    jVar.f28458b = typedArrayObtainStyledAttributes.getResourceId(d.j.MenuGroup_android_id, 0);
                    jVar.f28459c = typedArrayObtainStyledAttributes.getInt(d.j.MenuGroup_android_menuCategory, 0);
                    jVar.f28460d = typedArrayObtainStyledAttributes.getInt(d.j.MenuGroup_android_orderInCategory, 0);
                    jVar.f28461e = typedArrayObtainStyledAttributes.getInt(d.j.MenuGroup_android_checkableBehavior, 0);
                    jVar.f28462f = typedArrayObtainStyledAttributes.getBoolean(d.j.MenuGroup_android_visible, true);
                    jVar.f28463g = typedArrayObtainStyledAttributes.getBoolean(d.j.MenuGroup_android_enabled, true);
                    typedArrayObtainStyledAttributes.recycle();
                } else if (name3.equals("item")) {
                    Context context = kVar.f28487c;
                    TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(attributeSet, d.j.MenuItem);
                    p3 p3Var = new p3(context, typedArrayObtainStyledAttributes2);
                    jVar.f28465i = typedArrayObtainStyledAttributes2.getResourceId(d.j.MenuItem_android_id, 0);
                    jVar.f28466j = (typedArrayObtainStyledAttributes2.getInt(d.j.MenuItem_android_menuCategory, jVar.f28459c) & (-65536)) | (typedArrayObtainStyledAttributes2.getInt(d.j.MenuItem_android_orderInCategory, jVar.f28460d) & 65535);
                    jVar.f28467k = typedArrayObtainStyledAttributes2.getText(d.j.MenuItem_android_title);
                    jVar.f28468l = typedArrayObtainStyledAttributes2.getText(d.j.MenuItem_android_titleCondensed);
                    jVar.f28469m = typedArrayObtainStyledAttributes2.getResourceId(d.j.MenuItem_android_icon, 0);
                    String string = typedArrayObtainStyledAttributes2.getString(d.j.MenuItem_android_alphabeticShortcut);
                    jVar.f28470n = string == null ? (char) 0 : string.charAt(0);
                    jVar.f28471o = typedArrayObtainStyledAttributes2.getInt(d.j.MenuItem_alphabeticModifiers, 4096);
                    String string2 = typedArrayObtainStyledAttributes2.getString(d.j.MenuItem_android_numericShortcut);
                    jVar.f28472p = string2 == null ? (char) 0 : string2.charAt(0);
                    jVar.f28473q = typedArrayObtainStyledAttributes2.getInt(d.j.MenuItem_numericModifiers, 4096);
                    int i11 = d.j.MenuItem_android_checkable;
                    if (typedArrayObtainStyledAttributes2.hasValue(i11)) {
                        jVar.f28474r = typedArrayObtainStyledAttributes2.getBoolean(i11, false) ? 1 : 0;
                    } else {
                        jVar.f28474r = jVar.f28461e;
                    }
                    jVar.f28475s = typedArrayObtainStyledAttributes2.getBoolean(d.j.MenuItem_android_checked, false);
                    jVar.f28476t = typedArrayObtainStyledAttributes2.getBoolean(d.j.MenuItem_android_visible, jVar.f28462f);
                    jVar.f28477u = typedArrayObtainStyledAttributes2.getBoolean(d.j.MenuItem_android_enabled, jVar.f28463g);
                    jVar.f28478v = typedArrayObtainStyledAttributes2.getInt(d.j.MenuItem_showAsAction, -1);
                    jVar.f28481y = typedArrayObtainStyledAttributes2.getString(d.j.MenuItem_android_onClick);
                    jVar.f28479w = typedArrayObtainStyledAttributes2.getResourceId(d.j.MenuItem_actionLayout, 0);
                    jVar.f28480x = typedArrayObtainStyledAttributes2.getString(d.j.MenuItem_actionViewClass);
                    String string3 = typedArrayObtainStyledAttributes2.getString(d.j.MenuItem_actionProviderClass);
                    if (string3 != null && jVar.f28479w == 0 && jVar.f28480x == null) {
                        jVar.f28482z = (androidx.core.view.e) jVar.a(string3, f28484f, kVar.f28486b);
                    } else {
                        jVar.f28482z = null;
                    }
                    jVar.A = typedArrayObtainStyledAttributes2.getText(d.j.MenuItem_contentDescription);
                    jVar.B = typedArrayObtainStyledAttributes2.getText(d.j.MenuItem_tooltipText);
                    int i12 = d.j.MenuItem_iconTintMode;
                    if (typedArrayObtainStyledAttributes2.hasValue(i12)) {
                        jVar.D = p1.c(typedArrayObtainStyledAttributes2.getInt(i12, -1), jVar.D);
                    } else {
                        jVar.D = null;
                    }
                    int i13 = d.j.MenuItem_iconTint;
                    if (typedArrayObtainStyledAttributes2.hasValue(i13)) {
                        jVar.C = p3Var.a(i13);
                    } else {
                        jVar.C = null;
                    }
                    p3Var.e();
                    jVar.f28464h = false;
                } else if (name3.equals("menu")) {
                    jVar.f28464h = true;
                    SubMenu subMenuAddSubMenu = jVar.f28457a.addSubMenu(jVar.f28458b, jVar.f28465i, jVar.f28466j, jVar.f28467k);
                    jVar.b(subMenuAddSubMenu.getItem());
                    b(xmlResourceParser, attributeSet, subMenuAddSubMenu);
                } else {
                    str = name3;
                    z11 = true;
                }
            }
            eventType = xmlResourceParser.next();
            i10 = 2;
            z10 = z10;
            z11 = z11;
        }
    }

    @Override // android.view.MenuInflater
    public final void inflate(int i10, Menu menu) {
        if (!(menu instanceof l0.a)) {
            super.inflate(i10, menu);
            return;
        }
        XmlResourceParser layout = null;
        boolean z10 = false;
        try {
            try {
                layout = this.f28487c.getResources().getLayout(i10);
                AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(layout);
                if (menu instanceof k.p) {
                    k.p pVar = (k.p) menu;
                    if (!pVar.f28895p) {
                        pVar.y();
                        z10 = true;
                    }
                }
                b(layout, attributeSetAsAttributeSet, menu);
                if (z10) {
                    ((k.p) menu).x();
                }
                layout.close();
            } catch (IOException e10) {
                throw new InflateException("Error inflating menu XML", e10);
            } catch (XmlPullParserException e11) {
                throw new InflateException("Error inflating menu XML", e11);
            }
        } catch (Throwable th) {
            if (z10) {
                ((k.p) menu).x();
            }
            if (layout != null) {
                layout.close();
            }
            throw th;
        }
    }
}
