package androidx.appcompat.view.menu;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import androidx.appcompat.view.menu.InterfaceC0114j;
import java.util.ArrayList;

/* renamed from: androidx.appcompat.view.menu.d */
/* loaded from: classes.dex */
public class C0102d extends BaseAdapter {

    /* renamed from: d */
    public C0103e f301d;

    /* renamed from: e */
    public int f302e = -1;

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

    /* renamed from: g */
    public final boolean f304g;

    /* renamed from: h */
    public final LayoutInflater f305h;

    /* renamed from: i */
    public final int f306i;

    public C0102d(C0103e c0103e, LayoutInflater layoutInflater, boolean z, int i) {
        this.f304g = z;
        this.f305h = layoutInflater;
        this.f301d = c0103e;
        this.f306i = i;
        m4916a();
    }

    /* renamed from: a */
    public void m4916a() {
        C0107g m4870v = this.f301d.m4870v();
        if (m4870v != null) {
            ArrayList<C0107g> m4866z = this.f301d.m4866z();
            int size = m4866z.size();
            for (int i = 0; i < size; i++) {
                if (m4866z.get(i) == m4870v) {
                    this.f302e = i;
                    return;
                }
            }
        }
        this.f302e = -1;
    }

    /* renamed from: b */
    public C0103e m4915b() {
        return this.f301d;
    }

    @Override // android.widget.Adapter
    /* renamed from: c */
    public C0107g getItem(int i) {
        ArrayList<C0107g> m4866z = this.f304g ? this.f301d.m4866z() : this.f301d.m4909E();
        int i2 = this.f302e;
        if (i2 >= 0 && i >= i2) {
            i++;
        }
        return m4866z.get(i);
    }

    /* renamed from: d */
    public void m4913d(boolean z) {
        this.f303f = z;
    }

    @Override // android.widget.Adapter
    public int getCount() {
        ArrayList<C0107g> m4866z = this.f304g ? this.f301d.m4866z() : this.f301d.m4909E();
        int i = this.f302e;
        int size = m4866z.size();
        return i < 0 ? size : size - 1;
    }

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

    @Override // android.widget.Adapter
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = this.f305h.inflate(this.f306i, viewGroup, false);
        }
        int groupId = getItem(i).getGroupId();
        int i2 = i - 1;
        ListMenuItemView listMenuItemView = (ListMenuItemView) view;
        listMenuItemView.setGroupDividerEnabled(this.f301d.mo4818F() && groupId != (i2 >= 0 ? getItem(i2).getGroupId() : groupId));
        InterfaceC0114j.InterfaceC0115a interfaceC0115a = (InterfaceC0114j.InterfaceC0115a) view;
        if (this.f303f) {
            listMenuItemView.setForceShowIcon(true);
        }
        interfaceC0115a.mo4822d(getItem(i), 0);
        return view;
    }

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