package android.support.v7.view.menu;

import android.content.Context;
import android.support.v7.view.menu.o;
import android.support.v7.view.menu.p;
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 java.util.ArrayList;

/* JADX INFO: compiled from: ListMenuPresenter.java */
/* JADX INFO: loaded from: classes.dex */
public class f implements o, AdapterView.OnItemClickListener {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    Context f871b;

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    ExpandedMenuView f874e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    int f875f;
    int g;
    int h;
    private o.a i;
    a j;

    /* JADX INFO: compiled from: ListMenuPresenter.java */
    private class a extends BaseAdapter {

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

        public a() {
            a();
        }

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

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

        @Override // android.widget.Adapter
        public int getCount() {
            int size = f.this.f873d.z().size() - f.this.f875f;
            return this.f876b < 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) {
                f fVar = f.this;
                view = fVar.f872c.inflate(fVar.h, viewGroup, false);
            }
            ((p.a) view).b(getItem(i), 0);
            return view;
        }

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

    public f(Context context, int i) {
        this(i, 0);
        this.f871b = context;
        this.f872c = LayoutInflater.from(context);
    }

    @Override // android.support.v7.view.menu.o
    public void a(h hVar, boolean z) {
        o.a aVar = this.i;
        if (aVar != null) {
            aVar.a(hVar, z);
        }
    }

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

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

    @Override // android.support.v7.view.menu.o
    public boolean d() {
        return false;
    }

    @Override // android.support.v7.view.menu.o
    public boolean e(h hVar, j jVar) {
        return false;
    }

    @Override // android.support.v7.view.menu.o
    public void f(o.a aVar) {
        this.i = aVar;
    }

    @Override // android.support.v7.view.menu.o
    public void g(Context context, h hVar) {
        if (this.g != 0) {
            ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(context, this.g);
            this.f871b = contextThemeWrapper;
            this.f872c = LayoutInflater.from(contextThemeWrapper);
        } else if (this.f871b != null) {
            this.f871b = context;
            if (this.f872c == null) {
                this.f872c = LayoutInflater.from(context);
            }
        }
        this.f873d = hVar;
        a aVar = this.j;
        if (aVar != null) {
            aVar.notifyDataSetChanged();
        }
    }

    public p h(ViewGroup viewGroup) {
        if (this.f874e == null) {
            this.f874e = (ExpandedMenuView) this.f872c.inflate(a.b.d.a.g.abc_expanded_menu_layout, viewGroup, false);
            if (this.j == null) {
                this.j = new a();
            }
            this.f874e.setAdapter((ListAdapter) this.j);
            this.f874e.setOnItemClickListener(this);
        }
        return this.f874e;
    }

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

    @Override // android.support.v7.view.menu.o
    public void k(boolean z) {
        a aVar = this.j;
        if (aVar != null) {
            aVar.notifyDataSetChanged();
        }
    }

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

    public f(int i, int i2) {
        this.h = i;
        this.g = i2;
    }
}
