package com.bytedance.tux.sheet.actionsheet;

import X.0HH;
import X.AnonymousClass4ZZ;
import X.C03012Pr;
import X.C208732h;
import X.C29023Xq;
import X.C29033Xr;
import X.C29043Xs;
import X.C29053Xt;
import X.C29063Xu;
import X.C29073Xv;
import X.LeS;
import X.LnI;
import X.LsC;
import X.M12;
import X.Qeg;
import X.Qen;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.tux.sheet.BaseSheet;
import java.util.ArrayList;
import java.util.List;
import kotlin.h.b.n;

public final class TuxActionSheet extends BaseSheet {
    public static final C29043Xs LJIIIZ = new C29043Xs((byte) 0);
    public List<List<C29073Xv<?>>> LIZ = new ArrayList();
    public CharSequence LIZIZ;
    public Integer LIZJ;
    public int LIZLLL = -1;
    public String LJ;
    public Integer LJFF;
    public boolean LJI;
    public boolean LJII;
    public View LJIIIIZZ;
    public SparseArray LJIIJ;

    static {
        Covode.recordClassIndex(39245);
    }

    public final void LIZ() {
        SparseArray sparseArray = this.LJIIJ;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    public final /* synthetic */ void onDestroyView() {
        super.onDestroyView();
        LIZ();
    }

    public final void onStart() {
        super.onStart();
        View view = getView();
        if (view != null) {
            view.post(new C29023Xq(this));
        }
    }

    private final CharSequence LIZ(Context context, CharSequence charSequence, Integer num) {
        if (charSequence != null) {
            return charSequence;
        }
        if (num == null) {
            return "";
        }
        String string = context.getResources().getString(num.intValue());
        n.LIZIZ(string, "");
        return string;
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        boolean z;
        int i;
        boolean z2;
        float f;
        int LIZ2;
        int i2;
        int i3;
        int i4;
        TuxActionSheet tuxActionSheet;
        float f2;
        MethodCollector.i(9523);
        LayoutInflater layoutInflater2 = layoutInflater;
        M12.LIZ(layoutInflater2);
        Context context = getContext();
        if (context == null) {
            MethodCollector.o(9523);
            return null;
        }
        n.LIZIZ(context, "");
        Integer num = this.LJJI;
        if (num != null) {
            context = new ContextThemeWrapper(context, num.intValue());
        }
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes((AttributeSet) null, new int[]{2130968837, 2130968838, 2130968839, 2130968840, 2130968841, 2130968842, 2130968843, 2130968844, 2130968845, 2130968846, 2130968847, 2130968848, 2130968849, 2130968850, 2130968851, 2130968852, 2130968853, 2130968854, 2130968855, 2130968856, 2130968857}, 2130968701, 0);
        n.LIZIZ(obtainStyledAttributes, "");
        int i5 = obtainStyledAttributes.getInt(19, 0);
        int i6 = obtainStyledAttributes.getInt(18, 0);
        int color = obtainStyledAttributes.getColor(7, 0);
        int color2 = obtainStyledAttributes.getColor(6, 0);
        int color3 = obtainStyledAttributes.getColor(11, 0);
        int i7 = obtainStyledAttributes.getInt(14, 0);
        int color4 = obtainStyledAttributes.getColor(2, 0);
        int color5 = obtainStyledAttributes.getColor(0, 0);
        int i8 = obtainStyledAttributes.getInt(13, 0);
        int i9 = obtainStyledAttributes.getInt(12, 0);
        String string = obtainStyledAttributes.getString(4);
        int i10 = obtainStyledAttributes.getInt(17, 0);
        int color6 = obtainStyledAttributes.getColor(16, 0);
        Resources system = Resources.getSystem();
        n.LIZIZ(system, "");
        int dimension = (int) obtainStyledAttributes.getDimension(20, TypedValue.applyDimension(1, 12.0f, system.getDisplayMetrics()));
        Resources system2 = Resources.getSystem();
        n.LIZIZ(system2, "");
        int dimension2 = (int) obtainStyledAttributes.getDimension(15, TypedValue.applyDimension(1, 16.0f, system2.getDisplayMetrics()));
        Resources system3 = Resources.getSystem();
        n.LIZIZ(system3, "");
        float dimension3 = obtainStyledAttributes.getDimension(1, TypedValue.applyDimension(1, 8.0f, system3.getDisplayMetrics()));
        boolean z3 = obtainStyledAttributes.getBoolean(9, false);
        Resources system4 = Resources.getSystem();
        n.LIZIZ(system4, "");
        int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(5, LnI.LIZ(TypedValue.applyDimension(1, 8.0f, system4.getDisplayMetrics())));
        obtainStyledAttributes.recycle();
        View LIZ3 = 0HH.LIZ(layoutInflater2, 2131558400, viewGroup, false);
        float f3 = (float) dimensionPixelSize;
        LIZ3.findViewById(2131369236).LIZ(f3, f3, 0.0f, 0.0f);
        Qeg findViewById = LIZ3.findViewById(2131361941);
        CharSequence LIZ4 = LIZ(context, this.LIZIZ, this.LIZJ);
        findViewById.setText(LIZ4);
        if (LIZ4.length() > 0) {
            z = true;
            i = 0;
        } else {
            z = false;
            i = 8;
        }
        findViewById.setVisibility(i);
        findViewById.setTuxFont(i5);
        findViewById.setTextColor(i6);
        Qen.LIZ(findViewById, (Integer) null, Integer.valueOf(dimension), (Integer) null, Integer.valueOf(dimension), false, 21);
        int i11 = this.LIZLLL;
        if (i11 > 0) {
            findViewById.setMaxLines(i11);
            findViewById.setEllipsize(TextUtils.TruncateAt.END);
        }
        LinearLayout linearLayout = (LinearLayout) LIZ3.findViewById(2131361940);
        int size = this.LIZ.size();
        if (!z && !this.LJI) {
            n.LIZIZ(linearLayout, "");
            Resources system5 = Resources.getSystem();
            n.LIZIZ(system5, "");
            Qen.LIZ(linearLayout, (Integer) null, Integer.valueOf(LnI.LIZ(TypedValue.applyDimension(1, 8.0f, system5.getDisplayMetrics()))), (Integer) null, (Integer) null, false, 29);
        }
        if (z3) {
            n.LIZIZ(linearLayout, "");
            Resources system6 = Resources.getSystem();
            n.LIZIZ(system6, "");
            LIZ((ViewGroup) linearLayout, TypedValue.applyDimension(1, 0.5f, system6.getDisplayMetrics()), color4, 0.0f);
        }
        View view = this.LJIIIIZZ;
        if (view != null) {
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
            ViewParent parent = view.getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(view);
            }
            linearLayout.addView(view, layoutParams);
            n.LIZIZ(linearLayout, "");
            LIZ((ViewGroup) linearLayout, dimension3, color5, 0.0f);
        }
        int i12 = 0;
        for (List size2 : this.LIZ) {
            i12 += size2.size();
        }
        int i13 = 0;
        for (T next : this.LIZ) {
            int i14 = i13 + 1;
            if (i13 < 0) {
                LeS.LIZIZ();
            }
            List list = (List) next;
            int size3 = list.size();
            int i15 = 0;
            for (Object next2 : list) {
                int i16 = i15 + 1;
                if (i15 < 0) {
                    LeS.LIZIZ();
                }
                C29073Xv r8 = (C29073Xv) next2;
                boolean z4 = r8 instanceof C29053Xt;
                if (z4) {
                    i2 = 2131558401;
                } else {
                    i2 = 2131558402;
                }
                View LIZ5 = 0HH.LIZ(LayoutInflater.from(context), i2, linearLayout, false);
                n.LIZIZ(LIZ5, "");
                LIZ5.setBackground(Qen.LIZIZ(context));
                LinearLayout linearLayout2 = linearLayout;
                LinearLayout linearLayout3 = linearLayout;
                int i17 = i7;
                int i18 = dimension2;
                Context context2 = context;
                C29073Xv r16 = r8;
                LIZ5.setOnClickListener(new C29033Xr(r8, size3, this, context, linearLayout, dimension2, color, color2, color3, i17, i10, color6, color4, size, dimension3, color5));
                Qen.LIZ(LIZ5, (Integer) null, Integer.valueOf(i18), (Integer) null, Integer.valueOf(i18), false, 21);
                if (!r16.LIZLLL) {
                    i4 = color;
                    i3 = 1;
                } else {
                    i3 = 1;
                    if (r16.LIZJ == 1) {
                        i4 = color2;
                    } else {
                        i4 = color3;
                    }
                }
                Qeg findViewById2 = LIZ5.findViewById(2131361930);
                if (findViewById2 != null) {
                    tuxActionSheet = this;
                    findViewById2.setText(tuxActionSheet.LIZ(context2, r16.LIZ, r16.LIZIZ));
                    findViewById2.setTuxFont(i17);
                    findViewById2.setTextColor(i4);
                } else {
                    tuxActionSheet = this;
                }
                if (z4) {
                    AnonymousClass4ZZ r82 = (AnonymousClass4ZZ) LIZ5.findViewById(2131361931);
                    C29053Xt r162 = (C29053Xt) r16;
                    Integer num2 = r162.LJFF;
                    LsC<? super AnonymousClass4ZZ, C03012Pr> lsC = r162.LJI;
                    View view2 = r162.LJII;
                    if (num2 != null) {
                        r82.setIconRes(num2.intValue());
                        r82.setTintColor(i4);
                    } else if (lsC != null) {
                        r82.LIZ();
                        n.LIZIZ(r82, "");
                        lsC.invoke(r82);
                    }
                    if (view2 != null) {
                        FrameLayout frameLayout = (FrameLayout) LIZ5.findViewById(2131364104);
                        frameLayout.removeAllViews();
                        frameLayout.addView(view2);
                        frameLayout.setVisibility(0);
                    }
                } else if (r16 instanceof C29063Xu) {
                    Qeg findViewById3 = LIZ5.findViewById(2131361932);
                    C29063Xu r163 = (C29063Xu) r16;
                    CharSequence LIZ6 = tuxActionSheet.LIZ(context2, r163.LJFF, r163.LJI);
                    if (LIZ6.length() > 0) {
                        n.LIZIZ(findViewById3, "");
                        findViewById3.setVisibility(0);
                        findViewById3.setText(LIZ6);
                        findViewById3.setTuxFont(i10);
                        findViewById3.setTextColor(color6);
                    } else {
                        n.LIZIZ(findViewById3, "");
                        findViewById3.setVisibility(8);
                    }
                }
                linearLayout2.addView(LIZ5);
                if (i15 < size3 - 1) {
                    if (z4) {
                        f2 = 16.0f;
                    } else {
                        f2 = 0.0f;
                    }
                    n.LIZIZ(linearLayout2, "");
                    Resources system7 = Resources.getSystem();
                    n.LIZIZ(system7, "");
                    tuxActionSheet.LIZ((ViewGroup) linearLayout3, TypedValue.applyDimension(i3, 0.5f, system7.getDisplayMetrics()), color4, f2);
                }
                linearLayout = linearLayout2;
                context = context2;
                dimension2 = i18;
                i7 = i17;
                i15 = i16;
            }
            if (i13 < size - 1) {
                n.LIZIZ(linearLayout, "");
                LIZ((ViewGroup) linearLayout, dimension3, color5, 0.0f);
            }
            i13 = i14;
        }
        if (this.LJII) {
            if (i12 <= 2) {
                z2 = true;
                n.LIZIZ(linearLayout, "");
                Resources system8 = Resources.getSystem();
                n.LIZIZ(system8, "");
                f = 16.0f;
                LIZ((ViewGroup) linearLayout, TypedValue.applyDimension(1, 0.5f, system8.getDisplayMetrics()), color4, 16.0f);
            } else {
                z2 = false;
                f = 16.0f;
            }
            n.LIZIZ(linearLayout, "");
            if (z2) {
                Resources system9 = Resources.getSystem();
                n.LIZIZ(system9, "");
                LIZ2 = LnI.LIZ(TypedValue.applyDimension(1, 52.0f, system9.getDisplayMetrics()));
            } else {
                Resources system10 = Resources.getSystem();
                n.LIZIZ(system10, "");
                LIZ2 = LnI.LIZ(TypedValue.applyDimension(1, f, system10.getDisplayMetrics()));
            }
            Qen.LIZ(linearLayout, (Integer) null, (Integer) null, (Integer) null, Integer.valueOf(LIZ2), false, 23);
        }
        if (this.LJI) {
            n.LIZIZ(linearLayout, "");
            LIZ((ViewGroup) linearLayout, dimension3, color5, 0.0f);
            CharSequence LIZ7 = LIZ(context, this.LJ, this.LJFF);
            if (LIZ7.length() == 0) {
                LIZ7 = LIZ(context, string, 17039360);
            }
            View LIZ8 = 0HH.LIZ(LayoutInflater.from(context), 2131558402, linearLayout, false);
            n.LIZIZ(LIZ8, "");
            LIZ8.setBackground(Qen.LIZIZ(context));
            LIZ8.setOnClickListener(new C208732h(this));
            Qen.LIZ(LIZ8, (Integer) null, Integer.valueOf(dimension2), (Integer) null, Integer.valueOf(dimension2), false, 21);
            Qeg findViewById4 = LIZ8.findViewById(2131361930);
            if (findViewById4 != null) {
                findViewById4.setText(LIZ7);
                findViewById4.setTuxFont(i8);
                findViewById4.setTextColor(i9);
            }
            linearLayout.addView(LIZ8);
        }
        MethodCollector.o(9523);
        return LIZ3;
    }

    /* access modifiers changed from: private */
    public final void LIZ(ViewGroup viewGroup, float f, int i, float f2) {
        MethodCollector.i(11108);
        FrameLayout frameLayout = new FrameLayout(viewGroup.getContext());
        ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(-1, (int) f);
        if (f2 > 0.0f) {
            Resources system = Resources.getSystem();
            n.LIZIZ(system, "");
            marginLayoutParams.leftMargin = LnI.LIZ(TypedValue.applyDimension(1, f2, system.getDisplayMetrics()));
            Resources system2 = Resources.getSystem();
            n.LIZIZ(system2, "");
            marginLayoutParams.rightMargin = LnI.LIZ(TypedValue.applyDimension(1, f2, system2.getDisplayMetrics()));
        }
        frameLayout.setBackgroundColor(i);
        viewGroup.addView(frameLayout, marginLayoutParams);
        MethodCollector.o(11108);
    }
}
