package o;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.ColorStateList;
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 org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Db0 extends MenuInflater {
    public static final Class[] e;
    public static final Class[] f;
    public final Object[] a;
    public final Object[] b;
    public final Context c;
    public Object d;

    static {
        Class[] clsArr = {Context.class};
        e = clsArr;
        f = clsArr;
    }

    public Db0(Context context) {
        super(context);
        this.c = context;
        Object[] objArr = {context};
        this.a = objArr;
        this.b = objArr;
    }

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

    public final void b(XmlPullParser xmlPullParser, AttributeSet attributeSet, Menu menu) throws XmlPullParserException, IOException {
        int i;
        XmlPullParser xmlPullParser2;
        ColorStateList colorStateList;
        int resourceId;
        Cb0 cb0 = new Cb0(this, menu);
        int eventType = xmlPullParser.getEventType();
        while (true) {
            i = 2;
            if (eventType == 2) {
                String name = xmlPullParser.getName();
                if (!name.equals("menu")) {
                    throw new RuntimeException("Expecting menu, got ".concat(name));
                }
                eventType = xmlPullParser.next();
            } else {
                eventType = xmlPullParser.next();
                if (eventType == 1) {
                    break;
                }
            }
        }
        boolean z = false;
        boolean z2 = false;
        String str = null;
        while (!z) {
            if (eventType == 1) {
                throw new RuntimeException("Unexpected end of document");
            }
            if (eventType != i) {
                if (eventType != 3) {
                    xmlPullParser2 = xmlPullParser;
                    z = z;
                } else {
                    String name2 = xmlPullParser.getName();
                    if (z2 && name2.equals(str)) {
                        xmlPullParser2 = xmlPullParser;
                        z2 = false;
                        str = null;
                    } else {
                        if (name2.equals("group")) {
                            cb0.b = 0;
                            cb0.c = 0;
                            cb0.d = 0;
                            cb0.e = 0;
                            cb0.f = true;
                            cb0.g = true;
                        } else if (name2.equals("item")) {
                            if (!cb0.h) {
                                MO mo = cb0.z;
                                if (mo == null || !mo.b.hasSubMenu()) {
                                    cb0.h = true;
                                    cb0.b(cb0.a.add(cb0.b, cb0.i, cb0.j, cb0.k));
                                } else {
                                    cb0.h = true;
                                    cb0.b(cb0.a.addSubMenu(cb0.b, cb0.i, cb0.j, cb0.k).getItem());
                                }
                            }
                        } else if (name2.equals("menu")) {
                            xmlPullParser2 = xmlPullParser;
                            z = true;
                        }
                        xmlPullParser2 = xmlPullParser;
                        z = z;
                    }
                }
                eventType = xmlPullParser2.next();
                i = 2;
                z = z;
                z2 = z2;
            } else {
                if (!z2) {
                    String name3 = xmlPullParser.getName();
                    boolean zEquals = name3.equals("group");
                    Context context = this.c;
                    if (zEquals) {
                        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, YZ.p);
                        cb0.b = typedArrayObtainStyledAttributes.getResourceId(1, 0);
                        cb0.c = typedArrayObtainStyledAttributes.getInt(3, 0);
                        cb0.d = typedArrayObtainStyledAttributes.getInt(4, 0);
                        cb0.e = typedArrayObtainStyledAttributes.getInt(5, 0);
                        cb0.f = typedArrayObtainStyledAttributes.getBoolean(2, true);
                        cb0.g = typedArrayObtainStyledAttributes.getBoolean(0, true);
                        typedArrayObtainStyledAttributes.recycle();
                    } else {
                        if (name3.equals("item")) {
                            TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(attributeSet, YZ.q);
                            cb0.i = typedArrayObtainStyledAttributes2.getResourceId(2, 0);
                            cb0.j = (typedArrayObtainStyledAttributes2.getInt(5, cb0.c) & (-65536)) | (typedArrayObtainStyledAttributes2.getInt(6, cb0.d) & 65535);
                            cb0.k = typedArrayObtainStyledAttributes2.getText(7);
                            cb0.l = typedArrayObtainStyledAttributes2.getText(8);
                            cb0.m = typedArrayObtainStyledAttributes2.getResourceId(0, 0);
                            String string = typedArrayObtainStyledAttributes2.getString(9);
                            cb0.n = string == null ? (char) 0 : string.charAt(0);
                            cb0.f69o = typedArrayObtainStyledAttributes2.getInt(16, 4096);
                            String string2 = typedArrayObtainStyledAttributes2.getString(10);
                            cb0.p = string2 == null ? (char) 0 : string2.charAt(0);
                            cb0.q = typedArrayObtainStyledAttributes2.getInt(20, 4096);
                            if (typedArrayObtainStyledAttributes2.hasValue(11)) {
                                cb0.r = typedArrayObtainStyledAttributes2.getBoolean(11, false) ? 1 : 0;
                            } else {
                                cb0.r = cb0.e;
                            }
                            cb0.s = typedArrayObtainStyledAttributes2.getBoolean(3, false);
                            cb0.t = typedArrayObtainStyledAttributes2.getBoolean(4, cb0.f);
                            cb0.u = typedArrayObtainStyledAttributes2.getBoolean(1, cb0.g);
                            cb0.v = typedArrayObtainStyledAttributes2.getInt(21, -1);
                            cb0.y = typedArrayObtainStyledAttributes2.getString(12);
                            cb0.w = typedArrayObtainStyledAttributes2.getResourceId(13, 0);
                            cb0.x = typedArrayObtainStyledAttributes2.getString(15);
                            String string3 = typedArrayObtainStyledAttributes2.getString(14);
                            if (string3 != null && cb0.w == 0 && cb0.x == null) {
                                cb0.z = (MO) cb0.a(string3, f, this.b);
                            } else {
                                cb0.z = null;
                            }
                            cb0.A = typedArrayObtainStyledAttributes2.getText(17);
                            cb0.B = typedArrayObtainStyledAttributes2.getText(22);
                            if (typedArrayObtainStyledAttributes2.hasValue(19)) {
                                cb0.D = AbstractC2949xt.b(typedArrayObtainStyledAttributes2.getInt(19, -1), cb0.D);
                            } else {
                                cb0.D = null;
                            }
                            if (typedArrayObtainStyledAttributes2.hasValue(18)) {
                                if (!typedArrayObtainStyledAttributes2.hasValue(18) || (resourceId = typedArrayObtainStyledAttributes2.getResourceId(18, 0)) == 0 || (colorStateList = Co0.z(context, resourceId)) == null) {
                                    colorStateList = typedArrayObtainStyledAttributes2.getColorStateList(18);
                                }
                                cb0.C = colorStateList;
                            } else {
                                cb0.C = null;
                            }
                            typedArrayObtainStyledAttributes2.recycle();
                            cb0.h = false;
                            xmlPullParser2 = xmlPullParser;
                        } else if (name3.equals("menu")) {
                            cb0.h = true;
                            SubMenu subMenuAddSubMenu = cb0.a.addSubMenu(cb0.b, cb0.i, cb0.j, cb0.k);
                            cb0.b(subMenuAddSubMenu.getItem());
                            xmlPullParser2 = xmlPullParser;
                            b(xmlPullParser2, attributeSet, subMenuAddSubMenu);
                        } else {
                            xmlPullParser2 = xmlPullParser;
                            str = name3;
                            z2 = true;
                        }
                        eventType = xmlPullParser2.next();
                        i = 2;
                        z = z;
                        z2 = z2;
                    }
                }
                xmlPullParser2 = xmlPullParser;
                z = z;
            }
            eventType = xmlPullParser2.next();
            i = 2;
            z = z;
            z2 = z2;
        }
    }

    @Override // android.view.MenuInflater
    public final void inflate(int i, Menu menu) {
        if (!(menu instanceof CO)) {
            super.inflate(i, menu);
            return;
        }
        XmlResourceParser layout = null;
        boolean z = false;
        try {
            try {
                layout = this.c.getResources().getLayout(i);
                AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(layout);
                if (menu instanceof CO) {
                    CO co = (CO) menu;
                    if (!co.p) {
                        co.w();
                        z = true;
                    }
                }
                b(layout, attributeSetAsAttributeSet, menu);
                if (z) {
                    ((CO) menu).v();
                }
                layout.close();
            } catch (IOException e2) {
                throw new InflateException("Error inflating menu XML", e2);
            } catch (XmlPullParserException e3) {
                throw new InflateException("Error inflating menu XML", e3);
            }
        } catch (Throwable th) {
            if (z) {
                ((CO) menu).v();
            }
            if (layout != null) {
                layout.close();
            }
            throw th;
        }
    }
}
