package androidx.appcompat.widget;

import android.R;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private boolean f618g;
    CharSequence h;
    private CharSequence i;
    private CharSequence j;
    Window.Callback k;
    boolean l;
    private int m;
    private int n;
    private Drawable o;

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

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

        a() {
            this.f619c = new androidx.appcompat.view.menu.a(j0.this.f612a.getContext(), 0, R.id.home, 0, 0, j0.this.h);
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            j0 j0Var = j0.this;
            Window.Callback callback = j0Var.k;
            if (callback == null || !j0Var.l) {
                return;
            }
            callback.onMenuItemSelected(0, this.f619c);
        }
    }

    public j0(Toolbar toolbar, boolean z) {
        this(toolbar, z, a.a.h.f42a, a.a.e.l);
    }

    private int d() {
        if (this.f612a.getNavigationIcon() == null) {
            return 11;
        }
        this.o = this.f612a.getNavigationIcon();
        return 15;
    }

    private void o(CharSequence charSequence) {
        this.h = charSequence;
        if ((this.f613b & 8) != 0) {
            this.f612a.setTitle(charSequence);
        }
    }

    private void p() {
        if ((this.f613b & 4) != 0) {
            if (TextUtils.isEmpty(this.j)) {
                this.f612a.setNavigationContentDescription(this.n);
            } else {
                this.f612a.setNavigationContentDescription(this.j);
            }
        }
    }

    private void q() {
        if ((this.f613b & 4) == 0) {
            this.f612a.setNavigationIcon((Drawable) null);
            return;
        }
        Toolbar toolbar = this.f612a;
        Drawable drawable = this.f617f;
        if (drawable == null) {
            drawable = this.o;
        }
        toolbar.setNavigationIcon(drawable);
    }

    private void r() {
        Drawable drawable;
        int i = this.f613b;
        if ((i & 2) == 0) {
            drawable = null;
        } else if ((i & 1) == 0 || (drawable = this.f616e) == null) {
            drawable = this.f615d;
        }
        this.f612a.setLogo(drawable);
    }

    @Override // androidx.appcompat.widget.q
    public void a(CharSequence charSequence) {
        if (this.f618g) {
            return;
        }
        o(charSequence);
    }

    @Override // androidx.appcompat.widget.q
    public void b(int i) {
        i(i != 0 ? a.a.k.a.a.d(e(), i) : null);
    }

    @Override // androidx.appcompat.widget.q
    public void c(Window.Callback callback) {
        this.k = callback;
    }

    public Context e() {
        return this.f612a.getContext();
    }

    public void f(View view) {
        View view2 = this.f614c;
        if (view2 != null && (this.f613b & 16) != 0) {
            this.f612a.removeView(view2);
        }
        this.f614c = view;
        if (view == null || (this.f613b & 16) == 0) {
            return;
        }
        this.f612a.addView(view);
    }

    public void g(int i) {
        if (i == this.n) {
            return;
        }
        this.n = i;
        if (TextUtils.isEmpty(this.f612a.getNavigationContentDescription())) {
            j(this.n);
        }
    }

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

    public void h(int i) {
        View view;
        int i2 = this.f613b ^ i;
        this.f613b = i;
        if (i2 != 0) {
            if ((i2 & 4) != 0) {
                if ((i & 4) != 0) {
                    p();
                }
                q();
            }
            if ((i2 & 3) != 0) {
                r();
            }
            if ((i2 & 8) != 0) {
                if ((i & 8) != 0) {
                    this.f612a.setTitle(this.h);
                    this.f612a.setSubtitle(this.i);
                } else {
                    this.f612a.setTitle((CharSequence) null);
                    this.f612a.setSubtitle((CharSequence) null);
                }
            }
            if ((i2 & 16) == 0 || (view = this.f614c) == null) {
                return;
            }
            if ((i & 16) != 0) {
                this.f612a.addView(view);
            } else {
                this.f612a.removeView(view);
            }
        }
    }

    public void i(Drawable drawable) {
        this.f616e = drawable;
        r();
    }

    public void j(int i) {
        k(i == 0 ? null : e().getString(i));
    }

    public void k(CharSequence charSequence) {
        this.j = charSequence;
        p();
    }

    public void l(Drawable drawable) {
        this.f617f = drawable;
        q();
    }

    public void m(CharSequence charSequence) {
        this.i = charSequence;
        if ((this.f613b & 8) != 0) {
            this.f612a.setSubtitle(charSequence);
        }
    }

    public void n(CharSequence charSequence) {
        this.f618g = true;
        o(charSequence);
    }

    @Override // androidx.appcompat.widget.q
    public void setIcon(int i) {
        setIcon(i != 0 ? a.a.k.a.a.d(e(), i) : null);
    }

    public j0(Toolbar toolbar, boolean z, int i, int i2) {
        Drawable drawable;
        this.m = 0;
        this.n = 0;
        this.f612a = toolbar;
        this.h = toolbar.getTitle();
        this.i = toolbar.getSubtitle();
        this.f618g = this.h != null;
        this.f617f = toolbar.getNavigationIcon();
        i0 i0VarS = i0.s(toolbar.getContext(), null, a.a.j.f51a, a.a.a.f2c, 0);
        this.o = i0VarS.f(a.a.j.j);
        if (z) {
            CharSequence charSequenceN = i0VarS.n(a.a.j.p);
            if (!TextUtils.isEmpty(charSequenceN)) {
                n(charSequenceN);
            }
            CharSequence charSequenceN2 = i0VarS.n(a.a.j.n);
            if (!TextUtils.isEmpty(charSequenceN2)) {
                m(charSequenceN2);
            }
            Drawable drawableF = i0VarS.f(a.a.j.l);
            if (drawableF != null) {
                i(drawableF);
            }
            Drawable drawableF2 = i0VarS.f(a.a.j.k);
            if (drawableF2 != null) {
                setIcon(drawableF2);
            }
            if (this.f617f == null && (drawable = this.o) != null) {
                l(drawable);
            }
            h(i0VarS.i(a.a.j.h, 0));
            int iL = i0VarS.l(a.a.j.f57g, 0);
            if (iL != 0) {
                f(LayoutInflater.from(this.f612a.getContext()).inflate(iL, (ViewGroup) this.f612a, false));
                h(this.f613b | 16);
            }
            int iK = i0VarS.k(a.a.j.i, 0);
            if (iK > 0) {
                ViewGroup.LayoutParams layoutParams = this.f612a.getLayoutParams();
                layoutParams.height = iK;
                this.f612a.setLayoutParams(layoutParams);
            }
            int iD = i0VarS.d(a.a.j.f56f, -1);
            int iD2 = i0VarS.d(a.a.j.f55e, -1);
            if (iD >= 0 || iD2 >= 0) {
                this.f612a.B(Math.max(iD, 0), Math.max(iD2, 0));
            }
            int iL2 = i0VarS.l(a.a.j.q, 0);
            if (iL2 != 0) {
                Toolbar toolbar2 = this.f612a;
                toolbar2.D(toolbar2.getContext(), iL2);
            }
            int iL3 = i0VarS.l(a.a.j.o, 0);
            if (iL3 != 0) {
                Toolbar toolbar3 = this.f612a;
                toolbar3.C(toolbar3.getContext(), iL3);
            }
            int iL4 = i0VarS.l(a.a.j.m, 0);
            if (iL4 != 0) {
                this.f612a.setPopupTheme(iL4);
            }
        } else {
            this.f613b = d();
        }
        i0VarS.t();
        g(i);
        this.j = this.f612a.getNavigationContentDescription();
        this.f612a.setNavigationOnClickListener(new a());
    }

    @Override // androidx.appcompat.widget.q
    public void setIcon(Drawable drawable) {
        this.f615d = drawable;
        r();
    }
}
