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.i0;

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private CheckBox f382g;
    private TextView h;
    private ImageView i;
    private ImageView j;
    private LinearLayout k;
    private Drawable l;
    private int m;
    private Context n;
    private boolean o;
    private Drawable p;
    private boolean q;
    private int r;
    private LayoutInflater s;
    private boolean t;

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

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

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

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

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

    private void g() {
        RadioButton radioButton = (RadioButton) getInflater().inflate(a.a.g.h, (ViewGroup) this, false);
        this.f380e = radioButton;
        a(radioButton);
    }

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

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

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

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

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

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

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

    @Override // android.view.View
    protected void onFinishInflate() {
        super.onFinishInflate();
        a.c.i.l.l(this, this.l);
        TextView textView = (TextView) findViewById(a.a.f.A);
        this.f381f = textView;
        int i = this.m;
        if (i != -1) {
            textView.setTextAppearance(this.n, i);
        }
        this.h = (TextView) findViewById(a.a.f.v);
        ImageView imageView = (ImageView) findViewById(a.a.f.y);
        this.i = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.p);
        }
        this.j = (ImageView) findViewById(a.a.f.l);
        this.k = (LinearLayout) findViewById(a.a.f.h);
    }

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

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

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

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

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

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

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

    public ListMenuItemView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet);
        i0 i0VarS = i0.s(getContext(), attributeSet, a.a.j.w1, i, 0);
        this.l = i0VarS.f(a.a.j.y1);
        this.m = i0VarS.l(a.a.j.x1, -1);
        this.o = i0VarS.a(a.a.j.z1, false);
        this.n = context;
        this.p = i0VarS.f(a.a.j.A1);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{R.attr.divider}, a.a.a.q, 0);
        this.q = typedArrayObtainStyledAttributes.hasValue(0);
        i0VarS.t();
        typedArrayObtainStyledAttributes.recycle();
    }
}
