package p022h;

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.graphics.PorterDuff;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
import android.view.InflateException;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import androidx.appcompat.view.menu.C0107g;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import p005b0.InterfaceMenuC0468a;
import p007c.C0494j;
import p023h0.AbstractC0775b;
import p023h0.C0937r0;
import p025i.MenuItemC1006c;
import p028j.C1106g3;
import p028j.C1115i2;

/* renamed from: h.g */
/* loaded from: classes.dex */
public class C0751g extends MenuInflater {

    /* renamed from: e */
    public static final Class<?>[] f2351e;

    /* renamed from: f */
    public static final Class<?>[] f2352f;

    /* renamed from: a */
    public final Object[] f2353a;

    /* renamed from: b */
    public final Object[] f2354b;

    /* renamed from: c */
    public Context f2355c;

    /* renamed from: d */
    public Object f2356d;

    /* renamed from: h.g$a */
    /* loaded from: classes.dex */
    public static class MenuItem$OnMenuItemClickListenerC0752a implements MenuItem.OnMenuItemClickListener {

        /* renamed from: c */
        public static final Class<?>[] f2357c = {MenuItem.class};

        /* renamed from: a */
        public Object f2358a;

        /* renamed from: b */
        public Method f2359b;

        public MenuItem$OnMenuItemClickListenerC0752a(Object obj, String str) {
            this.f2358a = obj;
            Class<?> cls = obj.getClass();
            try {
                this.f2359b = cls.getMethod(str, f2357c);
            } catch (Exception e) {
                InflateException inflateException = new InflateException("Couldn't resolve menu item onClick handler " + str + " in class " + cls.getName());
                inflateException.initCause(e);
                throw inflateException;
            }
        }

        @Override // android.view.MenuItem.OnMenuItemClickListener
        public boolean onMenuItemClick(MenuItem menuItem) {
            try {
                if (this.f2359b.getReturnType() == Boolean.TYPE) {
                    return ((Boolean) this.f2359b.invoke(this.f2358a, menuItem)).booleanValue();
                }
                this.f2359b.invoke(this.f2358a, menuItem);
                return true;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    /* renamed from: h.g$b */
    /* loaded from: classes.dex */
    public class C0753b {

        /* renamed from: A */
        public AbstractC0775b f2360A;

        /* renamed from: B */
        public CharSequence f2361B;

        /* renamed from: C */
        public CharSequence f2362C;

        /* renamed from: D */
        public ColorStateList f2363D = null;

        /* renamed from: E */
        public PorterDuff.Mode f2364E = null;

        /* renamed from: a */
        public Menu f2366a;

        /* renamed from: b */
        public int f2367b;

        /* renamed from: c */
        public int f2368c;

        /* renamed from: d */
        public int f2369d;

        /* renamed from: e */
        public int f2370e;

        /* renamed from: f */
        public boolean f2371f;

        /* renamed from: g */
        public boolean f2372g;

        /* renamed from: h */
        public boolean f2373h;

        /* renamed from: i */
        public int f2374i;

        /* renamed from: j */
        public int f2375j;

        /* renamed from: k */
        public CharSequence f2376k;

        /* renamed from: l */
        public CharSequence f2377l;

        /* renamed from: m */
        public int f2378m;

        /* renamed from: n */
        public char f2379n;

        /* renamed from: o */
        public int f2380o;

        /* renamed from: p */
        public char f2381p;

        /* renamed from: q */
        public int f2382q;

        /* renamed from: r */
        public int f2383r;

        /* renamed from: s */
        public boolean f2384s;

        /* renamed from: t */
        public boolean f2385t;

        /* renamed from: u */
        public boolean f2386u;

        /* renamed from: v */
        public int f2387v;

        /* renamed from: w */
        public int f2388w;

        /* renamed from: x */
        public String f2389x;

        /* renamed from: y */
        public String f2390y;

        /* renamed from: z */
        public String f2391z;

        public C0753b(Menu menu) {
            this.f2366a = menu;
            m2977h();
        }

        /* renamed from: a */
        public void m2984a() {
            this.f2373h = true;
            m2976i(this.f2366a.add(this.f2367b, this.f2374i, this.f2375j, this.f2376k));
        }

        /* renamed from: b */
        public SubMenu m2983b() {
            this.f2373h = true;
            SubMenu addSubMenu = this.f2366a.addSubMenu(this.f2367b, this.f2374i, this.f2375j, this.f2376k);
            m2976i(addSubMenu.getItem());
            return addSubMenu;
        }

        /* renamed from: c */
        public final char m2982c(String str) {
            if (str == null) {
                return (char) 0;
            }
            return str.charAt(0);
        }

        /* renamed from: d */
        public boolean m2981d() {
            return this.f2373h;
        }

        /* renamed from: e */
        public final <T> T m2980e(String str, Class<?>[] clsArr, Object[] objArr) {
            try {
                Constructor<?> constructor = Class.forName(str, false, C0751g.this.f2355c.getClassLoader()).getConstructor(clsArr);
                constructor.setAccessible(true);
                return (T) constructor.newInstance(objArr);
            } catch (Exception e) {
                Log.w("SupportMenuInflater", "Cannot instantiate class: " + str, e);
                return null;
            }
        }

        /* renamed from: f */
        public void m2979f(AttributeSet attributeSet) {
            TypedArray obtainStyledAttributes = C0751g.this.f2355c.obtainStyledAttributes(attributeSet, C0494j.f1873o1);
            this.f2367b = obtainStyledAttributes.getResourceId(C0494j.f1883q1, 0);
            this.f2368c = obtainStyledAttributes.getInt(C0494j.f1893s1, 0);
            this.f2369d = obtainStyledAttributes.getInt(C0494j.f1898t1, 0);
            this.f2370e = obtainStyledAttributes.getInt(C0494j.f1903u1, 0);
            this.f2371f = obtainStyledAttributes.getBoolean(C0494j.f1888r1, true);
            this.f2372g = obtainStyledAttributes.getBoolean(C0494j.f1878p1, true);
            obtainStyledAttributes.recycle();
        }

        /* JADX WARN: Multi-variable type inference failed */
        /* renamed from: g */
        public void m2978g(AttributeSet attributeSet) {
            C1106g3 m2161t = C1106g3.m2161t(C0751g.this.f2355c, attributeSet, C0494j.f1908v1);
            this.f2374i = m2161t.m2168m(C0494j.f1923y1, 0);
            this.f2375j = (m2161t.m2171j(C0494j.f1698B1, this.f2368c) & (-65536)) | (m2161t.m2171j(C0494j.f1703C1, this.f2369d) & 65535);
            this.f2376k = m2161t.m2166o(C0494j.f1708D1);
            this.f2377l = m2161t.m2166o(C0494j.f1713E1);
            this.f2378m = m2161t.m2168m(C0494j.f1913w1, 0);
            this.f2379n = m2982c(m2161t.m2167n(C0494j.f1718F1));
            this.f2380o = m2161t.m2171j(C0494j.f1747M1, 4096);
            this.f2381p = m2982c(m2161t.m2167n(C0494j.f1723G1));
            this.f2382q = m2161t.m2171j(C0494j.f1763Q1, 4096);
            int i = C0494j.f1727H1;
            this.f2383r = m2161t.m2163r(i) ? m2161t.m2180a(i, false) : this.f2370e;
            this.f2384s = m2161t.m2180a(C0494j.f1928z1, false);
            this.f2385t = m2161t.m2180a(C0494j.f1693A1, this.f2371f);
            this.f2386u = m2161t.m2180a(C0494j.f1918x1, this.f2372g);
            this.f2387v = m2161t.m2171j(C0494j.f1767R1, -1);
            this.f2391z = m2161t.m2167n(C0494j.f1731I1);
            this.f2388w = m2161t.m2168m(C0494j.f1735J1, 0);
            this.f2389x = m2161t.m2167n(C0494j.f1743L1);
            String m2167n = m2161t.m2167n(C0494j.f1739K1);
            this.f2390y = m2167n;
            boolean z = m2167n != null;
            if (z && this.f2388w == 0 && this.f2389x == null) {
                this.f2360A = (AbstractC0775b) m2980e(m2167n, C0751g.f2352f, C0751g.this.f2354b);
            } else {
                if (z) {
                    Log.w("SupportMenuInflater", "Ignoring attribute 'actionProviderClass'. Action view already specified.");
                }
                this.f2360A = null;
            }
            this.f2361B = m2161t.m2166o(C0494j.f1751N1);
            this.f2362C = m2161t.m2166o(C0494j.f1771S1);
            int i2 = C0494j.f1759P1;
            if (m2161t.m2163r(i2)) {
                this.f2364E = C1115i2.m2115d(m2161t.m2171j(i2, -1), this.f2364E);
            } else {
                this.f2364E = null;
            }
            int i3 = C0494j.f1755O1;
            if (m2161t.m2163r(i3)) {
                this.f2363D = m2161t.m2178c(i3);
            } else {
                this.f2363D = null;
            }
            m2161t.m2159v();
            this.f2373h = false;
        }

        /* renamed from: h */
        public void m2977h() {
            this.f2367b = 0;
            this.f2368c = 0;
            this.f2369d = 0;
            this.f2370e = 0;
            this.f2371f = true;
            this.f2372g = true;
        }

        /* renamed from: i */
        public final void m2976i(MenuItem menuItem) {
            boolean z = false;
            menuItem.setChecked(this.f2384s).setVisible(this.f2385t).setEnabled(this.f2386u).setCheckable(this.f2383r >= 1).setTitleCondensed(this.f2377l).setIcon(this.f2378m);
            int i = this.f2387v;
            if (i >= 0) {
                menuItem.setShowAsAction(i);
            }
            if (this.f2391z != null) {
                if (C0751g.this.f2355c.isRestricted()) {
                    throw new IllegalStateException("The android:onClick attribute cannot be used within a restricted context");
                }
                menuItem.setOnMenuItemClickListener(new MenuItem$OnMenuItemClickListenerC0752a(C0751g.this.m2986b(), this.f2391z));
            }
            if (this.f2383r >= 2) {
                if (menuItem instanceof C0107g) {
                    ((C0107g) menuItem).m4844t(true);
                } else if (menuItem instanceof MenuItemC1006c) {
                    ((MenuItemC1006c) menuItem).m2409h(true);
                }
            }
            String str = this.f2389x;
            if (str != null) {
                menuItem.setActionView((View) m2980e(str, C0751g.f2351e, C0751g.this.f2353a));
                z = true;
            }
            int i2 = this.f2388w;
            if (i2 > 0) {
                if (z) {
                    Log.w("SupportMenuInflater", "Ignoring attribute 'itemActionViewLayout'. Action view already specified.");
                } else {
                    menuItem.setActionView(i2);
                }
            }
            AbstractC0775b abstractC0775b = this.f2360A;
            if (abstractC0775b != null) {
                C0937r0.m2527a(menuItem, abstractC0775b);
            }
            C0937r0.m2525c(menuItem, this.f2361B);
            C0937r0.m2521g(menuItem, this.f2362C);
            C0937r0.m2526b(menuItem, this.f2379n, this.f2380o);
            C0937r0.m2522f(menuItem, this.f2381p, this.f2382q);
            PorterDuff.Mode mode = this.f2364E;
            if (mode != null) {
                C0937r0.m2523e(menuItem, mode);
            }
            ColorStateList colorStateList = this.f2363D;
            if (colorStateList != null) {
                C0937r0.m2524d(menuItem, colorStateList);
            }
        }
    }

    static {
        Class<?>[] clsArr = {Context.class};
        f2351e = clsArr;
        f2352f = clsArr;
    }

    public C0751g(Context context) {
        super(context);
        this.f2355c = context;
        Object[] objArr = {context};
        this.f2353a = objArr;
        this.f2354b = objArr;
    }

    /* renamed from: a */
    public final Object m2987a(Object obj) {
        return (!(obj instanceof Activity) && (obj instanceof ContextWrapper)) ? m2987a(((ContextWrapper) obj).getBaseContext()) : obj;
    }

    /* renamed from: b */
    public Object m2986b() {
        if (this.f2356d == null) {
            this.f2356d = m2987a(this.f2355c);
        }
        return this.f2356d;
    }

    /* JADX WARN: Code restructure failed: missing block: B:12:0x003b, code lost:
        r8 = null;
        r6 = false;
        r7 = false;
     */
    /* JADX WARN: Code restructure failed: missing block: B:13:0x0040, code lost:
        if (r6 != false) goto L64;
     */
    /* JADX WARN: Code restructure failed: missing block: B:14:0x0042, code lost:
        if (r15 == 1) goto L60;
     */
    /* JADX WARN: Code restructure failed: missing block: B:16:0x0048, code lost:
        if (r15 == 2) goto L44;
     */
    /* JADX WARN: Code restructure failed: missing block: B:18:0x004b, code lost:
        if (r15 == 3) goto L14;
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x004f, code lost:
        r15 = r13.getName();
     */
    /* JADX WARN: Code restructure failed: missing block: B:21:0x0053, code lost:
        if (r7 == false) goto L21;
     */
    /* JADX WARN: Code restructure failed: missing block: B:23:0x0059, code lost:
        if (r15.equals(r8) == false) goto L21;
     */
    /* JADX WARN: Code restructure failed: missing block: B:24:0x005b, code lost:
        r8 = null;
        r7 = false;
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x0062, code lost:
        if (r15.equals("group") == false) goto L25;
     */
    /* JADX WARN: Code restructure failed: missing block: B:27:0x0064, code lost:
        r0.m2977h();
     */
    /* JADX WARN: Code restructure failed: missing block: B:29:0x006c, code lost:
        if (r15.equals("item") == false) goto L38;
     */
    /* JADX WARN: Code restructure failed: missing block: B:31:0x0072, code lost:
        if (r0.m2981d() != false) goto L37;
     */
    /* JADX WARN: Code restructure failed: missing block: B:32:0x0074, code lost:
        r15 = r0.f2360A;
     */
    /* JADX WARN: Code restructure failed: missing block: B:33:0x0076, code lost:
        if (r15 == null) goto L35;
     */
    /* JADX WARN: Code restructure failed: missing block: B:35:0x007c, code lost:
        if (r15.mo2408a() == false) goto L35;
     */
    /* JADX WARN: Code restructure failed: missing block: B:36:0x007e, code lost:
        r0.m2983b();
     */
    /* JADX WARN: Code restructure failed: missing block: B:37:0x0082, code lost:
        r0.m2984a();
     */
    /* JADX WARN: Code restructure failed: missing block: B:39:0x008a, code lost:
        if (r15.equals("menu") == false) goto L42;
     */
    /* JADX WARN: Code restructure failed: missing block: B:40:0x008c, code lost:
        r6 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:41:0x008e, code lost:
        if (r7 == false) goto L45;
     */
    /* JADX WARN: Code restructure failed: missing block: B:43:0x0091, code lost:
        r15 = r13.getName();
     */
    /* JADX WARN: Code restructure failed: missing block: B:44:0x0099, code lost:
        if (r15.equals("group") == false) goto L49;
     */
    /* JADX WARN: Code restructure failed: missing block: B:45:0x009b, code lost:
        r0.m2979f(r14);
     */
    /* JADX WARN: Code restructure failed: missing block: B:47:0x00a3, code lost:
        if (r15.equals("item") == false) goto L53;
     */
    /* JADX WARN: Code restructure failed: missing block: B:48:0x00a5, code lost:
        r0.m2978g(r14);
     */
    /* JADX WARN: Code restructure failed: missing block: B:50:0x00ad, code lost:
        if (r15.equals("menu") == false) goto L57;
     */
    /* JADX WARN: Code restructure failed: missing block: B:51:0x00af, code lost:
        m2985c(r13, r14, r0.m2983b());
     */
    /* JADX WARN: Code restructure failed: missing block: B:52:0x00b7, code lost:
        r8 = r15;
        r7 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:53:0x00b9, code lost:
        r15 = r13.next();
     */
    /* JADX WARN: Code restructure failed: missing block: B:55:0x00c5, code lost:
        throw new java.lang.RuntimeException("Unexpected end of document");
     */
    /* JADX WARN: Code restructure failed: missing block: B:56:0x00c6, code lost:
        return;
     */
    /* renamed from: c */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m2985c(XmlPullParser xmlPullParser, AttributeSet attributeSet, Menu menu) {
        C0753b c0753b = new C0753b(menu);
        int eventType = xmlPullParser.getEventType();
        while (true) {
            if (eventType != 2) {
                eventType = xmlPullParser.next();
                if (eventType == 1) {
                    break;
                }
            } else {
                String name = xmlPullParser.getName();
                if (!name.equals("menu")) {
                    throw new RuntimeException("Expecting menu, got " + name);
                }
                eventType = xmlPullParser.next();
            }
        }
    }

    @Override // android.view.MenuInflater
    public void inflate(int i, Menu menu) {
        if (!(menu instanceof InterfaceMenuC0468a)) {
            super.inflate(i, menu);
            return;
        }
        XmlResourceParser xmlResourceParser = null;
        try {
            try {
                try {
                    xmlResourceParser = this.f2355c.getResources().getLayout(i);
                    m2985c(xmlResourceParser, Xml.asAttributeSet(xmlResourceParser), menu);
                } catch (IOException e) {
                    throw new InflateException("Error inflating menu XML", e);
                }
            } catch (XmlPullParserException e2) {
                throw new InflateException("Error inflating menu XML", e2);
            }
        } finally {
            if (xmlResourceParser != null) {
                xmlResourceParser.close();
            }
        }
    }
}