package com.ss.android.ugc.aweme.comment.barrage.cell;

import X.0HH;
import X.2nK;
import X.3EX;
import X.3ae;
import X.4ZZ;
import X.ACW;
import X.C02279ut;
import X.C0677ACb;
import X.C0681ACf;
import X.C0682ACg;
import X.C0684ACi;
import X.C2573AuX;
import X.Cl7;
import X.CwZ;
import X.Cwu;
import X.DaP;
import X.JIy;
import X.JIz;
import X.LnI;
import X.M12;
import X.QHW;
import X.QJt;
import X.Qeg;
import android.content.Context;
import android.content.res.Resources;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.powerlist.PowerCell;
import com.bytedance.lighten.loader.SmartImageView;
import com.ss.android.ugc.aweme.comment.model.Comment;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.profile.model.User;
import java.util.Set;
import kotlin.h.b.n;

public final class ReactionBubbleCommentCell extends PowerCell<ACW> {
    public static final C0684ACi LIZ = new C0684ACi((byte) 0);
    public SmartImageView LIZIZ;
    public Qeg LJIIIZ;
    public Qeg LJIIJ;
    public 4ZZ LJIIJJI;
    public Qeg LJIIL;
    public ACW LJIILIIL;

    static {
        Covode.recordClassIndex(56872);
    }

    private final String LIZ() {
        ACW acw = this.LJIILIIL;
        if (acw == null) {
            return "";
        }
        return acw.LJ + '_' + acw.LIZ.getCid();
    }

    public final void bE_() {
        C0682ACg aCg;
        Set<String> set;
        String str;
        ReactionBubbleCommentCell.super.bE_();
        ACW acw = this.LJIILIIL;
        if (acw != null && (aCg = acw.LIZJ) != null && (set = aCg.LJI) != null && !set.contains(LIZ())) {
            set.add(LIZ());
            ACW acw2 = this.LJIILIIL;
            if (acw2 != null) {
                Cwu[] cwuArr = new Cwu[4];
                C0682ACg aCg2 = acw2.LIZJ;
                String str2 = null;
                if (aCg2 != null) {
                    str = aCg2.LJ;
                } else {
                    str = null;
                }
                cwuArr[0] = CwZ.LIZ(str, "story_type");
                C0682ACg aCg3 = acw2.LIZJ;
                if (aCg3 != null) {
                    str2 = aCg3.LIZIZ;
                }
                cwuArr[1] = CwZ.LIZ(str2, "enter_from");
                cwuArr[2] = CwZ.LIZ("comment", "notice_type");
                User user = acw2.LIZ.getUser();
                n.LIZIZ(user, "");
                cwuArr[3] = CwZ.LIZ(user.getUid(), "from_user_id");
                2nK.LIZ("interaction_bullet_show", cwuArr);
            }
        }
    }

    private final void LIZIZ(boolean z) {
        TextPaint paint;
        float f;
        TextPaint paint2;
        TextPaint paint3;
        CharSequence charSequence;
        CharSequence charSequence2 = null;
        if (z) {
            Qeg qeg = this.LJIIIZ;
            float f2 = 0.0f;
            if (qeg == null || (paint3 = qeg.getPaint()) == null) {
                f = 0.0f;
            } else {
                Qeg qeg2 = this.LJIIIZ;
                if (qeg2 != null) {
                    charSequence = qeg2.getText();
                } else {
                    charSequence = null;
                }
                f = paint3.measureText(String.valueOf(charSequence));
            }
            Qeg qeg3 = this.LJIIL;
            if (!(qeg3 == null || (paint2 = qeg3.getPaint()) == null)) {
                Qeg qeg4 = this.LJIIL;
                if (qeg4 != null) {
                    charSequence2 = qeg4.getText();
                }
                f2 = paint2.measureText(String.valueOf(charSequence2));
            }
            Resources system = Resources.getSystem();
            n.LIZIZ(system, "");
            if (f + f2 > ((float) LnI.LIZ(TypedValue.applyDimension(1, 220.0f, system.getDisplayMetrics())))) {
                Resources system2 = Resources.getSystem();
                n.LIZIZ(system2, "");
                if (f2 < ((float) LnI.LIZ(TypedValue.applyDimension(1, 60.0f, system2.getDisplayMetrics())))) {
                    Qeg qeg5 = this.LJIIIZ;
                    if (qeg5 != null) {
                        Resources system3 = Resources.getSystem();
                        n.LIZIZ(system3, "");
                        qeg5.setMaxWidth((int) (((float) LnI.LIZ(TypedValue.applyDimension(1, 220.0f, system3.getDisplayMetrics()))) - f2));
                        return;
                    }
                    return;
                }
                Qeg qeg6 = this.LJIIIZ;
                if (qeg6 != null) {
                    Resources system4 = Resources.getSystem();
                    n.LIZIZ(system4, "");
                    qeg6.setMaxWidth(LnI.LIZ(TypedValue.applyDimension(1, 160.0f, system4.getDisplayMetrics())));
                }
                Qeg qeg7 = this.LJIIL;
                if (qeg7 != null) {
                    Resources system5 = Resources.getSystem();
                    n.LIZIZ(system5, "");
                    qeg7.setMaxWidth(LnI.LIZ(TypedValue.applyDimension(1, 60.0f, system5.getDisplayMetrics())));
                    return;
                }
                return;
            }
            return;
        }
        Qeg qeg8 = this.LJIIIZ;
        if (!(qeg8 == null || (paint = qeg8.getPaint()) == null)) {
            Qeg qeg9 = this.LJIIIZ;
            if (qeg9 != null) {
                charSequence2 = qeg9.getText();
            }
            paint.measureText(String.valueOf(charSequence2));
        }
        Qeg qeg10 = this.LJIIIZ;
        if (qeg10 != null) {
            Resources system6 = Resources.getSystem();
            n.LIZIZ(system6, "");
            qeg10.setMaxWidth(LnI.LIZ(TypedValue.applyDimension(1, 236.0f, system6.getDisplayMetrics())));
        }
    }

    public final View LIZ(ViewGroup viewGroup) {
        M12.LIZ(viewGroup);
        View LIZ2 = 0HH.LIZ(LayoutInflater.from(viewGroup.getContext()), 2131558826, viewGroup, false);
        n.LIZIZ(LIZ2, "");
        3ae r4 = new 3ae();
        r4.LIZIZ = 2130968615;
        Resources system = Resources.getSystem();
        n.LIZIZ(system, "");
        r4.LIZJ = Float.valueOf((float) LnI.LIZ(TypedValue.applyDimension(1, 24.0f, system.getDisplayMetrics())));
        Context context = viewGroup.getContext();
        n.LIZIZ(context, "");
        LIZ2.setBackground(r4.LIZ(context));
        this.LIZIZ = LIZ2.findViewById(2131362513);
        this.LJIIIZ = LIZ2.findViewById(2131367878);
        this.LJIIJ = LIZ2.findViewById(2131364009);
        this.LJIIJJI = LIZ2.findViewById(2131369455);
        this.LJIIL = LIZ2.findViewById(2131369456);
        LIZ2.setVisibility(4);
        return LIZ2;
    }

    public final /* synthetic */ void LIZ(DaP daP) {
        String text;
        String str;
        ACW acw = (ACW) daP;
        M12.LIZ(acw);
        ReactionBubbleCommentCell.super.LIZ(acw);
        Comment comment = acw.LIZ;
        User user = comment.getUser();
        n.LIZIZ(user, "");
        QJt LIZ2 = QHW.LIZ(3EX.LIZ(user.getAvatarThumb()));
        LIZ2.LIZ("ReactionBubbleCommentCell");
        LIZ2.LJJIIZ = this.LIZIZ;
        JIy jIy = new JIy();
        jIy.LIZ = true;
        JIz LIZ3 = jIy.LIZ();
        n.LIZIZ(LIZ3, "");
        LIZ2.LJIL = LIZ3;
        LIZ2.LIZJ = true;
        LIZ2.LIZJ();
        this.LJIILIIL = acw;
        this.itemView.setOnClickListener(new C0677ACb(this, comment, acw));
        SmartImageView smartImageView = this.LIZIZ;
        if (smartImageView != null) {
            smartImageView.setOnClickListener(new C0681ACf(this, comment, acw));
        }
        Qeg qeg = this.LJIIIZ;
        if (qeg != null) {
            User user2 = comment.getUser();
            C0682ACg aCg = acw.LIZJ;
            if (aCg != null) {
                str = aCg.LIZIZ;
            } else {
                str = null;
            }
            qeg.setText(C02279ut.LIZ(user2, str));
        }
        if (comment.getAliasAweme() != null) {
            StringBuilder sb = new StringBuilder("[");
            View view = this.itemView;
            n.LIZIZ(view, "");
            sb.append(view.getContext().getString(2131824730));
            sb.append(']');
            text = sb.toString();
        } else {
            text = comment.getText();
        }
        Qeg qeg2 = this.LJIIJ;
        if (qeg2 != null) {
            C2573AuX auX = new C2573AuX();
            n.LIZIZ(text, "");
            auX.LIZ(text);
            qeg2.setText(auX.LIZ);
        }
        if (TextUtils.isEmpty(comment.getReplyToUserName())) {
            4ZZ r0 = this.LJIIJJI;
            if (r0 != null) {
                r0.setVisibility(8);
            }
            Qeg qeg3 = this.LJIIL;
            if (qeg3 != null) {
                qeg3.setVisibility(8);
            }
            LIZIZ(false);
        } else {
            4ZZ r02 = this.LJIIJJI;
            if (r02 != null) {
                r02.setVisibility(0);
            }
            Qeg qeg4 = this.LJIIL;
            if (qeg4 != null) {
                qeg4.setVisibility(0);
            }
            Qeg qeg5 = this.LJIIL;
            if (qeg5 != null) {
                qeg5.setText(comment.getReplyToUserName());
            }
            LIZIZ(true);
        }
        if (acw.LIZIZ) {
            View view2 = this.itemView;
            n.LIZIZ(view2, "");
            view2.setVisibility(0);
            View view3 = this.itemView;
            n.LIZIZ(view3, "");
            view3.setTag(1);
            return;
        }
        View view4 = this.itemView;
        n.LIZIZ(view4, "");
        view4.setVisibility(4);
        View view5 = this.itemView;
        n.LIZIZ(view5, "");
        view5.setTag(0);
    }

    public final void LIZ(User user, C0682ACg aCg) {
        String str;
        String str2;
        Cwu[] cwuArr = new Cwu[4];
        Aweme aweme = null;
        if (aCg != null) {
            str = aCg.LIZIZ;
        } else {
            str = null;
        }
        cwuArr[0] = CwZ.LIZ(str, "enter_from");
        cwuArr[1] = CwZ.LIZ("comment", "notice_type");
        if (aCg != null) {
            aweme = aCg.LIZ;
        }
        if (Cl7.LJ(aweme)) {
            str2 = "story";
        } else {
            str2 = "post";
        }
        cwuArr[2] = CwZ.LIZ(str2, "story_type");
        cwuArr[3] = CwZ.LIZ(user.getUid(), "from_user_id");
        2nK.LIZ("interaction_bullet_click", cwuArr);
    }
}
