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.o;
import androidx.appcompat.view.menu.p;
import java.util.ArrayList;

/* JADX INFO: compiled from: ListMenuPresenter.java */
/* JADX INFO: loaded from: classes.dex */
public class f implements o, AdapterView.OnItemClickListener {
    Context b;
    LayoutInflater d;
    h e;
    ExpandedMenuView f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    int f76h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    int f77i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private o.a f78j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    a f79k;

    /* JADX INFO: compiled from: ListMenuPresenter.java */
    private class a extends BaseAdapter {
        private int b = -1;

        public a() {
            a();
        }

        void a() {
            j jVarV = f.this.e.v();
            if (jVarV != null) {
                ArrayList<j> arrayListZ = f.this.e.z();
                int size = arrayListZ.size();
                for (int i2 = 0; i2 < size; i2++) {
                    if (arrayListZ.get(i2) == jVarV) {
                        this.b = i2;
                        return;
                    }
                }
            }
            this.b = -1;
        }

        @Override // android.widget.Adapter
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public j getItem(int i2) {
            ArrayList<j> arrayListZ = f.this.e.z();
            int i3 = i2 + f.this.f75g;
            int i4 = this.b;
            if (i4 >= 0 && i3 >= i4) {
                i3++;
            }
            return arrayListZ.get(i3);
        }

        @Override // android.widget.Adapter
        public int getCount() {
            int size = f.this.e.z().size() - f.this.f75g;
            return this.b < 0 ? size : size - 1;
        }

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

        @Override // android.widget.Adapter
        public View getView(int i2, View view, ViewGroup viewGroup) {
            if (view == null) {
                f fVar = f.this;
                view = fVar.d.inflate(fVar.f77i, viewGroup, false);
            }
            ((p.a) view).d(getItem(i2), 0);
            return view;
        }

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

    public f(Context context, int i2) {
        this(i2, 0);
        this.b = context;
        this.d = LayoutInflater.from(context);
    }

    @Override // androidx.appcompat.view.menu.o
    public void a(h hVar, boolean z) {
        o.a aVar = this.f78j;
        if (aVar != null) {
            aVar.a(hVar, z);
        }
    }

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

    @Override // androidx.appcompat.view.menu.o
    public void c(Context context, h hVar) {
        if (this.f76h != 0) {
            ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(context, this.f76h);
            this.b = contextThemeWrapper;
            this.d = LayoutInflater.from(contextThemeWrapper);
        } else if (this.b != null) {
            this.b = context;
            if (this.d == null) {
                this.d = LayoutInflater.from(context);
            }
        }
        this.e = hVar;
        a aVar = this.f79k;
        if (aVar != null) {
            aVar.notifyDataSetChanged();
        }
    }

    public p d(ViewGroup viewGroup) {
        if (this.f == null) {
            this.f = (ExpandedMenuView) this.d.inflate(g.a.g.abc_expanded_menu_layout, viewGroup, false);
            if (this.f79k == null) {
                this.f79k = new a();
            }
            this.f.setAdapter((ListAdapter) this.f79k);
            this.f.setOnItemClickListener(this);
        }
        return this.f;
    }

    @Override // androidx.appcompat.view.menu.o
    public boolean e(u uVar) {
        if (!uVar.hasVisibleItems()) {
            return false;
        }
        new i(uVar).d(null);
        o.a aVar = this.f78j;
        if (aVar == null) {
            return true;
        }
        aVar.b(uVar);
        return true;
    }

    @Override // androidx.appcompat.view.menu.o
    public void f(boolean z) {
        a aVar = this.f79k;
        if (aVar != null) {
            aVar.notifyDataSetChanged();
        }
    }

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

    @Override // androidx.appcompat.view.menu.o
    public boolean h(h hVar, j jVar) {
        return false;
    }

    @Override // androidx.appcompat.view.menu.o
    public boolean j(h hVar, j jVar) {
        return false;
    }

    @Override // androidx.appcompat.view.menu.o
    public void k(o.a aVar) {
        this.f78j = aVar;
    }

    @Override // android.widget.AdapterView.OnItemClickListener
    public void onItemClick(AdapterView<?> adapterView, View view, int i2, long j2) {
        this.e.M(this.f79k.getItem(i2), this, 0);
    }

    public f(int i2, int i3) {
        this.f77i = i2;
        this.f76h = i3;
    }
}
