package androidx.appcompat.view.menu; import android.content.Context; 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: a, reason: collision with root package name */ Context f589a; /* renamed from: b, reason: collision with root package name */ LayoutInflater f590b; /* renamed from: c, reason: collision with root package name */ e f591c; /* renamed from: d, reason: collision with root package name */ ExpandedMenuView f592d; /* renamed from: e, reason: collision with root package name */ int f593e; /* renamed from: f, reason: collision with root package name */ int f594f; /* renamed from: g, reason: collision with root package name */ int f595g; /* renamed from: h, reason: collision with root package name */ private j.a f596h; /* renamed from: i, reason: collision with root package name */ a f597i; private class a extends BaseAdapter { /* renamed from: a, reason: collision with root package name */ private int f598a = -1; public a() { a(); } void a() { g v10 = c.this.f591c.v(); if (v10 != null) { ArrayList z10 = c.this.f591c.z(); int size = z10.size(); for (int i10 = 0; i10 < size; i10++) { if (((g) z10.get(i10)) == v10) { this.f598a = i10; return; } } } this.f598a = -1; } @Override // android.widget.Adapter /* renamed from: b, reason: merged with bridge method [inline-methods] */ public g getItem(int i10) { ArrayList z10 = c.this.f591c.z(); int i11 = i10 + c.this.f593e; int i12 = this.f598a; if (i12 >= 0 && i11 >= i12) { i11++; } return (g) z10.get(i11); } @Override // android.widget.Adapter public int getCount() { int size = c.this.f591c.z().size() - c.this.f593e; return this.f598a < 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.f590b.inflate(cVar.f595g, 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.f589a = context; this.f590b = LayoutInflater.from(context); } public ListAdapter a() { if (this.f597i == null) { this.f597i = new a(); } return this.f597i; } @Override // androidx.appcompat.view.menu.j public void b(e eVar, boolean z10) { j.a aVar = this.f596h; if (aVar != null) { aVar.b(eVar, z10); } } @Override // androidx.appcompat.view.menu.j public void c(boolean z10) { a aVar = this.f597i; if (aVar != null) { aVar.notifyDataSetChanged(); } } @Override // androidx.appcompat.view.menu.j public boolean d() { return false; } @Override // androidx.appcompat.view.menu.j public boolean e(e eVar, g gVar) { return false; } @Override // androidx.appcompat.view.menu.j public boolean f(e eVar, g gVar) { return false; } @Override // androidx.appcompat.view.menu.j public void g(j.a aVar) { this.f596h = aVar; } public k h(ViewGroup viewGroup) { if (this.f592d == null) { this.f592d = (ExpandedMenuView) this.f590b.inflate(d.g.f8785g, viewGroup, false); if (this.f597i == null) { this.f597i = new a(); } this.f592d.setAdapter((ListAdapter) this.f597i); this.f592d.setOnItemClickListener(this); } return this.f592d; } @Override // androidx.appcompat.view.menu.j public void i(Context context, e eVar) { if (this.f594f != 0) { ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(context, this.f594f); this.f589a = contextThemeWrapper; this.f590b = LayoutInflater.from(contextThemeWrapper); } else if (this.f589a != null) { this.f589a = context; if (this.f590b == null) { this.f590b = LayoutInflater.from(context); } } this.f591c = eVar; a aVar = this.f597i; if (aVar != null) { aVar.notifyDataSetChanged(); } } @Override // androidx.appcompat.view.menu.j public boolean k(m mVar) { if (!mVar.hasVisibleItems()) { return false; } new f(mVar).d(null); j.a aVar = this.f596h; if (aVar == null) { return true; } aVar.c(mVar); return true; } @Override // android.widget.AdapterView.OnItemClickListener public void onItemClick(AdapterView adapterView, View view, int i10, long j10) { this.f591c.M(this.f597i.getItem(i10), this, 0); } public c(int i10, int i11) { this.f595g = i10; this.f594f = i11; } }