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.e;
import androidx.appcompat.view.menu.j;
import androidx.core.view.b1;
import androidx.core.view.d1;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;

/* loaded from: classes.dex */
public class x0 implements e0 {

    /* renamed from: a, reason: collision with root package name */
    Toolbar f1199a;

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

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

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

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

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

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

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

    /* renamed from: i, reason: collision with root package name */
    CharSequence f1207i;

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

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

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

    /* renamed from: m, reason: collision with root package name */
    boolean f1211m;

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

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

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

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

    /* loaded from: classes.dex */
    class a implements View.OnClickListener {

        /* renamed from: p, reason: collision with root package name */
        final o.a f1216p;

        a() {
            this.f1216p = new o.a(x0.this.f1199a.getContext(), 0, R.id.home, 0, 0, x0.this.f1207i);
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            x0 x0Var = x0.this;
            Window.Callback callback = x0Var.f1210l;
            if (callback == null || !x0Var.f1211m) {
                return;
            }
            callback.onMenuItemSelected(0, this.f1216p);
        }
    }

    /* loaded from: classes.dex */
    class b extends d1 {

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

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

        b(int i10) {
            this.f1219b = i10;
        }

        @Override // androidx.core.view.d1, androidx.core.view.c1
        public void a(View view) {
            this.f1218a = true;
        }

        @Override // androidx.core.view.c1
        public void b(View view) {
            if (this.f1218a) {
                return;
            }
            x0.this.f1199a.setVisibility(this.f1219b);
        }

        @Override // androidx.core.view.d1, androidx.core.view.c1
        public void c(View view) {
            x0.this.f1199a.setVisibility(0);
        }
    }

    public x0(Toolbar toolbar, boolean z10) {
        this(toolbar, z10, h.h.f20262a, h.e.f20204n);
    }

    private int B() {
        if (this.f1199a.getNavigationIcon() == null) {
            return 11;
        }
        this.f1215q = this.f1199a.getNavigationIcon();
        return 15;
    }

    private void H(CharSequence charSequence) {
        this.f1207i = charSequence;
        if ((this.f1200b & 8) != 0) {
            this.f1199a.setTitle(charSequence);
            if (this.f1206h) {
                androidx.core.view.s0.p0(this.f1199a.getRootView(), charSequence);
            }
        }
    }

    private void I() {
        if ((this.f1200b & 4) != 0) {
            if (TextUtils.isEmpty(this.f1209k)) {
                this.f1199a.setNavigationContentDescription(this.f1214p);
            } else {
                this.f1199a.setNavigationContentDescription(this.f1209k);
            }
        }
    }

    private void J() {
        if ((this.f1200b & 4) == 0) {
            this.f1199a.setNavigationIcon((Drawable) null);
            return;
        }
        Toolbar toolbar = this.f1199a;
        Drawable drawable = this.f1205g;
        if (drawable == null) {
            drawable = this.f1215q;
        }
        toolbar.setNavigationIcon(drawable);
    }

    private void K() {
        Drawable drawable;
        int i10 = this.f1200b;
        if ((i10 & 2) == 0) {
            drawable = null;
        } else if ((i10 & 1) != 0) {
            drawable = this.f1204f;
            if (drawable == null) {
                drawable = this.f1203e;
            }
        } else {
            drawable = this.f1203e;
        }
        this.f1199a.setLogo(drawable);
    }

    @Override // androidx.appcompat.widget.e0
    public void A(boolean z10) {
        this.f1199a.setCollapsible(z10);
    }

    public void C(View view) {
        View view2 = this.f1202d;
        if (view2 != null && (this.f1200b & 16) != 0) {
            this.f1199a.removeView(view2);
        }
        this.f1202d = view;
        if (view == null || (this.f1200b & 16) == 0) {
            return;
        }
        this.f1199a.addView(view);
    }

    public void D(int i10) {
        if (i10 == this.f1214p) {
            return;
        }
        this.f1214p = i10;
        if (TextUtils.isEmpty(this.f1199a.getNavigationContentDescription())) {
            w(this.f1214p);
        }
    }

    public void E(Drawable drawable) {
        this.f1204f = drawable;
        K();
    }

    public void F(CharSequence charSequence) {
        this.f1209k = charSequence;
        I();
    }

    public void G(CharSequence charSequence) {
        this.f1208j = charSequence;
        if ((this.f1200b & 8) != 0) {
            this.f1199a.setSubtitle(charSequence);
        }
    }

    @Override // androidx.appcompat.widget.e0
    public void a(Menu menu, j.a aVar) {
        if (this.f1212n == null) {
            c cVar = new c(this.f1199a.getContext());
            this.f1212n = cVar;
            cVar.r(h.f.f20223g);
        }
        this.f1212n.h(aVar);
        this.f1199a.K((androidx.appcompat.view.menu.e) menu, this.f1212n);
    }

    @Override // androidx.appcompat.widget.e0
    public void b(Drawable drawable) {
        androidx.core.view.s0.q0(this.f1199a, drawable);
    }

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

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

    @Override // androidx.appcompat.widget.e0
    public void d() {
        this.f1211m = true;
    }

    @Override // androidx.appcompat.widget.e0
    public boolean e() {
        return this.f1199a.d();
    }

    @Override // androidx.appcompat.widget.e0
    public boolean f() {
        return this.f1199a.A();
    }

    @Override // androidx.appcompat.widget.e0
    public boolean g() {
        return this.f1199a.w();
    }

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

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

    @Override // androidx.appcompat.widget.e0
    public boolean h() {
        return this.f1199a.Q();
    }

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

    @Override // androidx.appcompat.widget.e0
    public void j(p0 p0Var) {
        View view = this.f1201c;
        if (view != null) {
            ViewParent parent = view.getParent();
            Toolbar toolbar = this.f1199a;
            if (parent == toolbar) {
                toolbar.removeView(this.f1201c);
            }
        }
        this.f1201c = p0Var;
    }

    @Override // androidx.appcompat.widget.e0
    public boolean k() {
        return this.f1199a.v();
    }

    @Override // androidx.appcompat.widget.e0
    public void l(int i10) {
        View view;
        int i11 = this.f1200b ^ i10;
        this.f1200b = i10;
        if (i11 != 0) {
            if ((i11 & 4) != 0) {
                if ((i10 & 4) != 0) {
                    I();
                }
                J();
            }
            if ((i11 & 3) != 0) {
                K();
            }
            if ((i11 & 8) != 0) {
                if ((i10 & 8) != 0) {
                    this.f1199a.setTitle(this.f1207i);
                    this.f1199a.setSubtitle(this.f1208j);
                } else {
                    this.f1199a.setTitle((CharSequence) null);
                    this.f1199a.setSubtitle((CharSequence) null);
                }
            }
            if ((i11 & 16) == 0 || (view = this.f1202d) == null) {
                return;
            }
            if ((i10 & 16) != 0) {
                this.f1199a.addView(view);
            } else {
                this.f1199a.removeView(view);
            }
        }
    }

    @Override // androidx.appcompat.widget.e0
    public Menu m() {
        return this.f1199a.getMenu();
    }

    @Override // androidx.appcompat.widget.e0
    public void n(int i10) {
        E(i10 != 0 ? j.a.b(getContext(), i10) : null);
    }

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

    @Override // androidx.appcompat.widget.e0
    public b1 p(int i10, long j10) {
        return androidx.core.view.s0.e(this.f1199a).b(i10 == 0 ? 1.0f : BitmapDescriptorFactory.HUE_RED).f(j10).h(new b(i10));
    }

    @Override // androidx.appcompat.widget.e0
    public void q(int i10) {
        z(i10 != 0 ? j.a.b(getContext(), i10) : null);
    }

    @Override // androidx.appcompat.widget.e0
    public void r(j.a aVar, e.a aVar2) {
        this.f1199a.L(aVar, aVar2);
    }

    @Override // androidx.appcompat.widget.e0
    public void s(int i10) {
        this.f1199a.setVisibility(i10);
    }

    @Override // androidx.appcompat.widget.e0
    public void setIcon(int i10) {
        setIcon(i10 != 0 ? j.a.b(getContext(), i10) : null);
    }

    @Override // androidx.appcompat.widget.e0
    public void setTitle(CharSequence charSequence) {
        this.f1206h = true;
        H(charSequence);
    }

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

    @Override // androidx.appcompat.widget.e0
    public void setWindowTitle(CharSequence charSequence) {
        if (this.f1206h) {
            return;
        }
        H(charSequence);
    }

    @Override // androidx.appcompat.widget.e0
    public ViewGroup t() {
        return this.f1199a;
    }

    @Override // androidx.appcompat.widget.e0
    public void u(boolean z10) {
    }

    @Override // androidx.appcompat.widget.e0
    public int v() {
        return this.f1200b;
    }

    @Override // androidx.appcompat.widget.e0
    public void w(int i10) {
        F(i10 == 0 ? null : getContext().getString(i10));
    }

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

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

    @Override // androidx.appcompat.widget.e0
    public void z(Drawable drawable) {
        this.f1205g = drawable;
        J();
    }

    public x0(Toolbar toolbar, boolean z10, int i10, int i11) {
        Drawable drawable;
        this.f1213o = 0;
        this.f1214p = 0;
        this.f1199a = toolbar;
        this.f1207i = toolbar.getTitle();
        this.f1208j = toolbar.getSubtitle();
        this.f1206h = this.f1207i != null;
        this.f1205g = toolbar.getNavigationIcon();
        v0 v10 = v0.v(toolbar.getContext(), null, h.j.f20281a, h.a.f20149c, 0);
        this.f1215q = v10.g(h.j.f20336l);
        if (z10) {
            CharSequence p10 = v10.p(h.j.f20366r);
            if (!TextUtils.isEmpty(p10)) {
                setTitle(p10);
            }
            CharSequence p11 = v10.p(h.j.f20356p);
            if (!TextUtils.isEmpty(p11)) {
                G(p11);
            }
            Drawable g10 = v10.g(h.j.f20346n);
            if (g10 != null) {
                E(g10);
            }
            Drawable g11 = v10.g(h.j.f20341m);
            if (g11 != null) {
                setIcon(g11);
            }
            if (this.f1205g == null && (drawable = this.f1215q) != null) {
                z(drawable);
            }
            l(v10.k(h.j.f20316h, 0));
            int n10 = v10.n(h.j.f20311g, 0);
            if (n10 != 0) {
                C(LayoutInflater.from(this.f1199a.getContext()).inflate(n10, (ViewGroup) this.f1199a, false));
                l(this.f1200b | 16);
            }
            int m10 = v10.m(h.j.f20326j, 0);
            if (m10 > 0) {
                ViewGroup.LayoutParams layoutParams = this.f1199a.getLayoutParams();
                layoutParams.height = m10;
                this.f1199a.setLayoutParams(layoutParams);
            }
            int e10 = v10.e(h.j.f20306f, -1);
            int e11 = v10.e(h.j.f20301e, -1);
            if (e10 >= 0 || e11 >= 0) {
                this.f1199a.J(Math.max(e10, 0), Math.max(e11, 0));
            }
            int n11 = v10.n(h.j.f20371s, 0);
            if (n11 != 0) {
                Toolbar toolbar2 = this.f1199a;
                toolbar2.N(toolbar2.getContext(), n11);
            }
            int n12 = v10.n(h.j.f20361q, 0);
            if (n12 != 0) {
                Toolbar toolbar3 = this.f1199a;
                toolbar3.M(toolbar3.getContext(), n12);
            }
            int n13 = v10.n(h.j.f20351o, 0);
            if (n13 != 0) {
                this.f1199a.setPopupTheme(n13);
            }
        } else {
            this.f1200b = B();
        }
        v10.w();
        D(i10);
        this.f1209k = this.f1199a.getNavigationContentDescription();
        this.f1199a.setNavigationOnClickListener(new a());
    }

    @Override // androidx.appcompat.widget.e0
    public void setIcon(Drawable drawable) {
        this.f1203e = drawable;
        K();
    }
}
