package androidx.appcompat.view.menu;

import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.SparseArray;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import androidx.appcompat.view.menu.j;
import androidx.appcompat.view.menu.k;
import java.util.ArrayList;

/* loaded from: classes.dex */
public class c implements j, AdapterView.OnItemClickListener {

    /* renamed from: p, reason: collision with root package name */
    Context f690p;

    /* renamed from: q, reason: collision with root package name */
    LayoutInflater f691q;

    /* renamed from: r, reason: collision with root package name */
    e f692r;

    /* renamed from: s, reason: collision with root package name */
    ExpandedMenuView f693s;

    /* renamed from: t, reason: collision with root package name */
    int f694t;

    /* renamed from: u, reason: collision with root package name */
    int f695u;

    /* renamed from: v, reason: collision with root package name */
    int f696v;

    /* renamed from: w, reason: collision with root package name */
    private j.a f697w;

    /* renamed from: x, reason: collision with root package name */
    a f698x;

    /* renamed from: y, reason: collision with root package name */
    private int f699y;

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public class a extends BaseAdapter {

        /* renamed from: p, reason: collision with root package name */
        private int f700p = -1;

        public a() {
            a();
        }

        void a() {
            g x10 = c.this.f692r.x();
            if (x10 != null) {
                ArrayList B = c.this.f692r.B();
                int size = B.size();
                for (int i10 = 0; i10 < size; i10++) {
                    if (((g) B.get(i10)) == x10) {
                        this.f700p = i10;
                        return;
                    }
                }
            }
            this.f700p = -1;
        }

        @Override // android.widget.Adapter
        /* renamed from: b, reason: merged with bridge method [inline-methods] */
        public g getItem(int i10) {
            ArrayList B = c.this.f692r.B();
            int i11 = i10 + c.this.f694t;
            int i12 = this.f700p;
            if (i12 >= 0 && i11 >= i12) {
                i11++;
            }
            return (g) B.get(i11);
        }

        @Override // android.widget.Adapter
        public int getCount() {
            int size = c.this.f692r.B().size() - c.this.f694t;
            return this.f700p < 0 ? size : size - 1;
        }

        @Override // android.widget.Adapter
        public long getItemId(int i10) {
            return i10;
        }

        @Override // android.widget.Adapter
        public View getView(int i10, View view, ViewGroup viewGroup) {
            if (view == null) {
                c cVar = c.this;
                view = cVar.f691q.inflate(cVar.f696v, viewGroup, false);
            }
            ((k.a) view).e(getItem(i10), 0);
            return view;
        }

        @Override // android.widget.BaseAdapter
        public void notifyDataSetChanged() {
            a();
            super.notifyDataSetChanged();
        }
    }

    public c(Context context, int i10) {
        this(i10, 0);
        this.f690p = context;
        this.f691q = LayoutInflater.from(context);
    }

    public ListAdapter a() {
        if (this.f698x == null) {
            this.f698x = new a();
        }
        return this.f698x;
    }

    @Override // androidx.appcompat.view.menu.j
    public void b(e eVar, boolean z10) {
        j.a aVar = this.f697w;
        if (aVar != null) {
            aVar.b(eVar, z10);
        }
    }

    public k c(ViewGroup viewGroup) {
        if (this.f693s == null) {
            this.f693s = (ExpandedMenuView) this.f691q.inflate(h.g.f20249g, viewGroup, false);
            if (this.f698x == null) {
                this.f698x = new a();
            }
            this.f693s.setAdapter((ListAdapter) this.f698x);
            this.f693s.setOnItemClickListener(this);
        }
        return this.f693s;
    }

    @Override // androidx.appcompat.view.menu.j
    public void d(boolean z10) {
        a aVar = this.f698x;
        if (aVar != null) {
            aVar.notifyDataSetChanged();
        }
    }

    @Override // androidx.appcompat.view.menu.j
    public boolean e() {
        return false;
    }

    @Override // androidx.appcompat.view.menu.j
    public boolean f(e eVar, g gVar) {
        return false;
    }

    @Override // androidx.appcompat.view.menu.j
    public boolean g(e eVar, g gVar) {
        return false;
    }

    @Override // androidx.appcompat.view.menu.j
    public int getId() {
        return this.f699y;
    }

    @Override // androidx.appcompat.view.menu.j
    public void h(j.a aVar) {
        this.f697w = aVar;
    }

    @Override // androidx.appcompat.view.menu.j
    public void i(Context context, e eVar) {
        if (this.f695u != 0) {
            ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(context, this.f695u);
            this.f690p = contextThemeWrapper;
            this.f691q = LayoutInflater.from(contextThemeWrapper);
        } else if (this.f690p != null) {
            this.f690p = context;
            if (this.f691q == null) {
                this.f691q = LayoutInflater.from(context);
            }
        }
        this.f692r = eVar;
        a aVar = this.f698x;
        if (aVar != null) {
            aVar.notifyDataSetChanged();
        }
    }

    @Override // androidx.appcompat.view.menu.j
    public void j(Parcelable parcelable) {
        k((Bundle) parcelable);
    }

    public void k(Bundle bundle) {
        SparseArray<Parcelable> sparseParcelableArray = bundle.getSparseParcelableArray("android:menu:list");
        if (sparseParcelableArray != null) {
            this.f693s.restoreHierarchyState(sparseParcelableArray);
        }
    }

    @Override // androidx.appcompat.view.menu.j
    public boolean l(m mVar) {
        if (!mVar.hasVisibleItems()) {
            return false;
        }
        new f(mVar).d(null);
        j.a aVar = this.f697w;
        if (aVar == null) {
            return true;
        }
        aVar.c(mVar);
        return true;
    }

    @Override // androidx.appcompat.view.menu.j
    public Parcelable m() {
        if (this.f693s == null) {
            return null;
        }
        Bundle bundle = new Bundle();
        n(bundle);
        return bundle;
    }

    public void n(Bundle bundle) {
        SparseArray<Parcelable> sparseArray = new SparseArray<>();
        ExpandedMenuView expandedMenuView = this.f693s;
        if (expandedMenuView != null) {
            expandedMenuView.saveHierarchyState(sparseArray);
        }
        bundle.putSparseParcelableArray("android:menu:list", sparseArray);
    }

    @Override // android.widget.AdapterView.OnItemClickListener
    public void onItemClick(AdapterView adapterView, View view, int i10, long j10) {
        this.f692r.O(this.f698x.getItem(i10), this, 0);
    }

    public c(int i10, int i11) {
        this.f696v = i10;
        this.f695u = i11;
    }
}
