package androidx.appcompat.view.menu;

import android.R;
import android.content.Context;
import android.content.res.Resources;
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.ViewConfiguration;
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.annotation.RestrictTo;
import androidx.media3.common.C;
import d.a;
import d.f;
import d.g;
import d.h;
import d.j;
import k.c0;
import k.p;
import k.r;
import l.p3;

/* JADX INFO: loaded from: classes.dex */
@RestrictTo({RestrictTo.Scope.f557c})
public class ListMenuItemView extends LinearLayout implements c0, AbsListView.SelectionBoundsAdjuster {
    public final Drawable Q;
    public final boolean R;
    public LayoutInflater S;
    public boolean T;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public r f574a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public ImageView f575b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public RadioButton f576c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public TextView f577d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public CheckBox f578e;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public ImageView f580g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public ImageView f581h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public LinearLayout f582i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final Drawable f583j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final int f584k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final Context f585l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public boolean f586m;

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

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

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

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

    @Override // k.c0
    public final void c(r rVar) {
        this.f574a = rVar;
        boolean z10 = false;
        setVisibility(rVar.isVisible() ? 0 : 8);
        setTitle(rVar.f28912e);
        setCheckable(rVar.isCheckable());
        if (rVar.f28921n.o()) {
            if ((rVar.f28921n.n() ? rVar.f28917j : rVar.f28915h) != 0) {
                z10 = true;
            }
        }
        setShortcut(z10, rVar.f28921n.n() ? rVar.f28917j : rVar.f28915h);
        setIcon(rVar.getIcon());
        setEnabled(rVar.isEnabled());
        setSubMenuArrowVisible(rVar.hasSubMenu());
        setContentDescription(rVar.f28924q);
    }

    @Override // k.c0
    public r getItemData() {
        return this.f574a;
    }

    @Override // android.view.View
    public final void onFinishInflate() {
        super.onFinishInflate();
        setBackground(this.f583j);
        TextView textView = (TextView) findViewById(f.title);
        this.f577d = textView;
        int i10 = this.f584k;
        if (i10 != -1) {
            textView.setTextAppearance(this.f585l, i10);
        }
        this.f579f = (TextView) findViewById(f.shortcut);
        ImageView imageView = (ImageView) findViewById(f.submenuarrow);
        this.f580g = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.Q);
        }
        this.f581h = (ImageView) findViewById(f.group_divider);
        this.f582i = (LinearLayout) findViewById(f.content);
    }

    @Override // android.widget.LinearLayout, android.view.View
    public final void onMeasure(int i10, int i11) {
        if (this.f575b != null && this.f586m) {
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) this.f575b.getLayoutParams();
            int i12 = layoutParams.height;
            if (i12 > 0 && layoutParams2.width <= 0) {
                layoutParams2.width = i12;
            }
        }
        super.onMeasure(i10, i11);
    }

    public void setCheckable(boolean z10) {
        CompoundButton compoundButton;
        View view;
        if (!z10 && this.f576c == null && this.f578e == null) {
            return;
        }
        if ((this.f574a.f28931x & 4) != 0) {
            if (this.f576c == null) {
                RadioButton radioButton = (RadioButton) getInflater().inflate(g.abc_list_menu_item_radio, (ViewGroup) this, false);
                this.f576c = radioButton;
                LinearLayout linearLayout = this.f582i;
                if (linearLayout != null) {
                    linearLayout.addView(radioButton, -1);
                } else {
                    addView(radioButton, -1);
                }
            }
            compoundButton = this.f576c;
            view = this.f578e;
        } else {
            if (this.f578e == null) {
                CheckBox checkBox = (CheckBox) getInflater().inflate(g.abc_list_menu_item_checkbox, (ViewGroup) this, false);
                this.f578e = checkBox;
                LinearLayout linearLayout2 = this.f582i;
                if (linearLayout2 != null) {
                    linearLayout2.addView(checkBox, -1);
                } else {
                    addView(checkBox, -1);
                }
            }
            compoundButton = this.f578e;
            view = this.f576c;
        }
        if (z10) {
            compoundButton.setChecked(this.f574a.isChecked());
            if (compoundButton.getVisibility() != 0) {
                compoundButton.setVisibility(0);
            }
            if (view == null || view.getVisibility() == 8) {
                return;
            }
            view.setVisibility(8);
            return;
        }
        CheckBox checkBox2 = this.f578e;
        if (checkBox2 != null) {
            checkBox2.setVisibility(8);
        }
        RadioButton radioButton2 = this.f576c;
        if (radioButton2 != null) {
            radioButton2.setVisibility(8);
        }
    }

    public void setChecked(boolean z10) {
        CompoundButton compoundButton;
        if ((this.f574a.f28931x & 4) != 0) {
            if (this.f576c == null) {
                RadioButton radioButton = (RadioButton) getInflater().inflate(g.abc_list_menu_item_radio, (ViewGroup) this, false);
                this.f576c = radioButton;
                LinearLayout linearLayout = this.f582i;
                if (linearLayout != null) {
                    linearLayout.addView(radioButton, -1);
                } else {
                    addView(radioButton, -1);
                }
            }
            compoundButton = this.f576c;
        } else {
            if (this.f578e == null) {
                CheckBox checkBox = (CheckBox) getInflater().inflate(g.abc_list_menu_item_checkbox, (ViewGroup) this, false);
                this.f578e = checkBox;
                LinearLayout linearLayout2 = this.f582i;
                if (linearLayout2 != null) {
                    linearLayout2.addView(checkBox, -1);
                } else {
                    addView(checkBox, -1);
                }
            }
            compoundButton = this.f578e;
        }
        compoundButton.setChecked(z10);
    }

    public void setForceShowIcon(boolean z10) {
        this.T = z10;
        this.f586m = z10;
    }

    public void setGroupDividerEnabled(boolean z10) {
        ImageView imageView = this.f581h;
        if (imageView != null) {
            imageView.setVisibility((this.R || !z10) ? 8 : 0);
        }
    }

    public void setIcon(Drawable drawable) {
        boolean z10 = this.f574a.f28921n.f28898s || this.T;
        if (z10 || this.f586m) {
            ImageView imageView = this.f575b;
            if (imageView == null && drawable == null && !this.f586m) {
                return;
            }
            if (imageView == null) {
                ImageView imageView2 = (ImageView) getInflater().inflate(g.abc_list_menu_item_icon, (ViewGroup) this, false);
                this.f575b = imageView2;
                LinearLayout linearLayout = this.f582i;
                if (linearLayout != null) {
                    linearLayout.addView(imageView2, 0);
                } else {
                    addView(imageView2, 0);
                }
            }
            if (drawable == null && !this.f586m) {
                this.f575b.setVisibility(8);
                return;
            }
            ImageView imageView3 = this.f575b;
            if (!z10) {
                drawable = null;
            }
            imageView3.setImageDrawable(drawable);
            if (this.f575b.getVisibility() != 0) {
                this.f575b.setVisibility(0);
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x001f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void setShortcut(boolean z10, char c6) {
        int i10;
        String string;
        if (z10) {
            r rVar = this.f574a;
            if (rVar.f28921n.o()) {
                if ((rVar.f28921n.n() ? rVar.f28917j : rVar.f28915h) != 0) {
                    i10 = 0;
                }
            } else {
                i10 = 8;
            }
        }
        if (i10 == 0) {
            TextView textView = this.f579f;
            r rVar2 = this.f574a;
            char c10 = rVar2.f28921n.n() ? rVar2.f28917j : rVar2.f28915h;
            if (c10 == 0) {
                string = "";
            } else {
                p pVar = rVar2.f28921n;
                Resources resources = pVar.f28880a.getResources();
                StringBuilder sb = new StringBuilder();
                if (ViewConfiguration.get(pVar.f28880a).hasPermanentMenuKey()) {
                    sb.append(resources.getString(h.abc_prepend_shortcut_label));
                }
                int i11 = pVar.n() ? rVar2.f28918k : rVar2.f28916i;
                r.a(i11, C.DEFAULT_BUFFER_SEGMENT_SIZE, resources.getString(h.abc_menu_meta_shortcut_label), sb);
                r.a(i11, 4096, resources.getString(h.abc_menu_ctrl_shortcut_label), sb);
                r.a(i11, 2, resources.getString(h.abc_menu_alt_shortcut_label), sb);
                r.a(i11, 1, resources.getString(h.abc_menu_shift_shortcut_label), sb);
                r.a(i11, 4, resources.getString(h.abc_menu_sym_shortcut_label), sb);
                r.a(i11, 8, resources.getString(h.abc_menu_function_shortcut_label), sb);
                if (c10 == '\b') {
                    sb.append(resources.getString(h.abc_menu_delete_shortcut_label));
                } else if (c10 == '\n') {
                    sb.append(resources.getString(h.abc_menu_enter_shortcut_label));
                } else if (c10 != ' ') {
                    sb.append(c10);
                } else {
                    sb.append(resources.getString(h.abc_menu_space_shortcut_label));
                }
                string = sb.toString();
            }
            textView.setText(string);
        }
        if (this.f579f.getVisibility() != i10) {
            this.f579f.setVisibility(i10);
        }
    }

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

    public ListMenuItemView(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet);
        p3 p3VarD = p3.d(getContext(), attributeSet, j.MenuView, i10);
        this.f583j = p3VarD.b(j.MenuView_android_itemBackground);
        int i11 = j.MenuView_android_itemTextAppearance;
        TypedArray typedArray = p3VarD.f29809b;
        this.f584k = typedArray.getResourceId(i11, -1);
        this.f586m = typedArray.getBoolean(j.MenuView_preserveIconSpacing, false);
        this.f585l = context;
        this.Q = p3VarD.b(j.MenuView_subMenuArrow);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{R.attr.divider}, a.dropDownListViewStyle, 0);
        this.R = typedArrayObtainStyledAttributes.hasValue(0);
        p3VarD.e();
        typedArrayObtainStyledAttributes.recycle();
    }
}
