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.m;
import androidx.appcompat.widget.Toolbar;

/* JADX INFO: compiled from: ToolbarWidgetWrapper.java */
/* JADX INFO: loaded from: classes.dex */
public class c1 implements h0 {

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

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

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    Window.Callback f858l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    boolean f859m;

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

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

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

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

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

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

        a() {
            this.f864e = new androidx.appcompat.view.menu.a(c1.this.f847a.getContext(), 0, R.id.home, 0, 0, c1.this.f855i);
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            c1 c1Var = c1.this;
            Window.Callback callback = c1Var.f858l;
            if (callback == null || !c1Var.f859m) {
                return;
            }
            callback.onMenuItemSelected(0, this.f864e);
        }
    }

    /* JADX INFO: compiled from: ToolbarWidgetWrapper.java */
    class b extends androidx.core.view.g0 {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private boolean f866a = false;

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

        b(int i3) {
            this.f867b = i3;
        }

        @Override // androidx.core.view.f0
        public void a(View view) {
            if (this.f866a) {
                return;
            }
            c1.this.f847a.setVisibility(this.f867b);
        }

        @Override // androidx.core.view.g0, androidx.core.view.f0
        public void b(View view) {
            c1.this.f847a.setVisibility(0);
        }

        @Override // androidx.core.view.g0, androidx.core.view.f0
        public void c(View view) {
            this.f866a = true;
        }
    }

    public c1(Toolbar toolbar, boolean z2) {
        this(toolbar, z2, c.h.f3272a, c.e.f3213n);
    }

    private void E(CharSequence charSequence) {
        this.f855i = charSequence;
        if ((this.f848b & 8) != 0) {
            this.f847a.setTitle(charSequence);
            if (this.f854h) {
                androidx.core.view.y.u0(this.f847a.getRootView(), charSequence);
            }
        }
    }

    private void F() {
        if ((this.f848b & 4) != 0) {
            if (TextUtils.isEmpty(this.f857k)) {
                this.f847a.setNavigationContentDescription(this.f862p);
            } else {
                this.f847a.setNavigationContentDescription(this.f857k);
            }
        }
    }

    private void G() {
        if ((this.f848b & 4) == 0) {
            this.f847a.setNavigationIcon((Drawable) null);
            return;
        }
        Toolbar toolbar = this.f847a;
        Drawable drawable = this.f853g;
        if (drawable == null) {
            drawable = this.f863q;
        }
        toolbar.setNavigationIcon(drawable);
    }

    private void H() {
        Drawable drawable;
        int i3 = this.f848b;
        if ((i3 & 2) == 0) {
            drawable = null;
        } else if ((i3 & 1) == 0 || (drawable = this.f852f) == null) {
            drawable = this.f851e;
        }
        this.f847a.setLogo(drawable);
    }

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

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

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

    public void C(CharSequence charSequence) {
        this.f856j = charSequence;
        if ((this.f848b & 8) != 0) {
            this.f847a.setSubtitle(charSequence);
        }
    }

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

    @Override // androidx.appcompat.widget.h0
    public void a(Menu menu, m.a aVar) {
        if (this.f860n == null) {
            c cVar = new c(this.f847a.getContext());
            this.f860n = cVar;
            cVar.p(c.f.f3232g);
        }
        this.f860n.h(aVar);
        this.f847a.K((androidx.appcompat.view.menu.g) menu, this.f860n);
    }

    @Override // androidx.appcompat.widget.h0
    public boolean b() {
        return this.f847a.A();
    }

    @Override // androidx.appcompat.widget.h0
    public boolean c() {
        return this.f847a.B();
    }

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

    @Override // androidx.appcompat.widget.h0
    public Context d() {
        return this.f847a.getContext();
    }

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

    @Override // androidx.appcompat.widget.h0
    public boolean f() {
        return this.f847a.P();
    }

    @Override // androidx.appcompat.widget.h0
    public void g() {
        this.f859m = true;
    }

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

    @Override // androidx.appcompat.widget.h0
    public boolean h() {
        return this.f847a.d();
    }

    @Override // androidx.appcompat.widget.h0
    public void i() {
        this.f847a.f();
    }

    @Override // androidx.appcompat.widget.h0
    public int j() {
        return this.f848b;
    }

    @Override // androidx.appcompat.widget.h0
    public void k(int i3) {
        this.f847a.setVisibility(i3);
    }

    @Override // androidx.appcompat.widget.h0
    public void l(int i3) {
        y(i3 != 0 ? d.a.b(d(), i3) : null);
    }

    @Override // androidx.appcompat.widget.h0
    public void m(t0 t0Var) {
        View view = this.f849c;
        if (view != null) {
            ViewParent parent = view.getParent();
            Toolbar toolbar = this.f847a;
            if (parent == toolbar) {
                toolbar.removeView(this.f849c);
            }
        }
        this.f849c = t0Var;
        if (t0Var == null || this.f861o != 2) {
            return;
        }
        this.f847a.addView(t0Var, 0);
        Toolbar.e eVar = (Toolbar.e) this.f849c.getLayoutParams();
        ((ViewGroup.MarginLayoutParams) eVar).width = -2;
        ((ViewGroup.MarginLayoutParams) eVar).height = -2;
        eVar.f163a = 8388691;
        t0Var.setAllowCollapse(true);
    }

    @Override // androidx.appcompat.widget.h0
    public void n(boolean z2) {
    }

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

    @Override // androidx.appcompat.widget.h0
    public androidx.core.view.e0 p(int i3, long j3) {
        return androidx.core.view.y.e(this.f847a).b(i3 == 0 ? 1.0f : 0.0f).f(j3).h(new b(i3));
    }

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

    @Override // androidx.appcompat.widget.h0
    public boolean r() {
        return this.f847a.v();
    }

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

    @Override // androidx.appcompat.widget.h0
    public void setIcon(int i3) {
        setIcon(i3 != 0 ? d.a.b(d(), i3) : null);
    }

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

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

    @Override // androidx.appcompat.widget.h0
    public void t(boolean z2) {
        this.f847a.setCollapsible(z2);
    }

    @Override // androidx.appcompat.widget.h0
    public void u(int i3) {
        View view;
        int i4 = this.f848b ^ i3;
        this.f848b = i3;
        if (i4 != 0) {
            if ((i4 & 4) != 0) {
                if ((i3 & 4) != 0) {
                    F();
                }
                G();
            }
            if ((i4 & 3) != 0) {
                H();
            }
            if ((i4 & 8) != 0) {
                if ((i3 & 8) != 0) {
                    this.f847a.setTitle(this.f855i);
                    this.f847a.setSubtitle(this.f856j);
                } else {
                    this.f847a.setTitle((CharSequence) null);
                    this.f847a.setSubtitle((CharSequence) null);
                }
            }
            if ((i4 & 16) == 0 || (view = this.f850d) == null) {
                return;
            }
            if ((i3 & 16) != 0) {
                this.f847a.addView(view);
            } else {
                this.f847a.removeView(view);
            }
        }
    }

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

    public void x(int i3) {
        if (i3 == this.f862p) {
            return;
        }
        this.f862p = i3;
        if (TextUtils.isEmpty(this.f847a.getNavigationContentDescription())) {
            z(this.f862p);
        }
    }

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

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

    public c1(Toolbar toolbar, boolean z2, int i3, int i4) {
        Drawable drawable;
        this.f861o = 0;
        this.f862p = 0;
        this.f847a = toolbar;
        this.f855i = toolbar.getTitle();
        this.f856j = toolbar.getSubtitle();
        this.f854h = this.f855i != null;
        this.f853g = toolbar.getNavigationIcon();
        a1 a1VarV = a1.v(toolbar.getContext(), null, c.j.f3288a, c.a.f3152c, 0);
        this.f863q = a1VarV.g(c.j.f3332l);
        if (z2) {
            CharSequence charSequenceP = a1VarV.p(c.j.f3350r);
            if (!TextUtils.isEmpty(charSequenceP)) {
                D(charSequenceP);
            }
            CharSequence charSequenceP2 = a1VarV.p(c.j.f3344p);
            if (!TextUtils.isEmpty(charSequenceP2)) {
                C(charSequenceP2);
            }
            Drawable drawableG = a1VarV.g(c.j.f3338n);
            if (drawableG != null) {
                y(drawableG);
            }
            Drawable drawableG2 = a1VarV.g(c.j.f3335m);
            if (drawableG2 != null) {
                setIcon(drawableG2);
            }
            if (this.f853g == null && (drawable = this.f863q) != null) {
                B(drawable);
            }
            u(a1VarV.k(c.j.f3316h, 0));
            int iN = a1VarV.n(c.j.f3312g, 0);
            if (iN != 0) {
                w(LayoutInflater.from(this.f847a.getContext()).inflate(iN, (ViewGroup) this.f847a, false));
                u(this.f848b | 16);
            }
            int iM = a1VarV.m(c.j.f3324j, 0);
            if (iM > 0) {
                ViewGroup.LayoutParams layoutParams = this.f847a.getLayoutParams();
                layoutParams.height = iM;
                this.f847a.setLayoutParams(layoutParams);
            }
            int iE = a1VarV.e(c.j.f3308f, -1);
            int iE2 = a1VarV.e(c.j.f3304e, -1);
            if (iE >= 0 || iE2 >= 0) {
                this.f847a.J(Math.max(iE, 0), Math.max(iE2, 0));
            }
            int iN2 = a1VarV.n(c.j.f3353s, 0);
            if (iN2 != 0) {
                Toolbar toolbar2 = this.f847a;
                toolbar2.M(toolbar2.getContext(), iN2);
            }
            int iN3 = a1VarV.n(c.j.f3347q, 0);
            if (iN3 != 0) {
                Toolbar toolbar3 = this.f847a;
                toolbar3.L(toolbar3.getContext(), iN3);
            }
            int iN4 = a1VarV.n(c.j.f3341o, 0);
            if (iN4 != 0) {
                this.f847a.setPopupTheme(iN4);
            }
        } else {
            this.f848b = v();
        }
        a1VarV.w();
        x(i3);
        this.f857k = this.f847a.getNavigationContentDescription();
        this.f847a.setNavigationOnClickListener(new a());
    }

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