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 {
    private j b;
    private ImageView d;
    private RadioButton e;
    private TextView f;

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

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

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

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

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private int f56m;
    private Context n;
    private boolean o;
    private Drawable p;
    private boolean q;
    private LayoutInflater r;
    private boolean s;

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

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

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

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

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

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

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

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

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

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

    @Override // androidx.appcompat.view.menu.p.a
    public void d(j jVar, int i2) {
        this.b = jVar;
        setVisibility(jVar.isVisible() ? 0 : 8);
        setTitle(jVar.i(this));
        setCheckable(jVar.isCheckable());
        h(jVar.A(), 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.b;
    }

    public void h(boolean z, char c) {
        int i2 = (z && this.b.A()) ? 0 : 8;
        if (i2 == 0) {
            this.f51h.setText(this.b.h());
        }
        if (this.f51h.getVisibility() != i2) {
            this.f51h.setVisibility(i2);
        }
    }

    @Override // android.view.View
    protected void onFinishInflate() {
        super.onFinishInflate();
        g.e.j.o.t(this, this.f55l);
        TextView textView = (TextView) findViewById(g.a.f.title);
        this.f = textView;
        int i2 = this.f56m;
        if (i2 != -1) {
            textView.setTextAppearance(this.n, i2);
        }
        this.f51h = (TextView) findViewById(g.a.f.shortcut);
        ImageView imageView = (ImageView) findViewById(g.a.f.submenuarrow);
        this.f52i = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.p);
        }
        this.f53j = (ImageView) findViewById(g.a.f.group_divider);
        this.f54k = (LinearLayout) findViewById(g.a.f.content);
    }

    @Override // android.widget.LinearLayout, android.view.View
    protected void onMeasure(int i2, int i3) {
        if (this.d != null && this.o) {
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) this.d.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.e == null && this.f50g == null) {
            return;
        }
        if (this.b.m()) {
            if (this.e == null) {
                g();
            }
            compoundButton = this.e;
            compoundButton2 = this.f50g;
        } else {
            if (this.f50g == null) {
                e();
            }
            compoundButton = this.f50g;
            compoundButton2 = this.e;
        }
        if (z) {
            compoundButton.setChecked(this.b.isChecked());
            if (compoundButton.getVisibility() != 0) {
                compoundButton.setVisibility(0);
            }
            if (compoundButton2 == null || compoundButton2.getVisibility() == 8) {
                return;
            }
            compoundButton2.setVisibility(8);
            return;
        }
        CheckBox checkBox = this.f50g;
        if (checkBox != null) {
            checkBox.setVisibility(8);
        }
        RadioButton radioButton = this.e;
        if (radioButton != null) {
            radioButton.setVisibility(8);
        }
    }

    public void setChecked(boolean z) {
        CompoundButton compoundButton;
        if (this.b.m()) {
            if (this.e == null) {
                g();
            }
            compoundButton = this.e;
        } else {
            if (this.f50g == null) {
                e();
            }
            compoundButton = this.f50g;
        }
        compoundButton.setChecked(z);
    }

    public void setForceShowIcon(boolean z) {
        this.s = z;
        this.o = z;
    }

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

    public void setIcon(Drawable drawable) {
        boolean z = this.b.z() || this.s;
        if (z || this.o) {
            if (this.d == null && drawable == null && !this.o) {
                return;
            }
            if (this.d == null) {
                f();
            }
            if (drawable == null && !this.o) {
                this.d.setVisibility(8);
                return;
            }
            ImageView imageView = this.d;
            if (!z) {
                drawable = null;
            }
            imageView.setImageDrawable(drawable);
            if (this.d.getVisibility() != 0) {
                this.d.setVisibility(0);
            }
        }
    }

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

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