package com.bytedance.android.live.design.view.sheet.action;

import X.6Is;
import X.9Y3;
import X.AnonymousClass088;
import X.AnonymousClass0CB;
import X.AnonymousClass0CH;
import X.AnonymousClass1MK;
import X.AnonymousClass1MO;
import X.AnonymousClass1MP;
import X.AnonymousClass1MQ;
import X.AnonymousClass1MR;
import X.AnonymousClass1MW;
import X.C11340dA;
import X.C11940e8;
import X.C11960eA;
import X.C11980eC;
import X.C11990eD;
import X.C40861jg;
import X.Ql4;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.core.g.t;
import com.bytedance.android.live.design.view.sheet.LiveFixedHeightSheetDialog;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.util.ArrayList;
import java.util.List;

public class LiveActionSheetDialog extends LiveFixedHeightSheetDialog implements 6Is {
    public LinearLayout LJFF;
    public View LJI;
    public TextView LJII;
    public final List<AnonymousClass1MP> LJIIIIZZ = new ArrayList();
    public AnonymousClass1MP LJIIIZ;
    public CharSequence LJIIJ;
    public AnonymousClass1MQ LJIIJJI;

    static {
        Covode.recordClassIndex(5831);
    }

    public void onStateChanged(AnonymousClass0CH r1, AnonymousClass0CB r2) {
        super.onStateChanged(r1, r2);
    }

    private void LIZ(boolean z, int i, AnonymousClass1MQ r9) {
        MethodCollector.i(11166);
        C11960eA r4 = r9.LIZ;
        AnonymousClass1MK r3 = new AnonymousClass1MK(getContext());
        r3.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
        LIZ(r4, r3);
        this.LJFF.addView(r3, i);
        r9.LIZIZ = r3;
        if (z) {
            LIZ(i + 1, r9);
        }
        MethodCollector.o(11166);
    }

    private void LJ() {
        if (this.LJII != null) {
            if (!TextUtils.isEmpty(this.LJIIJ)) {
                this.LJII.setText(this.LJIIJ);
                this.LJII.setVisibility(0);
            } else {
                this.LJII.setVisibility(8);
            }
        }
        LIZLLL();
    }

    private void LIZLLL() {
        View view = this.LJI;
        if (view != null) {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
            if (this.LJIIIIZZ.size() > 0 && this.LJIIIIZZ.get(0).LIZ() > 0) {
                C11960eA r1 = this.LJIIIIZZ.get(0).LIZ.get(0).LIZ;
                if (TextUtils.isEmpty(this.LJIIJ) && (r1 instanceof AnonymousClass1MW) && ((AnonymousClass1MW) r1).LJ != null) {
                    marginLayoutParams.topMargin = this.LJI.getContext().getResources().getDimensionPixelSize(2131165779);
                    this.LJI.setLayoutParams(marginLayoutParams);
                }
            }
            marginLayoutParams.topMargin = 0;
            this.LJI.setLayoutParams(marginLayoutParams);
        }
    }

    public void setTitle(CharSequence charSequence) {
        this.LJIIJ = charSequence;
        LJ();
    }

    public void setTitle(int i) {
        setTitle((CharSequence) getContext().getResources().getString(i));
    }

    private int LIZ(int i) {
        int i2 = 0;
        for (int i3 = 0; i3 < i; i3++) {
            i2 += this.LJIIIIZZ.get(i3).LIZ() * 2;
        }
        return i2 + 0;
    }

    public static View LIZ(LayoutInflater layoutInflater) {
        MethodCollector.i(9365);
        if (9Y3.LIZ(9Y3.LIZ(), true, "tiktok_tux_text_view_opt", false) && layoutInflater != null && layoutInflater.getFactory() == null && layoutInflater.getFactory2() == null) {
            try {
                layoutInflater.setFactory(new Ql4());
            } catch (Exception unused) {
                View inflate = layoutInflater.inflate(2131560556, (ViewGroup) null);
                MethodCollector.o(9365);
                return inflate;
            }
        }
        View inflate2 = layoutInflater.inflate(2131560556, (ViewGroup) null);
        MethodCollector.o(9365);
        return inflate2;
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(LIZ(getLayoutInflater()), new ViewGroup.LayoutParams(-1, -2));
        this.LJII = (TextView) findViewById(2131361935);
        this.LJFF = (LinearLayout) findViewById(2131361933);
        t.LIZ((View) this.LJFF, (AnonymousClass088) new AnonymousClass1MR(getContext().getResources().getDimensionPixelSize(2131165778), getContext().getResources().getDimensionPixelSize(2131165772)));
        this.LJFF.requestApplyInsets();
        View findViewById = findViewById(2131361934);
        this.LJI = findViewById;
        if (this.LJII != null && this.LJFF != null && findViewById != null) {
            LJ();
            for (int i = 0; i < this.LJIIIIZZ.size(); i++) {
                LIZ(i, LIZ(i), this.LJIIIIZZ.get(i));
            }
            LinearLayout linearLayout = this.LJFF;
            if (linearLayout != null && this.LJIIJJI != null) {
                LIZ(linearLayout.getChildCount(), (C11940e8) this.LJIIJJI);
                LIZ(false, this.LJFF.getChildCount(), this.LJIIJJI);
            }
        }
    }

    private void LIZ(C40861jg r8) {
        this.LJIIJ = r8.LJII;
        if (r8.LJI != null && !r8.LJI.isEmpty()) {
            for (C11980eC next : r8.LJI) {
                int size = this.LJIIIIZZ.size();
                if (size >= 0 && size <= this.LJIIIIZZ.size() && next != null && next.LIZ != null && !next.LIZ.isEmpty()) {
                    boolean z = false;
                    AnonymousClass1MP r3 = new AnonymousClass1MP((byte) 0);
                    for (C11960eA r0 : next.LIZ) {
                        AnonymousClass1MQ r1 = new AnonymousClass1MQ(r0);
                        r1.LIZJ = r3;
                        r3.LIZ.add(r1);
                    }
                    if (size == this.LJIIIIZZ.size()) {
                        z = true;
                        this.LJIIIZ = r3;
                    }
                    this.LJIIIIZZ.add(size, r3);
                    if (this.LJFF != null) {
                        if (z && size > 0) {
                            LIZ(LIZ(size) - 1, (C11940e8) this.LJIIIIZZ.get(size - 1));
                        }
                        LIZ(size, LIZ(size), r3);
                    }
                    LIZLLL();
                }
            }
        }
        if (r8.LJIIIIZZ != null) {
            this.LJIIJJI = new AnonymousClass1MQ(r8.LJIIIIZZ);
        }
    }

    public LiveActionSheetDialog(Context context, int i) {
        super(context, i);
    }

    public LiveActionSheetDialog(Context context, C40861jg r3) {
        super(context, (AnonymousClass1MO<?>) r3);
        LIZ(r3);
    }

    private void LIZ(int i, C11940e8 r8) {
        MethodCollector.i(11401);
        if (r8.LIZLLL == null) {
            View view = new View(getContext());
            view.setLayoutParams(new LinearLayout.LayoutParams(-1, view.getContext().getResources().getDimensionPixelSize(2131165791)));
            view.setBackgroundColor(C11340dA.LIZ(view, 2130971286));
            this.LJFF.addView(view, i);
            r8.LIZLLL = view;
        }
        MethodCollector.o(11401);
    }

    private void LIZ(int i, AnonymousClass1MQ r8) {
        MethodCollector.i(11403);
        if (r8.LIZLLL == null) {
            View view = new View(getContext());
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, view.getContext().getResources().getDimensionPixelSize(2131165762));
            if ((r8.LIZ instanceof AnonymousClass1MW) && ((AnonymousClass1MW) r8.LIZ).LJ != null) {
                int dimensionPixelSize = view.getContext().getResources().getDimensionPixelSize(2131165777);
                layoutParams.rightMargin = dimensionPixelSize;
                layoutParams.leftMargin = dimensionPixelSize;
            }
            view.setLayoutParams(layoutParams);
            view.setBackgroundColor(C11340dA.LIZ(view, 2130971309));
            this.LJFF.addView(view, i);
            r8.LIZLLL = view;
        }
        MethodCollector.o(11403);
    }

    private void LIZ(C11960eA r2, AnonymousClass1MK r3) {
        if (r2 instanceof AnonymousClass1MW) {
            r3.setIcon(((AnonymousClass1MW) r2).LJ);
        }
        r3.setText(r2.LIZ);
        r3.setOnClickListener(new C11990eD(this, r2));
        r3.setEnabled(r2.LIZLLL);
        r3.LIZ(r2.LIZIZ);
    }

    private void LIZ(int i, int i2, AnonymousClass1MP r7) {
        List<AnonymousClass1MQ> list = r7.LIZ;
        int i3 = 0;
        while (true) {
            boolean z = true;
            if (i3 >= list.size()) {
                break;
            }
            if (i3 >= r7.LIZ() - 1) {
                z = false;
            }
            LIZ(z, i2, list.get(i3));
            i2 += 2;
            i3++;
        }
        if (i < this.LJIIIIZZ.size() - 1) {
            LIZ(LIZ(i + 1) - 1, (C11940e8) r7);
        }
    }
}
