package androidx.appcompat.view.menu;

import M.J;
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 com.google.android.material.datepicker.c;
import com.martsnew.tv.R;
import h.a;
import java.lang.reflect.Field;
import m.InterfaceC1155p;
import m.MenuC1147h;
import m.MenuItemC1148i;

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

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

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

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public boolean f7728C;
    public final Drawable D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public final boolean f7729E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public LayoutInflater f7730F;

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public MenuItemC1148i f7732q;

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

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

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

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

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

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

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

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

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

    public ListMenuItemView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        c cVarZ = c.z(getContext(), attributeSet, a.f13018o, R.attr.listMenuViewStyle);
        this.f7741z = cVarZ.u(5);
        TypedArray typedArray = (TypedArray) cVarZ.f10220s;
        this.f7726A = typedArray.getResourceId(1, -1);
        this.f7728C = typedArray.getBoolean(7, false);
        this.f7727B = context;
        this.D = cVarZ.u(8);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{android.R.attr.divider}, R.attr.dropDownListViewStyle, 0);
        this.f7729E = typedArrayObtainStyledAttributes.hasValue(0);
        cVarZ.B();
        typedArrayObtainStyledAttributes.recycle();
    }

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

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

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

    /* JADX WARN: Removed duplicated region for block: B:14:0x0037  */
    /* JADX WARN: Removed duplicated region for block: B:25:0x005a  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x005e  */
    @Override // m.InterfaceC1155p
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void b(MenuItemC1148i menuItemC1148i) {
        boolean z8;
        int i;
        String string;
        boolean z9;
        this.f7732q = menuItemC1148i;
        setVisibility(menuItemC1148i.isVisible() ? 0 : 8);
        setTitle(menuItemC1148i.f14491e);
        setCheckable(menuItemC1148i.isCheckable());
        if (menuItemC1148i.f14499n.n()) {
            if ((menuItemC1148i.f14499n.m() ? menuItemC1148i.f14495j : menuItemC1148i.f14494h) != 0) {
                z8 = true;
            }
        } else {
            z8 = false;
        }
        menuItemC1148i.f14499n.m();
        if (z8) {
            MenuItemC1148i menuItemC1148i2 = this.f7732q;
            if (menuItemC1148i2.f14499n.n()) {
                if ((menuItemC1148i2.f14499n.m() ? menuItemC1148i2.f14495j : menuItemC1148i2.f14494h) != 0) {
                    z9 = true;
                }
                if (z9) {
                }
            } else {
                z9 = false;
                i = z9 ? 0 : 8;
            }
        }
        if (i == 0) {
            TextView textView = this.f7737v;
            MenuItemC1148i menuItemC1148i3 = this.f7732q;
            char c3 = menuItemC1148i3.f14499n.m() ? menuItemC1148i3.f14495j : menuItemC1148i3.f14494h;
            if (c3 == 0) {
                string = "";
            } else {
                MenuC1147h menuC1147h = menuItemC1148i3.f14499n;
                Resources resources = menuC1147h.f14465a.getResources();
                StringBuilder sb = new StringBuilder();
                if (ViewConfiguration.get(menuC1147h.f14465a).hasPermanentMenuKey()) {
                    sb.append(resources.getString(R.string.abc_prepend_shortcut_label));
                }
                int i5 = menuC1147h.m() ? menuItemC1148i3.f14496k : menuItemC1148i3.i;
                MenuItemC1148i.a(sb, i5, 65536, resources.getString(R.string.abc_menu_meta_shortcut_label));
                MenuItemC1148i.a(sb, i5, 4096, resources.getString(R.string.abc_menu_ctrl_shortcut_label));
                MenuItemC1148i.a(sb, i5, 2, resources.getString(R.string.abc_menu_alt_shortcut_label));
                MenuItemC1148i.a(sb, i5, 1, resources.getString(R.string.abc_menu_shift_shortcut_label));
                MenuItemC1148i.a(sb, i5, 4, resources.getString(R.string.abc_menu_sym_shortcut_label));
                MenuItemC1148i.a(sb, i5, 8, resources.getString(R.string.abc_menu_function_shortcut_label));
                if (c3 == '\b') {
                    sb.append(resources.getString(R.string.abc_menu_delete_shortcut_label));
                } else if (c3 == '\n') {
                    sb.append(resources.getString(R.string.abc_menu_enter_shortcut_label));
                } else if (c3 != ' ') {
                    sb.append(c3);
                } else {
                    sb.append(resources.getString(R.string.abc_menu_space_shortcut_label));
                }
                string = sb.toString();
            }
            textView.setText(string);
        }
        if (this.f7737v.getVisibility() != i) {
            this.f7737v.setVisibility(i);
        }
        setIcon(menuItemC1148i.getIcon());
        setEnabled(menuItemC1148i.isEnabled());
        setSubMenuArrowVisible(menuItemC1148i.hasSubMenu());
        setContentDescription(menuItemC1148i.f14502q);
    }

    @Override // m.InterfaceC1155p
    public MenuItemC1148i getItemData() {
        return this.f7732q;
    }

    @Override // android.view.View
    public final void onFinishInflate() {
        super.onFinishInflate();
        Field field = J.f4065a;
        setBackground(this.f7741z);
        TextView textView = (TextView) findViewById(R.id.title);
        this.f7735t = textView;
        int i = this.f7726A;
        if (i != -1) {
            textView.setTextAppearance(this.f7727B, i);
        }
        this.f7737v = (TextView) findViewById(R.id.shortcut);
        ImageView imageView = (ImageView) findViewById(R.id.submenuarrow);
        this.f7738w = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.D);
        }
        this.f7739x = (ImageView) findViewById(R.id.group_divider);
        this.f7740y = (LinearLayout) findViewById(R.id.content);
    }

    @Override // android.widget.LinearLayout, android.view.View
    public final void onMeasure(int i, int i5) {
        if (this.f7733r != null && this.f7728C) {
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) this.f7733r.getLayoutParams();
            int i8 = layoutParams.height;
            if (i8 > 0 && layoutParams2.width <= 0) {
                layoutParams2.width = i8;
            }
        }
        super.onMeasure(i, i5);
    }

    public void setCheckable(boolean z8) {
        CompoundButton compoundButton;
        View view;
        if (!z8 && this.f7734s == null && this.f7736u == null) {
            return;
        }
        if ((this.f7732q.f14509x & 4) != 0) {
            if (this.f7734s == null) {
                RadioButton radioButton = (RadioButton) getInflater().inflate(R.layout.abc_list_menu_item_radio, (ViewGroup) this, false);
                this.f7734s = radioButton;
                LinearLayout linearLayout = this.f7740y;
                if (linearLayout != null) {
                    linearLayout.addView(radioButton, -1);
                } else {
                    addView(radioButton, -1);
                }
            }
            compoundButton = this.f7734s;
            view = this.f7736u;
        } else {
            if (this.f7736u == null) {
                CheckBox checkBox = (CheckBox) getInflater().inflate(R.layout.abc_list_menu_item_checkbox, (ViewGroup) this, false);
                this.f7736u = checkBox;
                LinearLayout linearLayout2 = this.f7740y;
                if (linearLayout2 != null) {
                    linearLayout2.addView(checkBox, -1);
                } else {
                    addView(checkBox, -1);
                }
            }
            compoundButton = this.f7736u;
            view = this.f7734s;
        }
        if (z8) {
            compoundButton.setChecked(this.f7732q.isChecked());
            if (compoundButton.getVisibility() != 0) {
                compoundButton.setVisibility(0);
            }
            if (view == null || view.getVisibility() == 8) {
                return;
            }
            view.setVisibility(8);
            return;
        }
        CheckBox checkBox2 = this.f7736u;
        if (checkBox2 != null) {
            checkBox2.setVisibility(8);
        }
        RadioButton radioButton2 = this.f7734s;
        if (radioButton2 != null) {
            radioButton2.setVisibility(8);
        }
    }

    public void setChecked(boolean z8) {
        CompoundButton compoundButton;
        if ((this.f7732q.f14509x & 4) != 0) {
            if (this.f7734s == null) {
                RadioButton radioButton = (RadioButton) getInflater().inflate(R.layout.abc_list_menu_item_radio, (ViewGroup) this, false);
                this.f7734s = radioButton;
                LinearLayout linearLayout = this.f7740y;
                if (linearLayout != null) {
                    linearLayout.addView(radioButton, -1);
                } else {
                    addView(radioButton, -1);
                }
            }
            compoundButton = this.f7734s;
        } else {
            if (this.f7736u == null) {
                CheckBox checkBox = (CheckBox) getInflater().inflate(R.layout.abc_list_menu_item_checkbox, (ViewGroup) this, false);
                this.f7736u = checkBox;
                LinearLayout linearLayout2 = this.f7740y;
                if (linearLayout2 != null) {
                    linearLayout2.addView(checkBox, -1);
                } else {
                    addView(checkBox, -1);
                }
            }
            compoundButton = this.f7736u;
        }
        compoundButton.setChecked(z8);
    }

    public void setForceShowIcon(boolean z8) {
        this.f7731G = z8;
        this.f7728C = z8;
    }

    public void setGroupDividerEnabled(boolean z8) {
        ImageView imageView = this.f7739x;
        if (imageView != null) {
            imageView.setVisibility((this.f7729E || !z8) ? 8 : 0);
        }
    }

    public void setIcon(Drawable drawable) {
        this.f7732q.f14499n.getClass();
        boolean z8 = this.f7731G;
        if (z8 || this.f7728C) {
            ImageView imageView = this.f7733r;
            if (imageView == null && drawable == null && !this.f7728C) {
                return;
            }
            if (imageView == null) {
                ImageView imageView2 = (ImageView) getInflater().inflate(R.layout.abc_list_menu_item_icon, (ViewGroup) this, false);
                this.f7733r = imageView2;
                LinearLayout linearLayout = this.f7740y;
                if (linearLayout != null) {
                    linearLayout.addView(imageView2, 0);
                } else {
                    addView(imageView2, 0);
                }
            }
            if (drawable == null && !this.f7728C) {
                this.f7733r.setVisibility(8);
                return;
            }
            ImageView imageView3 = this.f7733r;
            if (!z8) {
                drawable = null;
            }
            imageView3.setImageDrawable(drawable);
            if (this.f7733r.getVisibility() != 0) {
                this.f7733r.setVisibility(0);
            }
        }
    }

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