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.p;
import androidx.appcompat.widget.t0;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private ImageView f184k;
    private ImageView l;
    private LinearLayout m;
    private Drawable n;
    private int o;
    private Context p;
    private boolean q;
    private Drawable r;
    private boolean s;
    private LayoutInflater t;
    private boolean u;

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

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

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

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

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

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

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

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

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

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

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

    @Override // androidx.appcompat.view.menu.p.a
    public j getItemData() {
        return this.f178b;
    }

    public void h(boolean z, char c2) {
        int i2 = (z && this.f178b.z()) ? 0 : 8;
        if (i2 == 0) {
            this.f183j.setText(this.f178b.h());
        }
        if (this.f183j.getVisibility() != i2) {
            this.f183j.setVisibility(i2);
        }
    }

    @Override // android.view.View
    protected void onFinishInflate() {
        super.onFinishInflate();
        c.f.l.t.X(this, this.n);
        TextView textView = (TextView) findViewById(c.a.f.title);
        this.f181h = textView;
        int i2 = this.o;
        if (i2 != -1) {
            textView.setTextAppearance(this.p, i2);
        }
        this.f183j = (TextView) findViewById(c.a.f.shortcut);
        ImageView imageView = (ImageView) findViewById(c.a.f.submenuarrow);
        this.f184k = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.r);
        }
        this.l = (ImageView) findViewById(c.a.f.group_divider);
        this.m = (LinearLayout) findViewById(c.a.f.content);
    }

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

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

    public void setChecked(boolean z) {
        CompoundButton compoundButton;
        if (this.f178b.m()) {
            if (this.f180g == null) {
                g();
            }
            compoundButton = this.f180g;
        } else {
            if (this.f182i == null) {
                c();
            }
            compoundButton = this.f182i;
        }
        compoundButton.setChecked(z);
    }

    public void setForceShowIcon(boolean z) {
        this.u = z;
        this.q = z;
    }

    public void setGroupDividerEnabled(boolean z) {
        ImageView imageView = this.l;
        if (imageView != null) {
            imageView.setVisibility((this.s || !z) ? 8 : 0);
        }
    }

    public void setIcon(Drawable drawable) {
        boolean z = this.f178b.y() || this.u;
        if (z || this.q) {
            if (this.f179f == null && drawable == null && !this.q) {
                return;
            }
            if (this.f179f == null) {
                f();
            }
            if (drawable == null && !this.q) {
                this.f179f.setVisibility(8);
                return;
            }
            ImageView imageView = this.f179f;
            if (!z) {
                drawable = null;
            }
            imageView.setImageDrawable(drawable);
            if (this.f179f.getVisibility() != 0) {
                this.f179f.setVisibility(0);
            }
        }
    }

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

    public ListMenuItemView(Context context, AttributeSet attributeSet, int i2) {
        super(context, attributeSet);
        t0 t0VarT = t0.t(getContext(), attributeSet, c.a.j.MenuView, i2, 0);
        this.n = t0VarT.f(c.a.j.MenuView_android_itemBackground);
        this.o = t0VarT.m(c.a.j.MenuView_android_itemTextAppearance, -1);
        this.q = t0VarT.a(c.a.j.MenuView_preserveIconSpacing, false);
        this.p = context;
        this.r = t0VarT.f(c.a.j.MenuView_subMenuArrow);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{R.attr.divider}, c.a.a.dropDownListViewStyle, 0);
        this.s = typedArrayObtainStyledAttributes.hasValue(0);
        t0VarT.u();
        typedArrayObtainStyledAttributes.recycle();
    }
}
