package androidx.appcompat.view.menu;

import android.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.appcompat.view.menu.n;
import androidx.appcompat.widget.a1;
import androidx.core.view.y;

/* JADX INFO: loaded from: classes.dex */
public class ListMenuItemView extends LinearLayout implements n.a, AbsListView.SelectionBoundsAdjuster {

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

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

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

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private CheckBox f402i;

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private ImageView f405l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private LinearLayout f406m;

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

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

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

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

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

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

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    private LayoutInflater f413t;

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

    public ListMenuItemView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, c.a.D);
    }

    private void a(View view) {
        b(view, -1);
    }

    private void b(View view, int i3) {
        LinearLayout linearLayout = this.f406m;
        if (linearLayout != null) {
            linearLayout.addView(view, i3);
        } else {
            addView(view, i3);
        }
    }

    private void c() {
        CheckBox checkBox = (CheckBox) getInflater().inflate(c.g.f3259h, (ViewGroup) this, false);
        this.f402i = checkBox;
        a(checkBox);
    }

    private void f() {
        ImageView imageView = (ImageView) getInflater().inflate(c.g.f3260i, (ViewGroup) this, false);
        this.f399f = imageView;
        b(imageView, 0);
    }

    private void g() {
        RadioButton radioButton = (RadioButton) getInflater().inflate(c.g.f3262k, (ViewGroup) this, false);
        this.f400g = radioButton;
        a(radioButton);
    }

    private LayoutInflater getInflater() {
        if (this.f413t == null) {
            this.f413t = LayoutInflater.from(getContext());
        }
        return this.f413t;
    }

    private void setSubMenuArrowVisible(boolean z2) {
        ImageView imageView = this.f404k;
        if (imageView != null) {
            imageView.setVisibility(z2 ? 0 : 8);
        }
    }

    @Override // android.widget.AbsListView.SelectionBoundsAdjuster
    public void adjustListItemSelectionBounds(Rect rect) {
        ImageView imageView = this.f405l;
        if (imageView == null || imageView.getVisibility() != 0) {
            return;
        }
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) this.f405l.getLayoutParams();
        rect.top += this.f405l.getHeight() + layoutParams.topMargin + layoutParams.bottomMargin;
    }

    @Override // androidx.appcompat.view.menu.n.a
    public boolean d() {
        return false;
    }

    @Override // androidx.appcompat.view.menu.n.a
    public void e(i iVar, int i3) {
        this.f398e = iVar;
        setVisibility(iVar.isVisible() ? 0 : 8);
        setTitle(iVar.i(this));
        setCheckable(iVar.isCheckable());
        h(iVar.z(), iVar.g());
        setIcon(iVar.getIcon());
        setEnabled(iVar.isEnabled());
        setSubMenuArrowVisible(iVar.hasSubMenu());
        setContentDescription(iVar.getContentDescription());
    }

    @Override // androidx.appcompat.view.menu.n.a
    public i getItemData() {
        return this.f398e;
    }

    public void h(boolean z2, char c3) {
        int i3 = (z2 && this.f398e.z()) ? 0 : 8;
        if (i3 == 0) {
            this.f403j.setText(this.f398e.h());
        }
        if (this.f403j.getVisibility() != i3) {
            this.f403j.setVisibility(i3);
        }
    }

    @Override // android.view.View
    protected void onFinishInflate() {
        super.onFinishInflate();
        y.v0(this, this.f407n);
        TextView textView = (TextView) findViewById(c.f.M);
        this.f401h = textView;
        int i3 = this.f408o;
        if (i3 != -1) {
            textView.setTextAppearance(this.f409p, i3);
        }
        this.f403j = (TextView) findViewById(c.f.F);
        ImageView imageView = (ImageView) findViewById(c.f.I);
        this.f404k = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.f411r);
        }
        this.f405l = (ImageView) findViewById(c.f.f3243r);
        this.f406m = (LinearLayout) findViewById(c.f.f3237l);
    }

    @Override // android.widget.LinearLayout, android.view.View
    protected void onMeasure(int i3, int i4) {
        if (this.f399f != null && this.f410q) {
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) this.f399f.getLayoutParams();
            int i5 = layoutParams.height;
            if (i5 > 0 && layoutParams2.width <= 0) {
                layoutParams2.width = i5;
            }
        }
        super.onMeasure(i3, i4);
    }

    public void setCheckable(boolean z2) {
        CompoundButton compoundButton;
        CompoundButton compoundButton2;
        if (!z2 && this.f400g == null && this.f402i == null) {
            return;
        }
        if (this.f398e.m()) {
            if (this.f400g == null) {
                g();
            }
            compoundButton = this.f400g;
            compoundButton2 = this.f402i;
        } else {
            if (this.f402i == null) {
                c();
            }
            compoundButton = this.f402i;
            compoundButton2 = this.f400g;
        }
        if (z2) {
            compoundButton.setChecked(this.f398e.isChecked());
            if (compoundButton.getVisibility() != 0) {
                compoundButton.setVisibility(0);
            }
            if (compoundButton2 == null || compoundButton2.getVisibility() == 8) {
                return;
            }
            compoundButton2.setVisibility(8);
            return;
        }
        CheckBox checkBox = this.f402i;
        if (checkBox != null) {
            checkBox.setVisibility(8);
        }
        RadioButton radioButton = this.f400g;
        if (radioButton != null) {
            radioButton.setVisibility(8);
        }
    }

    public void setChecked(boolean z2) {
        CompoundButton compoundButton;
        if (this.f398e.m()) {
            if (this.f400g == null) {
                g();
            }
            compoundButton = this.f400g;
        } else {
            if (this.f402i == null) {
                c();
            }
            compoundButton = this.f402i;
        }
        compoundButton.setChecked(z2);
    }

    public void setForceShowIcon(boolean z2) {
        this.f414u = z2;
        this.f410q = z2;
    }

    public void setGroupDividerEnabled(boolean z2) {
        ImageView imageView = this.f405l;
        if (imageView != null) {
            imageView.setVisibility((this.f412s || !z2) ? 8 : 0);
        }
    }

    public void setIcon(Drawable drawable) {
        boolean z2 = this.f398e.y() || this.f414u;
        if (z2 || this.f410q) {
            ImageView imageView = this.f399f;
            if (imageView == null && drawable == null && !this.f410q) {
                return;
            }
            if (imageView == null) {
                f();
            }
            if (drawable == null && !this.f410q) {
                this.f399f.setVisibility(8);
                return;
            }
            ImageView imageView2 = this.f399f;
            if (!z2) {
                drawable = null;
            }
            imageView2.setImageDrawable(drawable);
            if (this.f399f.getVisibility() != 0) {
                this.f399f.setVisibility(0);
            }
        }
    }

    public void setTitle(CharSequence charSequence) {
        if (charSequence == null) {
            if (this.f401h.getVisibility() != 8) {
                this.f401h.setVisibility(8);
            }
        } else {
            this.f401h.setText(charSequence);
            if (this.f401h.getVisibility() != 0) {
                this.f401h.setVisibility(0);
            }
        }
    }

    public ListMenuItemView(Context context, AttributeSet attributeSet, int i3) {
        super(context, attributeSet);
        a1 a1VarV = a1.v(getContext(), attributeSet, c.j.O1, i3, 0);
        this.f407n = a1VarV.g(c.j.Q1);
        this.f408o = a1VarV.n(c.j.P1, -1);
        this.f410q = a1VarV.a(c.j.R1, false);
        this.f409p = context;
        this.f411r = a1VarV.g(c.j.S1);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{R.attr.divider}, c.a.A, 0);
        this.f412s = typedArrayObtainStyledAttributes.hasValue(0);
        a1VarV.w();
        typedArrayObtainStyledAttributes.recycle();
    }
}
