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.n;
import java.util.ArrayList;

/* JADX INFO: compiled from: MenuAdapter.java */
/* JADX INFO: loaded from: classes.dex */
public class f extends BaseAdapter {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    g f413c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private int f414d = -1;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private boolean f415e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final boolean f416f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final LayoutInflater f417g;
    private final int h;

    public f(g gVar, LayoutInflater layoutInflater, boolean z, int i) {
        this.f416f = z;
        this.f417g = layoutInflater;
        this.f413c = gVar;
        this.h = i;
        a();
    }

    void a() {
        h hVarT = this.f413c.t();
        if (hVarT != null) {
            ArrayList<h> arrayListV = this.f413c.v();
            int size = arrayListV.size();
            for (int i = 0; i < size; i++) {
                if (arrayListV.get(i) == hVarT) {
                    this.f414d = i;
                    return;
                }
            }
        }
        this.f414d = -1;
    }

    public g b() {
        return this.f413c;
    }

    @Override // android.widget.Adapter
    /* JADX INFO: renamed from: e, reason: merged with bridge method [inline-methods] */
    public h getItem(int i) {
        ArrayList<h> arrayListV = this.f416f ? this.f413c.v() : this.f413c.A();
        int i2 = this.f414d;
        if (i2 >= 0 && i >= i2) {
            i++;
        }
        return arrayListV.get(i);
    }

    public void f(boolean z) {
        this.f415e = z;
    }

    @Override // android.widget.Adapter
    public int getCount() {
        return this.f414d < 0 ? (this.f416f ? this.f413c.v() : this.f413c.A()).size() : r0.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.f417g.inflate(this.h, viewGroup, false);
        }
        int groupId = getItem(i).getGroupId();
        int i2 = i - 1;
        ListMenuItemView listMenuItemView = (ListMenuItemView) view;
        listMenuItemView.setGroupDividerEnabled(this.f413c.B() && groupId != (i2 >= 0 ? getItem(i2).getGroupId() : groupId));
        n.a aVar = (n.a) view;
        if (this.f415e) {
            listMenuItemView.setForceShowIcon(true);
        }
        aVar.d(getItem(i), 0);
        return view;
    }

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