package androidx.appcompat.widget;

import android.R;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import androidx.appcompat.view.menu.o;
import androidx.appcompat.widget.Toolbar;

/* JADX INFO: compiled from: ToolbarWidgetWrapper.java */
/* JADX INFO: loaded from: classes.dex */
public class u0 implements b0 {
    Toolbar a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private int f505b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private View f506c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private View f507d;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private Drawable f509f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private Drawable f510g;

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private CharSequence f513j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private CharSequence f514k;
    Window.Callback l;
    boolean m;
    private c n;
    private int o;
    private int p;
    private Drawable q;

    /* JADX INFO: compiled from: ToolbarWidgetWrapper.java */
    class a implements View.OnClickListener {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final androidx.appcompat.view.menu.a f515b;

        a() {
            this.f515b = new androidx.appcompat.view.menu.a(u0.this.a.getContext(), 0, R.id.home, 0, 0, u0.this.f512i);
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            u0 u0Var = u0.this;
            Window.Callback callback = u0Var.l;
            if (callback == null || !u0Var.m) {
                return;
            }
            callback.onMenuItemSelected(0, this.f515b);
        }
    }

    /* JADX INFO: compiled from: ToolbarWidgetWrapper.java */
    class b extends c.f.l.z {
        private boolean a = false;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ int f517b;

        b(int i2) {
            this.f517b = i2;
        }

        @Override // c.f.l.z, c.f.l.y
        public void a(View view) {
            this.a = true;
        }

        @Override // c.f.l.y
        public void b(View view) {
            if (this.a) {
                return;
            }
            u0.this.a.setVisibility(this.f517b);
        }

        @Override // c.f.l.z, c.f.l.y
        public void c(View view) {
            u0.this.a.setVisibility(0);
        }
    }

    public u0(Toolbar toolbar, boolean z) {
        this(toolbar, z, c.a.h.abc_action_bar_up_description, c.a.e.abc_ic_ab_back_material);
    }

    private void E(CharSequence charSequence) {
        this.f512i = charSequence;
        if ((this.f505b & 8) != 0) {
            this.a.setTitle(charSequence);
        }
    }

    private void F() {
        if ((this.f505b & 4) != 0) {
            if (TextUtils.isEmpty(this.f514k)) {
                this.a.setNavigationContentDescription(this.p);
            } else {
                this.a.setNavigationContentDescription(this.f514k);
            }
        }
    }

    private void G() {
        if ((this.f505b & 4) == 0) {
            this.a.setNavigationIcon((Drawable) null);
            return;
        }
        Toolbar toolbar = this.a;
        Drawable drawable = this.f510g;
        if (drawable == null) {
            drawable = this.q;
        }
        toolbar.setNavigationIcon(drawable);
    }

    private void H() {
        Drawable drawable;
        int i2 = this.f505b;
        if ((i2 & 2) == 0) {
            drawable = null;
        } else if ((i2 & 1) == 0 || (drawable = this.f509f) == null) {
            drawable = this.f508e;
        }
        this.a.setLogo(drawable);
    }

    private int v() {
        if (this.a.getNavigationIcon() == null) {
            return 11;
        }
        this.q = this.a.getNavigationIcon();
        return 15;
    }

    public void A(CharSequence charSequence) {
        this.f514k = charSequence;
        F();
    }

    public void B(Drawable drawable) {
        this.f510g = drawable;
        G();
    }

    public void C(CharSequence charSequence) {
        this.f513j = charSequence;
        if ((this.f505b & 8) != 0) {
            this.a.setSubtitle(charSequence);
        }
    }

    public void D(CharSequence charSequence) {
        this.f511h = true;
        E(charSequence);
    }

    @Override // androidx.appcompat.widget.b0
    public void a(Menu menu, o.a aVar) {
        if (this.n == null) {
            c cVar = new c(this.a.getContext());
            this.n = cVar;
            cVar.p(c.a.f.action_menu_presenter);
        }
        this.n.k(aVar);
        this.a.H((androidx.appcompat.view.menu.h) menu, this.n);
    }

    @Override // androidx.appcompat.widget.b0
    public boolean b() {
        return this.a.z();
    }

    @Override // androidx.appcompat.widget.b0
    public void c() {
        this.m = true;
    }

    @Override // androidx.appcompat.widget.b0
    public void collapseActionView() {
        this.a.e();
    }

    @Override // androidx.appcompat.widget.b0
    public boolean d() {
        return this.a.y();
    }

    @Override // androidx.appcompat.widget.b0
    public boolean e() {
        return this.a.w();
    }

    @Override // androidx.appcompat.widget.b0
    public boolean f() {
        return this.a.M();
    }

    @Override // androidx.appcompat.widget.b0
    public boolean g() {
        return this.a.d();
    }

    @Override // androidx.appcompat.widget.b0
    public Context getContext() {
        return this.a.getContext();
    }

    @Override // androidx.appcompat.widget.b0
    public CharSequence getTitle() {
        return this.a.getTitle();
    }

    @Override // androidx.appcompat.widget.b0
    public void h() {
        this.a.f();
    }

    @Override // androidx.appcompat.widget.b0
    public void i(int i2) {
        this.a.setVisibility(i2);
    }

    @Override // androidx.appcompat.widget.b0
    public void j(m0 m0Var) {
        View view = this.f506c;
        if (view != null) {
            ViewParent parent = view.getParent();
            Toolbar toolbar = this.a;
            if (parent == toolbar) {
                toolbar.removeView(this.f506c);
            }
        }
        this.f506c = m0Var;
        if (m0Var == null || this.o != 2) {
            return;
        }
        this.a.addView(m0Var, 0);
        Toolbar.e eVar = (Toolbar.e) this.f506c.getLayoutParams();
        ((ViewGroup.MarginLayoutParams) eVar).width = -2;
        ((ViewGroup.MarginLayoutParams) eVar).height = -2;
        eVar.a = 8388691;
        m0Var.setAllowCollapse(true);
    }

    @Override // androidx.appcompat.widget.b0
    public ViewGroup k() {
        return this.a;
    }

    @Override // androidx.appcompat.widget.b0
    public void l(boolean z) {
    }

    @Override // androidx.appcompat.widget.b0
    public boolean m() {
        return this.a.v();
    }

    @Override // androidx.appcompat.widget.b0
    public void n(int i2) {
        View view;
        int i3 = this.f505b ^ i2;
        this.f505b = i2;
        if (i3 != 0) {
            if ((i3 & 4) != 0) {
                if ((i2 & 4) != 0) {
                    F();
                }
                G();
            }
            if ((i3 & 3) != 0) {
                H();
            }
            if ((i3 & 8) != 0) {
                if ((i2 & 8) != 0) {
                    this.a.setTitle(this.f512i);
                    this.a.setSubtitle(this.f513j);
                } else {
                    this.a.setTitle((CharSequence) null);
                    this.a.setSubtitle((CharSequence) null);
                }
            }
            if ((i3 & 16) == 0 || (view = this.f507d) == null) {
                return;
            }
            if ((i2 & 16) != 0) {
                this.a.addView(view);
            } else {
                this.a.removeView(view);
            }
        }
    }

    @Override // androidx.appcompat.widget.b0
    public int o() {
        return this.f505b;
    }

    @Override // androidx.appcompat.widget.b0
    public void p(int i2) {
        y(i2 != 0 ? c.a.k.a.a.d(getContext(), i2) : null);
    }

    @Override // androidx.appcompat.widget.b0
    public int q() {
        return this.o;
    }

    @Override // androidx.appcompat.widget.b0
    public c.f.l.x r(int i2, long j2) {
        c.f.l.x xVarB = c.f.l.t.b(this.a);
        xVarB.a(i2 == 0 ? 1.0f : 0.0f);
        xVarB.d(j2);
        xVarB.f(new b(i2));
        return xVarB;
    }

    @Override // androidx.appcompat.widget.b0
    public void s() {
        Log.i("ToolbarWidgetWrapper", "Progress display unsupported");
    }

    @Override // androidx.appcompat.widget.b0
    public void setIcon(int i2) {
        setIcon(i2 != 0 ? c.a.k.a.a.d(getContext(), i2) : null);
    }

    @Override // androidx.appcompat.widget.b0
    public void setWindowCallback(Window.Callback callback) {
        this.l = callback;
    }

    @Override // androidx.appcompat.widget.b0
    public void setWindowTitle(CharSequence charSequence) {
        if (this.f511h) {
            return;
        }
        E(charSequence);
    }

    @Override // androidx.appcompat.widget.b0
    public void t() {
        Log.i("ToolbarWidgetWrapper", "Progress display unsupported");
    }

    @Override // androidx.appcompat.widget.b0
    public void u(boolean z) {
        this.a.setCollapsible(z);
    }

    public void w(View view) {
        View view2 = this.f507d;
        if (view2 != null && (this.f505b & 16) != 0) {
            this.a.removeView(view2);
        }
        this.f507d = view;
        if (view == null || (this.f505b & 16) == 0) {
            return;
        }
        this.a.addView(view);
    }

    public void x(int i2) {
        if (i2 == this.p) {
            return;
        }
        this.p = i2;
        if (TextUtils.isEmpty(this.a.getNavigationContentDescription())) {
            z(this.p);
        }
    }

    public void y(Drawable drawable) {
        this.f509f = drawable;
        H();
    }

    public void z(int i2) {
        A(i2 == 0 ? null : getContext().getString(i2));
    }

    public u0(Toolbar toolbar, boolean z, int i2, int i3) {
        Drawable drawable;
        this.o = 0;
        this.p = 0;
        this.a = toolbar;
        this.f512i = toolbar.getTitle();
        this.f513j = toolbar.getSubtitle();
        this.f511h = this.f512i != null;
        this.f510g = toolbar.getNavigationIcon();
        t0 t0VarT = t0.t(toolbar.getContext(), null, c.a.j.ActionBar, c.a.a.actionBarStyle, 0);
        this.q = t0VarT.f(c.a.j.ActionBar_homeAsUpIndicator);
        if (z) {
            CharSequence charSequenceO = t0VarT.o(c.a.j.ActionBar_title);
            if (!TextUtils.isEmpty(charSequenceO)) {
                D(charSequenceO);
            }
            CharSequence charSequenceO2 = t0VarT.o(c.a.j.ActionBar_subtitle);
            if (!TextUtils.isEmpty(charSequenceO2)) {
                C(charSequenceO2);
            }
            Drawable drawableF = t0VarT.f(c.a.j.ActionBar_logo);
            if (drawableF != null) {
                y(drawableF);
            }
            Drawable drawableF2 = t0VarT.f(c.a.j.ActionBar_icon);
            if (drawableF2 != null) {
                setIcon(drawableF2);
            }
            if (this.f510g == null && (drawable = this.q) != null) {
                B(drawable);
            }
            n(t0VarT.j(c.a.j.ActionBar_displayOptions, 0));
            int iM = t0VarT.m(c.a.j.ActionBar_customNavigationLayout, 0);
            if (iM != 0) {
                w(LayoutInflater.from(this.a.getContext()).inflate(iM, (ViewGroup) this.a, false));
                n(this.f505b | 16);
            }
            int iL = t0VarT.l(c.a.j.ActionBar_height, 0);
            if (iL > 0) {
                ViewGroup.LayoutParams layoutParams = this.a.getLayoutParams();
                layoutParams.height = iL;
                this.a.setLayoutParams(layoutParams);
            }
            int iD = t0VarT.d(c.a.j.ActionBar_contentInsetStart, -1);
            int iD2 = t0VarT.d(c.a.j.ActionBar_contentInsetEnd, -1);
            if (iD >= 0 || iD2 >= 0) {
                this.a.G(Math.max(iD, 0), Math.max(iD2, 0));
            }
            int iM2 = t0VarT.m(c.a.j.ActionBar_titleTextStyle, 0);
            if (iM2 != 0) {
                Toolbar toolbar2 = this.a;
                toolbar2.J(toolbar2.getContext(), iM2);
            }
            int iM3 = t0VarT.m(c.a.j.ActionBar_subtitleTextStyle, 0);
            if (iM3 != 0) {
                Toolbar toolbar3 = this.a;
                toolbar3.I(toolbar3.getContext(), iM3);
            }
            int iM4 = t0VarT.m(c.a.j.ActionBar_popupTheme, 0);
            if (iM4 != 0) {
                this.a.setPopupTheme(iM4);
            }
        } else {
            this.f505b = v();
        }
        t0VarT.u();
        x(i2);
        this.f514k = this.a.getNavigationContentDescription();
        this.a.setNavigationOnClickListener(new a());
    }

    @Override // androidx.appcompat.widget.b0
    public void setIcon(Drawable drawable) {
        this.f508e = drawable;
        H();
    }
}
