package o;

import android.content.Context;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.appcompat.widget.Toolbar;
import java.util.ArrayList;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Of0 implements InterfaceC1093eP {
    public CO l;
    public LO m;
    public final /* synthetic */ Toolbar n;

    public Of0(Toolbar toolbar) {
        this.n = toolbar;
    }

    @Override // o.InterfaceC1093eP
    public final void c() {
        if (this.m != null) {
            CO co = this.l;
            if (co != null) {
                int size = co.f.size();
                for (int i = 0; i < size; i++) {
                    if (this.l.getItem(i) == this.m) {
                        return;
                    }
                }
            }
            k(this.m);
        }
    }

    @Override // o.InterfaceC1093eP
    public final boolean d(LO lo) {
        Toolbar toolbar = this.n;
        toolbar.c();
        ViewParent parent = toolbar.s.getParent();
        if (parent != toolbar) {
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(toolbar.s);
            }
            toolbar.addView(toolbar.s);
        }
        View actionView = lo.getActionView();
        toolbar.t = actionView;
        this.m = lo;
        ViewParent parent2 = actionView.getParent();
        if (parent2 != toolbar) {
            if (parent2 instanceof ViewGroup) {
                ((ViewGroup) parent2).removeView(toolbar.t);
            }
            Pf0 pf0H = Toolbar.h();
            pf0H.a = (toolbar.y & 112) | 8388611;
            pf0H.b = 2;
            toolbar.t.setLayoutParams(pf0H);
            toolbar.addView(toolbar.t);
        }
        for (int childCount = toolbar.getChildCount() - 1; childCount >= 0; childCount--) {
            View childAt = toolbar.getChildAt(childCount);
            if (((Pf0) childAt.getLayoutParams()).b != 2 && childAt != toolbar.l) {
                toolbar.removeViewAt(childCount);
                toolbar.P.add(childAt);
            }
        }
        toolbar.requestLayout();
        lo.C = true;
        lo.n.p(false);
        KeyEvent.Callback callback = toolbar.t;
        if (callback instanceof InterfaceC2927xi) {
            ((NO) ((InterfaceC2927xi) callback)).l.onActionViewExpanded();
        }
        toolbar.w();
        return true;
    }

    @Override // o.InterfaceC1093eP
    public final void g(Context context, CO co) {
        LO lo;
        CO co2 = this.l;
        if (co2 != null && (lo = this.m) != null) {
            co2.d(lo);
        }
        this.l = co;
    }

    @Override // o.InterfaceC1093eP
    public final boolean i() {
        return false;
    }

    @Override // o.InterfaceC1093eP
    public final boolean j(SubMenuC2155pb0 subMenuC2155pb0) {
        return false;
    }

    @Override // o.InterfaceC1093eP
    public final boolean k(LO lo) {
        Toolbar toolbar = this.n;
        KeyEvent.Callback callback = toolbar.t;
        if (callback instanceof InterfaceC2927xi) {
            ((NO) ((InterfaceC2927xi) callback)).l.onActionViewCollapsed();
        }
        toolbar.removeView(toolbar.t);
        toolbar.removeView(toolbar.s);
        toolbar.t = null;
        ArrayList arrayList = toolbar.P;
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            toolbar.addView((View) arrayList.get(size));
        }
        arrayList.clear();
        this.m = null;
        toolbar.requestLayout();
        lo.C = false;
        lo.n.p(false);
        toolbar.w();
        return true;
    }

    @Override // o.InterfaceC1093eP
    public final void a(CO co, boolean z) {
    }
}
