package ῲ.ῲ.ඓ.㳳;

import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.SparseArray;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import androidx.appcompat.R$layout;
import androidx.appcompat.view.menu.ExpandedMenuView;
import com.google.android.material.internal.NavigationMenuPresenter;
import java.util.ArrayList;
import ῲ.ῲ.ඓ.㳳.AbstractC1897;
import ῲ.ῲ.ඓ.㳳.AbstractC1917;
import ῲ.ῲ.K.DialogInterfaceC1958;

/* renamed from: ῲ.ῲ.ඓ.㳳.ඓ  reason: contains not printable characters */
/* compiled from: ListMenuPresenter */
public class C1901 implements AbstractC1897, AdapterView.OnItemClickListener {

    /* renamed from: ʬ  reason: contains not printable characters */
    public LayoutInflater f6440;

    /* renamed from: ඓ  reason: contains not printable characters */
    public ExpandedMenuView f6441;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public int f6442;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public AbstractC1897.AbstractC1898 f6443;

    /* renamed from: ῲ  reason: contains not printable characters */
    public Context f6444;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public int f6445 = 0;

    /* renamed from: 㳳  reason: contains not printable characters */
    public C1902 f6446;

    /* renamed from: 㴹  reason: contains not printable characters */
    public int f6447;

    /* renamed from: 㸾  reason: contains not printable characters */
    public C1912 f6448;

    /* renamed from: 㿎  reason: contains not printable characters */
    public int f6449;

    /* renamed from: ῲ.ῲ.ඓ.㳳.ඓ$K  reason: contains not printable characters */
    /* compiled from: ListMenuPresenter */
    public class C1902 extends BaseAdapter {

        /* renamed from: ῲ  reason: contains not printable characters */
        public int f6451 = -1;

        public C1902() {
            m4924();
        }

        public int getCount() {
            int size = C1901.this.f6448.getNonActionItems().size() - C1901.this.f6447;
            return this.f6451 < 0 ? size : size - 1;
        }

        public long getItemId(int i) {
            return (long) i;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            if (view == null) {
                C1901 r4 = C1901.this;
                view = r4.f6440.inflate(r4.f6449, viewGroup, false);
            }
            ((AbstractC1917.AbstractC1918) view).initialize(getItem(i), 0);
            return view;
        }

        public void notifyDataSetChanged() {
            m4924();
            super.notifyDataSetChanged();
        }

        /* renamed from: K  reason: contains not printable characters */
        public void m4924() {
            C1922 expandedItem = C1901.this.f6448.getExpandedItem();
            if (expandedItem != null) {
                ArrayList<C1922> nonActionItems = C1901.this.f6448.getNonActionItems();
                int size = nonActionItems.size();
                for (int i = 0; i < size; i++) {
                    if (nonActionItems.get(i) == expandedItem) {
                        this.f6451 = i;
                        return;
                    }
                }
            }
            this.f6451 = -1;
        }

        public C1922 getItem(int i) {
            ArrayList<C1922> nonActionItems = C1901.this.f6448.getNonActionItems();
            int i2 = i + C1901.this.f6447;
            int i3 = this.f6451;
            if (i3 >= 0 && i2 >= i3) {
                i2++;
            }
            return nonActionItems.get(i2);
        }
    }

    public C1901(Context context, int i) {
        this.f6449 = i;
        this.f6444 = context;
        this.f6440 = LayoutInflater.from(this.f6444);
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public boolean collapseItemActionView(C1912 r1, C1922 r2) {
        return false;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public boolean expandItemActionView(C1912 r1, C1922 r2) {
        return false;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public boolean flagActionItems() {
        return false;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public int getId() {
        return this.f6442;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public void initForMenu(Context context, C1912 r4) {
        int i = this.f6445;
        if (i != 0) {
            this.f6444 = new ContextThemeWrapper(context, i);
            this.f6440 = LayoutInflater.from(this.f6444);
        } else if (this.f6444 != null) {
            this.f6444 = context;
            if (this.f6440 == null) {
                this.f6440 = LayoutInflater.from(this.f6444);
            }
        }
        this.f6448 = r4;
        C1902 k = this.f6446;
        if (k != null) {
            k.notifyDataSetChanged();
        }
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public void onCloseMenu(C1912 r2, boolean z) {
        AbstractC1897.AbstractC1898 k = this.f6443;
        if (k != null) {
            k.onCloseMenu(r2, z);
        }
    }

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

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public void onRestoreInstanceState(Parcelable parcelable) {
        SparseArray<Parcelable> sparseParcelableArray = ((Bundle) parcelable).getSparseParcelableArray(NavigationMenuPresenter.STATE_HIERARCHY);
        if (sparseParcelableArray != null) {
            this.f6441.restoreHierarchyState(sparseParcelableArray);
        }
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public Parcelable onSaveInstanceState() {
        if (this.f6441 == null) {
            return null;
        }
        Bundle bundle = new Bundle();
        SparseArray<Parcelable> sparseArray = new SparseArray<>();
        ExpandedMenuView expandedMenuView = this.f6441;
        if (expandedMenuView != null) {
            expandedMenuView.saveHierarchyState(sparseArray);
        }
        bundle.putSparseParcelableArray(NavigationMenuPresenter.STATE_HIERARCHY, sparseArray);
        return bundle;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public boolean onSubMenuSelected(SubMenuC1900 r7) {
        if (!r7.hasVisibleItems()) {
            return false;
        }
        DialogInterface$OnKeyListenerC1931 r0 = new DialogInterface$OnKeyListenerC1931(r7);
        C1912 r1 = r0.f6591;
        DialogInterfaceC1958.C1959 k = new DialogInterfaceC1958.C1959(r1.getContext());
        r0.f6592 = new C1901(k.getContext(), R$layout.abc_list_menu_item_layout);
        C1901 r3 = r0.f6592;
        r3.f6443 = r0;
        r0.f6591.addMenuPresenter(r3);
        k.setAdapter(r0.f6592.m4923(), r0);
        View headerView = r1.getHeaderView();
        if (headerView != null) {
            k.setCustomTitle(headerView);
        } else {
            k.setIcon(r1.getHeaderIcon()).setTitle(r1.getHeaderTitle());
        }
        k.setOnKeyListener(r0);
        r0.f6589 = k.create();
        r0.f6589.setOnDismissListener(r0);
        WindowManager.LayoutParams attributes = r0.f6589.getWindow().getAttributes();
        attributes.type = 1003;
        attributes.flags |= 131072;
        r0.f6589.show();
        AbstractC1897.AbstractC1898 k2 = this.f6443;
        if (k2 == null) {
            return true;
        }
        k2.m4922(r7);
        return true;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public void setCallback(AbstractC1897.AbstractC1898 k) {
        this.f6443 = k;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public void updateMenuView(boolean z) {
        C1902 k = this.f6446;
        if (k != null) {
            k.notifyDataSetChanged();
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public ListAdapter m4923() {
        if (this.f6446 == null) {
            this.f6446 = new C1902();
        }
        return this.f6446;
    }
}
